久久久久久久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)證的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  限時(shí)送ChatGPT賬號(hào)..

                  我在我的 .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. 通過(guò)將 JWT 設(shè)為 [AllowAonymus] 來(lái)驗(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 來(lái)驗(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)了我自己的類來(lái)驗(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
                      }
                  }
                  

                  但我最終還是做了繁重的工作.另外,我無(wú)法訪問(wèn) 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)
                  

                  同樣,我無(wú)法訪問(wèn)tenantId"參數(shù)來(lái)選擇合適的密鑰.

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

                  是否有根據(jù)參數(shù)選擇 IssuerSigningKey 的優(yōu)雅解決方案,這樣我就不需要編寫自己的邏輯來(lái)驗(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ò)展名注冊(cè):

                  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中的注冊(cè):

                  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)證的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  What are good algorithms for vehicle license plate detection?(車牌檢測(cè)有哪些好的算法?)
                  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>
                            主站蜘蛛池模板: 亚洲欧美日韩精品久久亚洲区 | 国产一区二区三区视频免费观看 | 永久免费av | 欧美亚洲国产一区二区三区 | 国产毛片毛片 | 成人午夜电影在线观看 | 伊人久麻豆社区 | 国产精品久久久久久久岛一牛影视 | 日韩精品一区二区三区 | 三级黄色大片网站 | 国产视频一区二区 | 精品久久久久香蕉网 | 亚洲精品一区二区另类图片 | 日韩精品一区二区在线观看 | 国产成人免费视频网站高清观看视频 | 欧美电影一区 | 国产xxxx岁13xxxxhd | 精品国产一区二区三区久久影院 | 麻豆av网站| 中文字幕高清av | 成人无遮挡毛片免费看 | 337p日本欧洲亚洲大胆精蜜臀 | 特级一级黄色片 | 美女三区| 欧美激情欧美激情在线五月 | 久久99久久99精品免视看婷婷 | 久久99精品久久久久久 | 久久aⅴ乱码一区二区三区 亚洲国产成人精品久久久国产成人一区 | 亚洲电影一区二区三区 | 在线观看的av | 天堂av免费观看 | 狠狠色综合欧美激情 | 欧美精品首页 | 91亚洲国产成人精品一区二三 | 在线观看av网站永久 | 国产精品久久久久久久久久久久冷 | 在线免费观看黄色 | 国产精品美女一区二区 | 一级在线免费观看 | 久久亚| 中文字幕精品一区二区三区在线 |