一、服务端建立authorization server
1、安装
Install-Package identityserver4
2、编写配置类
//一、IDS4服务制定 public class Config { //1、定义API资源 public static IEnumerable<ApiResource> GetApis() //ApiResource是属于using IdentityServer4.Models;内的。 { return new List<ApiResource> { new ApiResource("api1", "My API") }; } //2、定义客户端 public static IEnumerable<Client> GetClients() { return new List<Client> { new Client { ClientId = "client", // no interactive user, use the clientid/secret for authentication AllowedGrantTypes = GrantTypes.ClientCredentials, // secret for authentication ClientSecrets = { new Secret("secret".Sha256()) }, // scopes that client has access to AllowedScopes = { "api1" } } }; } }
在Startup.cs中注入ids4
//1、注入服务添&加在最底部 var builder = services.AddIdentityServer() .AddDeveloperSigningCredential()//添加开发人员签名凭据 //.AddInMemoryIdentityResources(Config.GetIdentityResources()) //注入GetIdentityResources资源。 .AddInMemoryApiResources(Config.GetApis()) //添加内存apiresource .AddInMemoryClients(Config.GetClients()); //添加内存client
到此我们的授权服务端算是完成了
二、服务端建立authorization server