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

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

    1. <tfoot id='eVbi2'></tfoot>

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

    2. <i id='eVbi2'><tr id='eVbi2'><dt id='eVbi2'><q id='eVbi2'><span id='eVbi2'><b id='eVbi2'><form id='eVbi2'><ins id='eVbi2'></ins><ul id='eVbi2'></ul><sub id='eVbi2'></sub></form><legend id='eVbi2'></legend><bdo id='eVbi2'><pre id='eVbi2'><center id='eVbi2'></center></pre></bdo></b><th id='eVbi2'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='eVbi2'><tfoot id='eVbi2'></tfoot><dl id='eVbi2'><fieldset id='eVbi2'></fieldset></dl></div>
        <bdo id='eVbi2'></bdo><ul id='eVbi2'></ul>
      1. 在 ASP.NET Core 中,從 Cookie 而不是 Headers 中讀取

        In ASP.NET Core read JWT token from Cookie instead of Headers(在 ASP.NET Core 中,從 Cookie 而不是 Headers 中讀取 JWT 令牌)
        <tfoot id='n8N14'></tfoot>
        <i id='n8N14'><tr id='n8N14'><dt id='n8N14'><q id='n8N14'><span id='n8N14'><b id='n8N14'><form id='n8N14'><ins id='n8N14'></ins><ul id='n8N14'></ul><sub id='n8N14'></sub></form><legend id='n8N14'></legend><bdo id='n8N14'><pre id='n8N14'><center id='n8N14'></center></pre></bdo></b><th id='n8N14'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='n8N14'><tfoot id='n8N14'></tfoot><dl id='n8N14'><fieldset id='n8N14'></fieldset></dl></div>

          1. <legend id='n8N14'><style id='n8N14'><dir id='n8N14'><q id='n8N14'></q></dir></style></legend>
              <tbody id='n8N14'></tbody>
            • <small id='n8N14'></small><noframes id='n8N14'>

                • <bdo id='n8N14'></bdo><ul id='n8N14'></ul>
                  本文介紹了在 ASP.NET Core 中,從 Cookie 而不是 Headers 中讀取 JWT 令牌的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

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

                  我正在將 ASP.NET Web API 4.6 OWIN 應(yīng)用程序移植到 ASP.NET Core 2.1.該應(yīng)用程序基于 JWT 令牌工作.但是通過(guò) cookie 而不是標(biāo)頭傳遞的令牌.我不確定為什么不使用標(biāo)題,這只是我必須處理的情況.

                  I am porting an ASP.NET Web API 4.6 OWIN application to ASP.NET Core 2.1. The application is working based on JWT token. But the token in passed via cookie instead of header. I'm not sure why headers are not used, it is just the situation that I have to deal with.

                  考慮到身份驗(yàn)證不是通過(guò) cookie 完成的.cookie 僅用作傳輸媒體.在遺留應(yīng)用程序中,CookieOAuthBearerProvider 用于從 cookie 中提取 JWT 令牌.配置代碼如下:

                  Consider that authentication is not done via cookie. The cookie is just used as a transfering media. In the legacy application CookieOAuthBearerProvider is employed to extract JWT token from cookie. Configuration code is as like this:

                      app.UseJwtBearerAuthentication(
                          new JwtBearerAuthenticationOptions
                          {
                              AuthenticationMode = AuthenticationMode.Active,
                              AllowedAudiences = new[] { audienceId },
                              IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
                              {
                                  new SymmetricKeyIssuerSecurityTokenProvider(issuer, audienceSecret)
                              },
                              Provider = new CookieOAuthBearerProvider("token")
                          });
                  }
                  

                  CookieOAuthBearerProvider類源碼如下:

                  public class CookieOAuthBearerProvider : OAuthBearerAuthenticationProvider
                  {
                      readonly string _name;
                      public CookieOAuthBearerProvider(string name)
                      {
                          _name = name;
                      }
                  
                      public override Task RequestToken(OAuthRequestTokenContext context)
                      {
                          var value = context.Request.Cookies[_name];
                  
                          if (!string.IsNullOrEmpty(value))
                          {
                              context.Token = value;
                          }
                  
                          return Task.FromResult<object>(null);
                      }
                  

                  這里討論了這個(gè)解決方案詳細(xì).

                  This solution is discussed here with more detail.

                  現(xiàn)在我需要為 ASP.NET Core 實(shí)現(xiàn)類似的解決方案.問(wèn)題是 UseJwtBearerAuthentication 不再存在于 ASP.NET Core 中,我不知道如何引入自定義 AuthenticationProvider.

                  Now I need to implement similar solution for ASP.NET Core. Problem is that UseJwtBearerAuthentication does not exists in ASP.NET Core anymore and I do not know how I can introduce a custom AuthenticationProvider.

                  非常感謝任何幫助.

                  更新:有 一種嘗試通過(guò)自己的代碼驗(yàn)證 JWT 的解決方案.這不是我需要的.我只是在尋找一種方法,將從 cookie 收到的令牌傳遞給標(biāo)頭閱讀器.

                  UPDATE: There is a solution that tries to validate JWT by its own code. It is not what I need. I'm just searching for a way to pass token recieved from cookie to header reader.

                  推薦答案

                  在 ASP.NET Core 2.0 中,身份驗(yàn)證系統(tǒng)進(jìn)行了一些大修.而不是使用例如UseJwtBearerAuthentication 作為中間件,ASP.NET Core 2.0+ 使用 DI 進(jìn)行配置.例如,這看起來(lái)像這樣:

                  In ASP.NET Core 2.0, the authentication system was somewhat overhauled. Rather than using e.g. UseJwtBearerAuthentication as middleware, ASP.NET Core 2.0+ configures things using DI. For example, this looks something like this:

                  public void ConfigureServices(IServiceCollection services)
                  {
                      services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                          .AddJwtBearer(options => {
                              // ...
                          });
                  }
                  

                  除此之外,下一個(gè)問(wèn)題是:我們?nèi)绾沃甘?JwtBearer 身份驗(yàn)證過(guò)程使用這個(gè)新系統(tǒng)查看 cookie?

                  With that out of the way, the next question would be: how do we instruct the JwtBearer authentication process to look at a cookie using this new system?

                  傳遞給 AddJwtBeareroptions 對(duì)象包含自己的 Events 屬性,它允許您自定義流程的各個(gè)部分.使用 OnMessageReceived,您可以實(shí)現(xiàn)您想要的:

                  That options object being passed in to AddJwtBearer contains an Events property of its own, which allows you to customise various parts of the process. Using OnMessageReceived, you can achieve what you're looking for:

                  public void ConfigureServices(IServiceCollection services)
                  {
                      services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                          .AddJwtBearer(options => {
                              options.Events = new JwtBearerEvents
                              {
                                  OnMessageReceived = context =>
                                  {
                                      context.Token = context.Request.Cookies["CookieName"];
                                      return Task.CompletedTask;
                                  }
                              };
                          });
                  }
                  

                  通過(guò)設(shè)置 context.Token,您是在告訴 JwtBearer 進(jìn)程您已經(jīng)負(fù)責(zé)自己提取令牌.

                  By setting context.Token, you're telling the JwtBearer process that you've taken care of extracting the token yourself.

                  這里是一個(gè)有用的遷移文檔,它更詳細(xì)地解釋了身份驗(yàn)證更改.

                  Here's a useful migration document that explains the authentication changes in more detail.

                  這篇關(guān)于在 ASP.NET Core 中,從 Cookie 而不是 Headers 中讀取 JWT 令牌的文章就介紹到這了,希望我們推薦的答案對(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)
                  <legend id='Kqeil'><style id='Kqeil'><dir id='Kqeil'><q id='Kqeil'></q></dir></style></legend>
                  <i id='Kqeil'><tr id='Kqeil'><dt id='Kqeil'><q id='Kqeil'><span id='Kqeil'><b id='Kqeil'><form id='Kqeil'><ins id='Kqeil'></ins><ul id='Kqeil'></ul><sub id='Kqeil'></sub></form><legend id='Kqeil'></legend><bdo id='Kqeil'><pre id='Kqeil'><center id='Kqeil'></center></pre></bdo></b><th id='Kqeil'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Kqeil'><tfoot id='Kqeil'></tfoot><dl id='Kqeil'><fieldset id='Kqeil'></fieldset></dl></div>
                • <small id='Kqeil'></small><noframes id='Kqeil'>

                    <tbody id='Kqeil'></tbody>
                      • <bdo id='Kqeil'></bdo><ul id='Kqeil'></ul>

                            <tfoot id='Kqeil'></tfoot>

                          • 主站蜘蛛池模板: 国产成人精品久久二区二区91 | 欧美成人手机在线 | 免费黄色录像视频 | 亚洲一二三区精品 | 久久激情视频 | 亚洲精品美女在线观看 | 久久88| 欧美一级黄色片在线观看 | 99国产精品久久久 | 亚洲高清视频在线 | 亚洲免费视频在线观看 | 久久精品国产99国产 | 亚洲精品一二三 | 国产资源视频 | 成人在线视频看看 | 色婷婷精品久久二区二区蜜臂av | 黄a大片| 鲁大师一区影视 | 一区二区视频在线 | 影音先锋男 | 久久久久久久一区 | 亚洲欧美中文日韩在线v日本 | 国产精品日本一区二区不卡视频 | 黄视频免费在线 | 99久久精品免费看国产小宝寻花 | 久久综合一区 | 激情五月婷婷在线 | 激情五月婷婷丁香 | 精品国产一区二区三区av片 | 91视频麻豆 | 国产三区视频在线观看 | 五月婷婷色 | 中文无吗 | 日韩中文在线 | 日韩成人在线播放 | 四色成人av永久网址 | 成人在线小视频 | 久久久青草婷婷精品综合日韩 | 青久草视频| 日本视频在线播放 | 欧美福利一区 |