public class Config { /// <summary> /// 微服务API资源 /// </summary> /// <returns></returns> public static IEnumerable<ApiResource> GetApiResources() { return new List<ApiResource> { new ApiResource("WebApi", "ChuanGoingWebApi"), new ApiResource("ProductApi", "ChuanGoingWebProduct") }; } /// <summary> /// OpenID Connect相关认证信息配置 /// </summary> /// <returns></returns> public static IEnumerable<IdentityResource> GetIdentityResources() { return new List<IdentityResource> { new IdentityResources.OpenId(), new IdentityResources.Profile() }; } /// <summary> /// 客户端信息配置 /// </summary> /// <returns></returns> public static IEnumerable<Client> GetClients(IConfiguration Configuration) { var OnlineConfig = Configuration.GetSection("OnlineClient"); var List = new List<Client> { //简单模式 new Client() { ClientId = "ClientCredentials", ClientName = "ClientCredentials", ClientSecrets = { new Secret("ClientSecret".Sha256()) }, AllowedGrantTypes = GrantTypes.ClientCredentials, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile, "WebApi", "ProductApi" }, AccessTokenLifetime = 10 * 60 * 1 }, //账号密码模式 new Client() { ClientId = "ResourceOwnerPassword", ClientName = "ResourceOwnerPassword", ClientSecrets = { new Secret("ClientSecret".Sha256()) }, AllowedGrantTypes = GrantTypes.ResourceOwnerPassword, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile, "WebApi", "ProductApi" }, AccessTokenLifetime = 10 * 60 * 1 }, /* 隐式模式:https://localhost:6005/connect/authorize?client_id=Implicit&redirect_uri=http://localhost:5000/Home&response_type=token&scope=WebApi */ new Client() { ClientId = "Implicit", ClientSecrets = { new Secret("ImplicitSecret".Sha256()) }, ClientName = "ImplicitClient", AllowedGrantTypes = GrantTypes.Implicit, //RedirectUris ={OnlineConfig.GetValue<string>("RedirectUris") }, //PostLogoutRedirectUris = {OnlineConfig.GetValue<string>("LogoutRedirectUris") }, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile, "WebApi", "ProductApi" }, AccessTokenLifetime = 10 * 60 * 1, //允许将token通过浏览器传递 AllowAccessTokensViaBrowser=true }, /* * 授权码模式:https://localhost:6005/connect/authorize?client_id=GrantCode&redirect_uri=http://localhost:5000/Home&response_type=code&scope=WebApi */ new Client() { //客户端Id ClientId="GrantCode", ClientName="GrantCodeClient", //客户端密码 ClientSecrets={new Secret("CodeSecret".Sha256()) }, //客户端授权类型,Code:授权码模式 AllowedGrantTypes=GrantTypes.Code, //允许登录后重定向的地址列表,可以有多个 RedirectUris ={OnlineConfig.GetValue<string>("RedirectUris") }, //允许访问的资源 AllowedScopes={"WebApi", "ProductApi"} } }; return List; } public static List<TestUser> GetUsers() { return new List<TestUser> { new TestUser { SubjectId = Guid.NewGuid().ToString(), Username = "admin", Password = "123456" //Claims = new List<Claim> //{ // new Claim("name", "admin"), // new Claim("website", "https://www.cnblogs.com/chuangoing") //} }, new TestUser { SubjectId = Guid.NewGuid().ToString(), Username = "chuangoing", Password = "123456" //Claims = new List<Claim> //{ // new Claim("name", "chuangoing"), // new Claim("website", "https://github.com/chuangoing") //} } }; } } }
标签:WebApi,ASP,StandardScopes,List,IdentityServerConstants,new,NET,public,IdentitySe From: https://www.cnblogs.com/xm123/p/18609501