久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='bIMgk'></tfoot>
    • <bdo id='bIMgk'></bdo><ul id='bIMgk'></ul>
    <i id='bIMgk'><tr id='bIMgk'><dt id='bIMgk'><q id='bIMgk'><span id='bIMgk'><b id='bIMgk'><form id='bIMgk'><ins id='bIMgk'></ins><ul id='bIMgk'></ul><sub id='bIMgk'></sub></form><legend id='bIMgk'></legend><bdo id='bIMgk'><pre id='bIMgk'><center id='bIMgk'></center></pre></bdo></b><th id='bIMgk'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='bIMgk'><tfoot id='bIMgk'></tfoot><dl id='bIMgk'><fieldset id='bIMgk'></fieldset></dl></div>

      <legend id='bIMgk'><style id='bIMgk'><dir id='bIMgk'><q id='bIMgk'></q></dir></style></legend>
    1. <small id='bIMgk'></small><noframes id='bIMgk'>

      1. 基于Multi-tenant Asp.net Core網站參數的JWT認證

        JWT authentication based on the Parameter in Multi-tenant Asp.net Core web site(基于Multi-tenant Asp.net Core網站參數的JWT認證)

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

        <legend id='eLymo'><style id='eLymo'><dir id='eLymo'><q id='eLymo'></q></dir></style></legend>

        • <bdo id='eLymo'></bdo><ul id='eLymo'></ul>
          <i id='eLymo'><tr id='eLymo'><dt id='eLymo'><q id='eLymo'><span id='eLymo'><b id='eLymo'><form id='eLymo'><ins id='eLymo'></ins><ul id='eLymo'></ul><sub id='eLymo'></sub></form><legend id='eLymo'></legend><bdo id='eLymo'><pre id='eLymo'><center id='eLymo'></center></pre></bdo></b><th id='eLymo'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='eLymo'><tfoot id='eLymo'></tfoot><dl id='eLymo'><fieldset id='eLymo'></fieldset></dl></div>
                <tbody id='eLymo'></tbody>
            • <tfoot id='eLymo'></tfoot>

                1. 本文介紹了基于Multi-tenant Asp.net Core網站參數的JWT認證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我在我的 .net core 2.1 網站中使用基于 JWT 的身份驗證.目前這工作正常.現在,我必須創建一個 API 多租戶,并且每個租戶都有自己的密鑰.租戶 ID 將作為參數傳遞給 API.

                  I am using JWT based authentication in my .net core 2.1 web site. Currently this works fine. Now, I have to make one API multi-tenant and each tenant will have it's own secret key. The tenant Id will be passed as parameter to the API.

                          [Authorize]
                          [HttpGet("tenant/{id}")]
                          public async Task<IActionResult> GetInfo(string id)
                          {
                          }
                  

                  每個租戶都將簽署 JWT 并將添加到 Authorization 標頭.我想不出根據參數更改 IssuerSigningKey 的方法.我嘗試了以下操作:

                  Each tenant will sign the JWT and will add to Authorization header. I am not able to think of a way to change IssuerSigningKey based on the parameter. I tried following:

                  1. 通過將 JWT 設為 [AllowAonymus] 來驗證 API 中的 JWT.這可行,但我最終編寫了所有 JWT 驗證代碼.

                  1. Validating the JWT inside the API by making it [AllowAonymus]. This works but I have end up writing all the JWT validating code.

                  實現ISecurityTokenValidator

                  我可以實現 ISecurityTokenValidator 來驗證令牌并在啟動配置中使用它,如下所示:

                  I can implement ISecurityTokenValidator to validate the token and using this in startup configuration something like this:

                  services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
                              {
                                  options.SecurityTokenValidators.Clear();
                                  options.SecurityTokenValidators.Add(new JWTSecurityTokenValidator());
                              });
                  

                  并實現了我自己的類來驗證令牌.

                  And implemented my own class to validate the token.

                  public class JWTSecurityTokenValidator : ISecurityTokenValidator
                  {
                      public ClaimsPrincipal ValidateToken(string securityToken, TokenValidationParameters validationParameters, out SecurityToken validatedToken)
                      {
                              // Implement the logic
                      }
                  }
                  

                  但我最終還是做了繁重的工作.另外,我無法訪問 ValidateToken 中的參數tenantId".

                  But again I end up doing heavy lifting. Also, I am not able to access the parameter "tenantId" in the ValidateToken.

                  3.使用IssuerSigningKeyResolver:我可以實現一個委托:

                  3.Using IssuerSigningKeyResolver: I can implement a delegate:

                  IEnumerable<SecurityKey> IssuerSigningKeyResolver(string token, SecurityToken securityToken, string kid, TokenValidationParameters validationParameters)
                  

                  同樣,我無法訪問tenantId"參數來選擇合適的密鑰.

                  Again I don't's have access to the "tenantId" parameter to choose the appropriate key.

                  是否有根據參數選擇 IssuerSigningKey 的優雅解決方案,這樣我就不需要編寫自己的邏輯來驗證 JWT?還是唯一的選擇是選擇第一個選項?

                  Is there elegant solution to choosing IssuerSigningKey based on the parameter so that I don't need to write my own logic to validate JWT? Or only option is to go with first option?

                  推薦答案

                  您可以使用 DI 將 IHttpContextAccessor 實例傳遞給您的 JWTSecurityTokenValidator 并獲取 IHttpContextAccessor 的值.HttpContext 屬性.

                  You can use DI to pass IHttpContextAccessor instance into your JWTSecurityTokenValidator and get value of IHttpContextAccessor.HttpContext property.

                  從 .Net Core 2.1 開始,您可以使用擴展名注冊:

                  From .Net Core 2.1 , you can register using extension :

                  services.AddHttpContextAccessor();
                  

                  然后在您的自定義 JWTSecurityTokenValidator 中,修改以注入 IHttpContextAccessor :

                  Then in your custom JWTSecurityTokenValidator , modify to inject the IHttpContextAccessor :

                  private readonly IHttpContextAccessor _httpContextAccessor;
                  
                  public JWTSecurityTokenValidator(IHttpContextAccessor httpContextAccessor) {
                      _httpContextAccessor = httpContextAccessor;
                  }
                  

                  修改Startup.cs中的注冊:

                  options.SecurityTokenValidators.Clear();
                  
                  options.SecurityTokenValidators.Add(new JWTSecurityTokenValidator(services.BuildServiceProvider().GetService<IHttpContextAccessor>()));
                  

                  這樣在 ValidateToken 方法中,你可以從 _httpContextAccessor.HttpContext 中讀取參數,根據你傳遞參數的方式,從查詢字符串或路徑中讀取:

                  So that in ValidateToken method ,you can read the parameter from _httpContextAccessor.HttpContext , according to how you pass the parameter , read it from query string or path :

                  public ClaimsPrincipal ValidateToken(string securityToken, TokenValidationParameters validationParameters, out SecurityToken validatedToken)
                  {
                          var xx = _httpContextAccessor.HttpContext.Request;
                          ........
                  }
                  

                  這篇關于基于Multi-tenant Asp.net Core網站參數的JWT認證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                  onClick event for Image in Unity(Unity中圖像的onClick事件)
                  Running Total C#(運行總 C#)
                  Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                  Calling A Button OnClick from a function(從函數調用按鈕 OnClick)
                    <tbody id='pptV9'></tbody>

                    <tfoot id='pptV9'></tfoot>

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

                        1. <legend id='pptV9'><style id='pptV9'><dir id='pptV9'><q id='pptV9'></q></dir></style></legend>
                        2. <i id='pptV9'><tr id='pptV9'><dt id='pptV9'><q id='pptV9'><span id='pptV9'><b id='pptV9'><form id='pptV9'><ins id='pptV9'></ins><ul id='pptV9'></ul><sub id='pptV9'></sub></form><legend id='pptV9'></legend><bdo id='pptV9'><pre id='pptV9'><center id='pptV9'></center></pre></bdo></b><th id='pptV9'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='pptV9'><tfoot id='pptV9'></tfoot><dl id='pptV9'><fieldset id='pptV9'></fieldset></dl></div>

                            <bdo id='pptV9'></bdo><ul id='pptV9'></ul>
                            主站蜘蛛池模板: 欧美日韩少妇 | 午夜精品久久久久久 | 国产第一福利 | 波多野结衣久久 | 性久久久久久 | 中文字幕黄色片 | 精品伊人久久 | 国产欧美一区二区精品性色超碰 | 日韩视频二区 | 精品国产91 | 中文字幕一区二区在线播放 | 久久久久人| 四虎四虎 | 中文字幕一区二区三区四区视频 | 久草免费在线视频 | 93久久精品日日躁夜夜躁欧美 | 在线不卡一区 | 他揉捏她两乳不停呻吟动态图 | 中文字幕在线一区二区三区 | 夜夜贪欢〈高h〉 | 欧美日韩一区二 | 亚洲午夜久久 | 国产理论在线 | 久久成人免费视频 | 欧美成人免费视频 | 日本福利在线 | 成人免费看片在线观看 | 九色91popny蝌蚪新疆 | 婷婷导航 | 黄色免费毛片 | 欧美久久久久久久久久 | 黄色av免费看| 日韩精品一区在线 | 亚洲视频在线看 | 日本三级韩国三级美三级91 | 亚洲一级二级三级 | 亚洲午夜视频在线观看 | 久久久久久av | 日韩一区二区三 | 日本a级大片 | 日韩在线观看中文字幕 |