久久久久久久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 令牌的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

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

                  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.

                  考慮到身份驗證不是通過 cookie 完成的.cookie 僅用作傳輸媒體.在遺留應用程序中,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);
                      }
                  

                  這里討論了這個解決方案詳細.

                  This solution is discussed here with more detail.

                  現(xiàn)在我需要為 ASP.NET Core 實現(xià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.

                  非常感謝任何幫助.

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

                  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 中,身份驗證系統(tǒng)進行了一些大修.而不是使用例如UseJwtBearerAuthentication 作為中間件,ASP.NET Core 2.0+ 使用 DI 進行配置.例如,這看起來像這樣:

                  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 => {
                              // ...
                          });
                  }
                  

                  除此之外,下一個問題是:我們?nèi)绾沃甘?JwtBearer 身份驗證過程使用這個新系統(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 對象包含自己的 Events 屬性,它允許您自定義流程的各個部分.使用 OnMessageReceived,您可以實現(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;
                                  }
                              };
                          });
                  }
                  

                  通過設置 context.Token,您是在告訴 JwtBearer 進程您已經(jīng)負責自己提取令牌.

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

                  這里是一個有用的遷移文檔,它更詳細地解釋了身份驗證更改.

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

                  這篇關于在 ASP.NET Core 中,從 Cookie 而不是 Headers 中讀取 JWT 令牌的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關文檔推薦

                  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(從函數(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>

                          • 主站蜘蛛池模板: 免费看欧美一级片 | 欧美一区二区在线 | 亚洲精品一区二区 | 9porny九色视频自拍 | 一级黄色片免费 | 北条麻妃一区二区三区在线观看 | 日韩美女爱爱 | 亚洲国产精品va在线看黑人 | 国产欧美日韩一区二区三区在线观看 | 日韩在线一区二区 | av中文字幕在线播放 | 日韩欧美三级电影 | 亚洲视频www | 欧美一a| 国产一区二区三区色淫影院 | 999国产视频 | 国产成人精品免费视频大全最热 | 1204国产成人精品视频 | 日本视频中文字幕 | 国产高清一区二区三区 | 成人做爰69片免费观看 | 亚洲成人三区 | 一区精品国产欧美在线 | 日本高清aⅴ毛片免费 | 亚洲精品高清视频 | 精区3d动漫一品二品精区 | 日韩欧美视频在线 | 羞羞视频在线观看免费观看 | 中文字幕av亚洲精品一部二部 | 亚洲九九| 日韩精品一区二区三区高清免费 | 91精品国产高清久久久久久久久 | 日本a级大片 | 一二三区视频 | 91亚洲国产成人久久精品网站 | 亚洲精品福利在线 | 国产精品久久久久久吹潮日韩动画 | 日韩久久中文字幕 | 国产电影一区二区在线观看 | www.亚洲精品 | 久久久久久久久99 |