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

  • <small id='JdZ3J'></small><noframes id='JdZ3J'>

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

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

      <tfoot id='JdZ3J'></tfoot>

          <bdo id='JdZ3J'></bdo><ul id='JdZ3J'></ul>
      1. ASP.NET Core WebAPI Cookie + JWT 身份驗證

        ASP.NET Core WebAPI Cookie + JWT Authentication(ASP.NET Core WebAPI Cookie + JWT 身份驗證)
      2. <tfoot id='pBH9m'></tfoot>

        • <small id='pBH9m'></small><noframes id='pBH9m'>

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

              • <legend id='pBH9m'><style id='pBH9m'><dir id='pBH9m'><q id='pBH9m'></q></dir></style></legend>

                  本文介紹了ASP.NET Core WebAPI Cookie + JWT 身份驗證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  we have a SPA (Angular) with API backend (ASP.NET Core WebAPI):

                  SPA is listens on app.mydomain.com, API on app.mydomain.com/API

                  We use JWT for Authentication with built-in Microsoft.AspNetCore.Authentication.JwtBearer; I have a controller app.mydomain.com/API/auth/jwt/login which creates tokens. SPA saves them into local storage. All works perfect. After a security audit, we have been told to switch local storage for cookies.

                  The problem is, that API on app.mydomain.com/API is used by SPA but also by a mobile app and several customers server-2-server solutions.

                  So, we have to keep JWT as is, but add Cookies. I found several articles which combines Cookies and JWT on different controllers, but I need them work side-by-side on each controller.

                  If client sends cookies, authenticate via cookies. If client sends JWT bearer, authenticate via JWT.

                  Is this achievable via built-in ASP.NET authentication or DIY middleware?

                  Thanks!

                  解決方案

                  Okay, I have been trying achieving this for a while and i solved same issue of using jwt Authentication Tokens and Cookie Authentication with the following code.

                  API Service Provider UserController.cs

                  This Provide Different Services to the User with Both (Cookie and JWT Bearer)Authentication Schemes

                  [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
                  [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)] 
                  [Route("[controller]")]
                  [ApiController]
                  public class UsersController : ControllerBase
                  { 
                      private readonly IUserServices_Api _services;
                      public UsersController(IUserServices_Api services)
                      {
                          this._services = services;
                      }
                       
                      [HttpGet]
                      public IEnumerable<User> Getall()
                      {
                          return _services.GetAll();
                      }
                  }
                  

                  My Startup.cs

                  public void ConfigureServices(IServiceCollection services)
                      {
                            
                          services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
                           
                          services.AddAuthentication(options => {
                              options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                              options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                              options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
                              options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
                          })
                              .AddCookie(options =>
                              {
                                  options.LoginPath = "/Account/Login";
                                  options.AccessDeniedPath = "/Home/Error";
                              })
                              .AddJwtBearer(options =>
                              {
                                  options.SaveToken = true;
                                  options.RequireHttpsMetadata = false;
                                  options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
                                  {
                                      ValidateIssuer = true,
                                      ValidateAudience = true,
                                      ValidAudience = " you site link blah blah",
                                      ValidIssuer = "You Site link Blah  blah",
                                      IssuerSigningKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(System.Text.Encoding.UTF8.GetBytes(sysController.GetSecurityKey()))
                                      ,
                                      ValidateLifetime = true,
                                      ClockSkew = TimeSpan.Zero
                                  };
                              });
                  
                      }
                  

                  And further if you want custom Authentication for a specific Controller then you have to specify the Authentitcation Type for the Authorization like:

                  [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)]
                  public IActionResult Index()
                  {
                      return View();    // This can only be Access when Cookie Authentication is Authorized.
                  }
                  
                  [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
                  public IActionResult Index()
                  {
                      return View();    // And this one will be Access when JWT Bearer is Valid
                  }
                  

                  這篇關于ASP.NET Core WebAPI Cookie + 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)

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

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

                          <bdo id='spXsO'></bdo><ul id='spXsO'></ul>
                          <legend id='spXsO'><style id='spXsO'><dir id='spXsO'><q id='spXsO'></q></dir></style></legend>
                            <tbody id='spXsO'></tbody>

                            <tfoot id='spXsO'></tfoot>

                          1. 主站蜘蛛池模板: 超碰在线97国产 | 国产精品成人在线播放 | 亚洲综合网站 | av手机免费在线观看 | 国产午夜精品理论片a大结局 | 午夜视频一区二区 | 日韩中文一区二区三区 | 久久久久久综合 | 国内精品久久久久久久影视简单 | 亚洲欧美bt | 久久机热 | 狠狠干网站 | 九九伊人sl水蜜桃色推荐 | 91久久国产综合久久 | 国产一区二区三区在线视频 | 在线观看国产视频 | 欧美区在线 | 欧美成人精品在线 | 日韩一区二区三区在线 | 野狼在线社区2017入口 | 精品在线一区二区三区 | 久久久久久久网 | 国产成人精品免高潮在线观看 | 成人免费精品视频 | 在线国产视频 | 国产91 在线播放 | av色站| 在线视频中文字幕 | 欧美日韩国产一区二区三区 | 国产精品视频久久久久 | 精品久久久久久 | caoporn免费 | 午夜免费电影院 | 午夜影院在线观看 | 91大神在线资源观看无广告 | 日韩在线免费视频 | 97精品国产97久久久久久免费 | 三级黄色大片网站 | 一级黄在线观看 | 黄色91在线 | 日日操av|