一、配置
1、安装 IdentityServer4
2、InitMemoryData 中的配置信息如下:
using System.Collections.Generic; using IdentityServer4.Models; namespace SunnTu { public class InitMemoryData { // scopes define the API resources in your system public static IEnumerable<ApiResource> GetApiResources() { return new List<ApiResource> { new ApiResource("inventoryapi", "this is inventory api"), new ApiResource("orderapi", "this is order api"), new ApiResource("productapi", "this is product api") }; } // clients want to access resources (aka scopes) public static IEnumerable<Client> GetClients() { // client credentials client return new List<Client> { new Client { ClientId = "inventory", AllowedGrantTypes = GrantTypes.ClientCredentials, ClientSecrets = { new Secret("inventorysecret".Sha256()) }, AllowedScopes = { "inventoryapi" } }, new Client { ClientId = "order", AllowedGrantTypes = GrantTypes.ClientCredentials, ClientSecrets = { new Secret("ordersecret".Sha256()) }, AllowedScopes = { "orderapi" } }, new Client { ClientId = "product", AllowedGrantTypes = GrantTypes.ClientCredentials, ClientSecrets = { new Secret("productsecret".Sha256()) }, AllowedScopes = { "productapi" } } }; } } }