using IdentityServer4.Models; using IdentityServer4.Test; namespace Id4 { public static class InMemoryConfig { // 这个 Authorization Server 保护了哪些 API (资源) public static IEnumerable GetApiResources() { return new[] { new ApiResource("blog.core.api", "Blog.Core API") }; } // 哪些客户端 Client(应用) 可以使用这个 Authorization Server public static IEnumerable GetClients() { return new[] { new Client { ClientId = "blogvuejs",//定义客户端 Id ClientSecrets = new [] { new Secret("secret".Sha256()) },//Client用来获取token AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,//这里使用的是通过用户名密码和ClientCredentials来换取token的方式. ClientCredentials允许Client只使用ClientSecrets来获取token. 这比较适合那种没有用户参与的api动作 AllowedScopes = new [] { "blog.core.api" }// 允许访问的 API 资源 } }; } // 指定可以使用 Authorization Server 授权的 Users(用户) public static IEnumerable Users() { return new[] { new TestUser { SubjectId = "1", Username = "laozhang", Password = "laozhang" } }; } public static IEnumerable ApiScopes => new ApiScope[] { new ApiScope("blog.core.api") }; } }