InMemoryConfig.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using IdentityServer4.Models;
  2. using IdentityServer4.Test;
  3. namespace Id4
  4. {
  5. public static class InMemoryConfig
  6. {
  7. // 这个 Authorization Server 保护了哪些 API (资源)
  8. public static IEnumerable<ApiResource> GetApiResources()
  9. {
  10. return new[]
  11. {
  12. new ApiResource("blog.core.api", "Blog.Core API")
  13. };
  14. }
  15. // 哪些客户端 Client(应用) 可以使用这个 Authorization Server
  16. public static IEnumerable<Client> GetClients()
  17. {
  18. return new[]
  19. {
  20. new Client
  21. {
  22. ClientId = "blogvuejs",//定义客户端 Id
  23. ClientSecrets = new [] { new Secret("secret".Sha256()) },//Client用来获取token
  24. AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,//这里使用的是通过用户名密码和ClientCredentials来换取token的方式. ClientCredentials允许Client只使用ClientSecrets来获取token. 这比较适合那种没有用户参与的api动作
  25. AllowedScopes = new [] { "blog.core.api" }// 允许访问的 API 资源
  26. }
  27. };
  28. }
  29. // 指定可以使用 Authorization Server 授权的 Users(用户)
  30. public static IEnumerable<TestUser> Users()
  31. {
  32. return new[]
  33. {
  34. new TestUser
  35. {
  36. SubjectId = "1",
  37. Username = "laozhang",
  38. Password = "laozhang"
  39. }
  40. };
  41. }
  42. public static IEnumerable<ApiScope> ApiScopes =>
  43. new ApiScope[] { new ApiScope("blog.core.api") };
  44. }
  45. }