2017-06-14 58 views

回答

1

当你定义的API资源(在Config.cs看看),你可以这样做:

new ApiResource 
{ 
    Name = "api", 
    DisplayName = "My API", 

    UserClaims = 
    { 
     JwtClaimTypes.Id, 
     JwtClaimTypes.Subject, 
     JwtClaimTypes.Email 
    } 
} 

它定义你的API将会收到这些声明。

编辑:

如果添加关联资源的到GetIdentityResources功能会更好(见Config.cs)

有官方文档中一眼就能有更好的画面 http://docs.identityserver.io/en/release/topics/resources.html

我给你一个完整的例子从一个个人项目:

public static IEnumerable<IdentityResource> GetIdentityResources() 
    { 
     //>Declaration 
     var lIdentityResources = new List<IdentityResource> 
     { 
      new IdentityResources.OpenId(), 
      new IdentityResources.Profile(), 
      new IdentityResources.Email() 
     }; 

     //>Processing 
     foreach (var lAPIResource in GetApiResources()) 
     { 
      lIdentityResources.Add(new IdentityResource(lAPIResource.Name, 
                 lAPIResource.UserClaims)); 
     } 

     //>Return 
     return lIdentityResources; 
    } 

    public static IEnumerable<ApiResource> GetApiResources() 
    { 
     return new List<ApiResource> 
     { 
      new ApiResource 
      { 
       Name = "api1", 
       DisplayName = "api1 API", 

       UserClaims = 
       { 
        JwtClaimTypes.Id, 
        JwtClaimTypes.Subject, 
        JwtClaimTypes.Email 
       } 
      } 
     }; 
    } 
+0

我得到了用户的权利,但仍没有得到该电子邮件要求,https://pastebin.com/aK4gBu3j – 001

+0

https://开头github上。 com/IdentityServer/IdentityServer4.Samples/blob/release/Quickstarts/8_EntityFrameworkStorage/src/Api/Controllers/IdentityController.cs – 001

+0

我的不好! 我忘了告诉你在IdentityServer4中根据OpenID规范实现添加电子邮件资源 – Coemgen

相关问题