久久久久久久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網(wǎng)站參數(shù)的JWT認(rèn)證

        JWT authentication based on the Parameter in Multi-tenant Asp.net Core web site(基于Multi-tenant Asp.net Core網(wǎng)站參數(shù)的JWT認(rèn)證)

        <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網(wǎng)站參數(shù)的JWT認(rèn)證的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時(shí)送ChatGPT賬號..

                  我在我的 .net core 2.1 網(wǎng)站中使用基于 JWT 的身份驗(yàn)證.目前這工作正常.現(xiàn)在,我必須創(chuàng)建一個(gè) API 多租戶,并且每個(gè)租戶都有自己的密鑰.租戶 ID 將作為參數(shù)傳遞給 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)
                          {
                          }
                  

                  每個(gè)租戶都將簽署 JWT 并將添加到 Authorization 標(biāo)頭.我想不出根據(jù)參數(shù)更改 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 設(shè)為 [AllowAonymus] 來驗(yàn)證 API 中的 JWT.這可行,但我最終編寫了所有 JWT 驗(yàn)證代碼.

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

                  實(shí)現(xiàn)ISecurityTokenValidator

                  我可以實(shí)現(xiàn) ISecurityTokenValidator 來驗(yàn)證令牌并在啟動(dòng)配置中使用它,如下所示:

                  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());
                              });
                  

                  并實(shí)現(xiàn)了我自己的類來驗(yàn)證令牌.

                  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 中的參數(shù)tenantId".

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

                  3.使用IssuerSigningKeyResolver:我可以實(shí)現(xiàn)一個(gè)委托:

                  3.Using IssuerSigningKeyResolver: I can implement a delegate:

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

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

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

                  是否有根據(jù)參數(shù)選擇 IssuerSigningKey 的優(yōu)雅解決方案,這樣我就不需要編寫自己的邏輯來驗(yàn)證 JWT?還是唯一的選擇是選擇第一個(gè)選項(xiàng)?

                  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 實(shí)例傳遞給您的 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 開始,您可以使用擴(kuò)展名注冊:

                  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 中讀取參數(shù),根據(jù)你傳遞參數(shù)的方式,從查詢字符串或路徑中讀取:

                  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;
                          ........
                  }
                  

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

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

                  相關(guān)文檔推薦

                  What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                  onClick event for Image in Unity(Unity中圖像的onClick事件)
                  Running Total C#(運(yùn)行總 C#)
                  Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時(shí)刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時(shí)突出顯示行)
                  Calling A Button OnClick from a function(從函數(shù)調(diào)用按鈕 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>
                            主站蜘蛛池模板: 免费看a | 亚洲一区二区黄 | 午夜精品一区二区三区三上悠亚 | japan21xxxxhd美女| 99re在线| 精品欧美一区二区三区久久久 | 精品入口麻豆88视频 | 欧美a v在线 | 成人二区 | 成人一区二区在线 | 免费毛片网站 | 人人干人人草 | 伦理午夜电影免费观看 | av成年人网站 | 国产成人精品久久 | 久久久久国产一区二区三区 | 国产美女视频一区 | 国产精品福利在线 | 91在线网站 | 亚洲有码转帖 | 欧美一区二区成人 | 日韩在线电影 | 亚洲字幕在线观看 | 97精品超碰一区二区三区 | 免费久久网 | 欧美中文在线 | 丁香婷婷久久久综合精品国产 | 无码一区二区三区视频 | 免费看大片bbbb欧美 | 欧美一级全黄 | 国产三级精品视频 | 99福利| 成人高清在线视频 | 99爱视频 | 狠狠操你 | 欧美日韩在线一区二区 | 视频一区二区三区中文字幕 | 精品www| 一区二区免费看 | 日本久久精 | 亚洲精品一区二区在线观看 |