• <legend id='GqMaF'><style id='GqMaF'><dir id='GqMaF'><q id='GqMaF'></q></dir></style></legend>

      <tfoot id='GqMaF'></tfoot>
      • <bdo id='GqMaF'></bdo><ul id='GqMaF'></ul>

        <i id='GqMaF'><tr id='GqMaF'><dt id='GqMaF'><q id='GqMaF'><span id='GqMaF'><b id='GqMaF'><form id='GqMaF'><ins id='GqMaF'></ins><ul id='GqMaF'></ul><sub id='GqMaF'></sub></form><legend id='GqMaF'></legend><bdo id='GqMaF'><pre id='GqMaF'><center id='GqMaF'></center></pre></bdo></b><th id='GqMaF'></th></span></q></dt></tr></i><div id='GqMaF'><tfoot id='GqMaF'></tfoot><dl id='GqMaF'><fieldset id='GqMaF'></fieldset></dl></div>
      1. <small id='GqMaF'></small><noframes id='GqMaF'>

        Identity Server 4:向访问令牌添加声明

        时间:2023-06-03

        <tfoot id='BamH6'></tfoot>

        <small id='BamH6'></small><noframes id='BamH6'>

              <tbody id='BamH6'></tbody>
            <legend id='BamH6'><style id='BamH6'><dir id='BamH6'><q id='BamH6'></q></dir></style></legend>

              • <bdo id='BamH6'></bdo><ul id='BamH6'></ul>
                1. <i id='BamH6'><tr id='BamH6'><dt id='BamH6'><q id='BamH6'><span id='BamH6'><b id='BamH6'><form id='BamH6'><ins id='BamH6'></ins><ul id='BamH6'></ul><sub id='BamH6'></sub></form><legend id='BamH6'></legend><bdo id='BamH6'><pre id='BamH6'><center id='BamH6'></center></pre></bdo></b><th id='BamH6'></th></span></q></dt></tr></i><div id='BamH6'><tfoot id='BamH6'></tfoot><dl id='BamH6'><fieldset id='BamH6'></fieldset></dl></div>

                  本文介绍了Identity Server 4:向访问令牌添加声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在使用 Identity Server 4 和隐式流,并想向访问令牌添加一些声明,新的声明或属性是tenantId"和langId".

                  I am using Identity Server 4 and Implicit Flow and want to add some claims to the access token, the new claims or attributes are "tenantId" and "langId".

                  我已将 langId 添加为我的范围之一,如下所示,然后通过身份服务器请求它,但我也得到了tenantId.怎么会这样?

                  I have added langId as one of my scopes as below and then requesting that through identity server, but i get the tenantId also. How can this happen?

                  这是范围和客户端配置的列表:

                  This the list of scopes and client configuration:

                    public IEnumerable<Scope> GetScopes()
                      {
                          return new List<Scope>
                          {
                               // standard OpenID Connect scopes
                              StandardScopes.OpenId,
                              StandardScopes.ProfileAlwaysInclude,
                              StandardScopes.EmailAlwaysInclude,
                  
                              new Scope
                              {
                                  Name="langId",
                                   Description = "Language",
                                  Type= ScopeType.Resource,
                                  Claims = new List<ScopeClaim>()
                                  {
                                      new ScopeClaim("langId", true)
                                  }
                              },
                              new Scope
                              {
                                  Name = "resourceAPIs",
                                  Description = "Resource APIs",
                                  Type= ScopeType.Resource
                              },
                              new Scope
                              {
                                  Name = "security_api",
                                  Description = "Security APIs",
                                  Type= ScopeType.Resource
                              },
                          };
                      }
                  

                  客户:

                    return new List<Client>
                          {
                              new Client
                              {
                                  ClientName = "angular2client",
                                  ClientId = "angular2client",
                                  AccessTokenType = AccessTokenType.Jwt,
                                  AllowedGrantTypes = GrantTypes.Implicit,
                                  AllowAccessTokensViaBrowser = true,
                                  RedirectUris = new List<string>(redirectUris.Split(',')), 
                                  PostLogoutRedirectUris = new List<string>(postLogoutRedirectUris.Split(',')),
                                  AllowedCorsOrigins = new List<string>(allowedCorsOrigins.Split(',')),
                  
                                  AllowedScopes = new List<string>
                                  {
                                     "openid",
                                     "resourceAPIs",
                                     "security_api",         
                                     "role",
                                    "langId"
                                  }
                              }
                          };
                  

                  我已在 ProfileService 中添加声明:

                  I have added the claims in the ProfileService:

                   public class ProfileService : IdentityServer4.Services.IProfileService
                  {
                      private readonly SecurityCore.ServiceContracts.IUserService _userService;
                  
                  
                      public ProfileService(SecurityCore.ServiceContracts.IUserService userService)
                      {
                          _userService = userService;
                      }
                  
                      public Task GetProfileDataAsync(ProfileDataRequestContext context)
                      {
                         //hardcoded them just for testing purposes
                          List<Claim> claims = new List<Claim>() { new Claim("langId", "en"), new Claim("tenantId", "123") };
                  
                          context.IssuedClaims = claims;
                  
                  
                          return Task.FromResult(0);
                      }
                  

                  这就是我要获取令牌的请求,问题是我只请求 langId 但我同时获得了 tenantIdlangId 在访问令牌中

                  This is what i am requesting to get the token, the problem is i am only requesting the langId but I am getting both the tenantId and langId in the access token

                  http://localhost:44312/account/login?returnUrl=%2Fconnect%2Fauthorize%2Flogin%3Fresponse_type%3Did_token%2520token%26client_id%3Dangular2client%26redirect_uri%3Dhttp%253A%252F%252Flocalhost:5002%26scope%3DresourceAPIs%2520notifications_api%2520security_api%2520langId%2520navigation_api%2520openid%26nonce%3DN0.73617935552798141482424408851%26state%3D14824244088510.41368537145696305%26
                  

                  解码的访问令牌:

                   {
                    "nbf": 1483043742,
                    "exp": 1483047342,
                    "iss": "http://localhost:44312",
                    "aud": "http://localhost:44312/resources",
                    "client_id": "angular2client",
                    "sub": "1",
                    "auth_time": 1483043588,
                    "idp": "local",
                    "langId": "en",
                    "tenantId": "123",
                    "scope": [
                      "resourceAPIs",     
                      "security_api",
                      "langId",
                      "openid"
                    ],
                    "amr": [
                      "pwd"
                    ]
                  }
                  

                  推荐答案

                  你应该检查 context.RequestedClaimTypes 并过滤掉未请求的声明.

                  You should check context.RequestedClaimTypes and filter out claims, that were not requested.

                  这篇关于Identity Server 4:向访问令牌添加声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:C# 中是否有任何 JSON Web 令牌 (JWT) 示例? 下一篇:在 ASP.NET Core 的 Swagger 中使用 JWT(授权:Bearer)

                  相关文章

                  最新文章

                  1. <legend id='mVWHh'><style id='mVWHh'><dir id='mVWHh'><q id='mVWHh'></q></dir></style></legend>

                    <small id='mVWHh'></small><noframes id='mVWHh'>

                    1. <i id='mVWHh'><tr id='mVWHh'><dt id='mVWHh'><q id='mVWHh'><span id='mVWHh'><b id='mVWHh'><form id='mVWHh'><ins id='mVWHh'></ins><ul id='mVWHh'></ul><sub id='mVWHh'></sub></form><legend id='mVWHh'></legend><bdo id='mVWHh'><pre id='mVWHh'><center id='mVWHh'></center></pre></bdo></b><th id='mVWHh'></th></span></q></dt></tr></i><div id='mVWHh'><tfoot id='mVWHh'></tfoot><dl id='mVWHh'><fieldset id='mVWHh'></fieldset></dl></div>
                      • <bdo id='mVWHh'></bdo><ul id='mVWHh'></ul>

                      <tfoot id='mVWHh'></tfoot>