1.新建ASP.NET Core Web 应用程序,程序文件如下图
引用以下包
2.新建config类配置客户端列表
public static class Config
{
public static IEnumerable<IdentityResource> IdentityResources =>
new IdentityResource[]
{
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
};
/// <summary>
/// api范围
/// </summary>
public static IEnumerable<ApiScope> ApiScopes =>
new ApiScope[]
{
new ApiScope("api")
};
/// <summary>
/// api资源
/// </summary>
public static IEnumerable<ApiResource> ApiResources =>
new ApiResource[]
{
new ApiResource("api","#api")
{
Scopes = { "api" }
}
};
public static IEnumerable<Client> GetClientConfigList()
{
var appInfo = Account.Instance.GetApps(); //这个是从数据库获取已配置的客户端。
List<Client> Clients = new List<Client>();
foreach (var item in appInfo)
{
Client client = new Client();
client.ClientId = item.App_ID;
client.AllowedGrantTypes = GrantTypes.ClientCredentials;//授权类型,这里使用的是客户端凭证模式
client.ClientSecrets.Add(new Secret(item.App_Key.Sha256()));
client.All