123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- using IdentityServer4;
- using IdentityServer4.Models;
- using Long.Common;
- namespace Auth
- {
- /// <summary>
- /// 认证配置
- /// </summary>
- public static class IdentityServer4Config
- {
- /// <summary>
- /// 范围
- /// </summary>
- /// <returns></returns>
- public static IEnumerable<ApiScope> ApiScopes()
- {
- return new List<ApiScope>
- {
- new ApiScope(IdsScope.GuestApi, "GuestAPI"),
- new ApiScope(IdsScope.UserApi, "UserAPI"),
- new ApiScope(IdsScope.AdminApi, "AdminAPI")
- };
- }
- /// <summary>
- /// 资源
- /// </summary>
- /// <returns></returns>
- public static IEnumerable<ApiResource> ApiResources()
- {
- return new List<ApiResource>
- {
- new ApiResource("LongApi", "Dotnet Core API")
- {
- Scopes = { IdsScope.GuestApi, IdsScope.UserApi, IdsScope.AdminApi }
- }
- };
- }
- /// <summary>
- /// 客户端
- /// </summary>
- /// <returns></returns>
- public static IEnumerable<Client> Clients()
- {
- var configurationBuilder = new ConfigurationBuilder();
- configurationBuilder.AddJsonFile("appsettings.json", false, true);
- var configuration = configurationBuilder.Build();
- return new List<Client>
- {
- new Client
- {
- ClientId = "guest",
- AllowedGrantTypes = GrantTypes.ClientCredentials,
- ClientSecrets =
- {
- new Secret("Long".Sha256())
- },
- AllowedScopes =
- {
- IdsScope.GuestApi,
- IdentityServerConstants.StandardScopes.OpenId,
- IdentityServerConstants.StandardScopes.OfflineAccess,
- IdentityServerConstants.StandardScopes.Profile
- },
- AccessTokenLifetime = 24 * 3600,
- AllowOfflineAccess = true,
- RefreshTokenExpiration = TokenExpiration.Sliding,
- SlidingRefreshTokenLifetime = 24 * 3600
- },
- new Client
- {
- ClientId = "user",
- AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
- ClientSecrets =
- {
- new Secret("Long".Sha256())
- },
- AllowedScopes =
- {
- IdsScope.UserApi,
- IdentityServerConstants.StandardScopes.OpenId,
- IdentityServerConstants.StandardScopes.OfflineAccess,
- IdentityServerConstants.StandardScopes.Profile
- },
- AccessTokenLifetime = 24 * 3600,
- AllowOfflineAccess = true,
- RefreshTokenExpiration = TokenExpiration.Sliding,
- SlidingRefreshTokenLifetime = 24 * 3600
- },
- new Client
- {
- ClientId = "admin",
- AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
- ClientSecrets =
- {
- new Secret("Long".Sha256())
- },
- AllowedScopes =
- {
- IdsScope.AdminApi,
- IdentityServerConstants.StandardScopes.OpenId,
- IdentityServerConstants.StandardScopes.OfflineAccess,
- IdentityServerConstants.StandardScopes.Profile
- },
- AccessTokenLifetime = 24 * 3600,
- AllowOfflineAccess = true,
- RefreshTokenExpiration = TokenExpiration.Sliding,
- SlidingRefreshTokenLifetime = 24 * 3600
- },
- new Client
- {
- ClientId = "web",
- //ClientName = "admin",
- AllowedGrantTypes = GrantTypes.Implicit,
- RequireConsent = false,
- RedirectUris = {configuration["RedirectUris"] },
- PostLogoutRedirectUris = {configuration["PostLogoutRedirectUris"] },
- ClientSecrets =
- {
- new Secret("Long".Sha256())
- },
- AllowedScopes =
- {
- IdentityServerConstants.StandardScopes.OpenId,
- IdentityServerConstants.StandardScopes.Profile
- }
- }
- };
- }
- }
- }
|