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

      <tfoot id='wDujo'></tfoot>

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

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

      1. ASP .NET CORE 2.2 JWT &amp;聲明網站身份認證

        ASP .NET CORE 2.2 JWT amp; Claims identity Authentication for Website(ASP .NET CORE 2.2 JWT amp;聲明網站身份認證)
          <tfoot id='Go1AD'></tfoot>
            <i id='Go1AD'><tr id='Go1AD'><dt id='Go1AD'><q id='Go1AD'><span id='Go1AD'><b id='Go1AD'><form id='Go1AD'><ins id='Go1AD'></ins><ul id='Go1AD'></ul><sub id='Go1AD'></sub></form><legend id='Go1AD'></legend><bdo id='Go1AD'><pre id='Go1AD'><center id='Go1AD'></center></pre></bdo></b><th id='Go1AD'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Go1AD'><tfoot id='Go1AD'></tfoot><dl id='Go1AD'><fieldset id='Go1AD'></fieldset></dl></div>

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

                <tbody id='Go1AD'></tbody>
              <legend id='Go1AD'><style id='Go1AD'><dir id='Go1AD'><q id='Go1AD'></q></dir></style></legend>

                • <bdo id='Go1AD'></bdo><ul id='Go1AD'></ul>
                  本文介紹了ASP .NET CORE 2.2 JWT &amp;聲明網站身份認證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我有一個 .net core 2.2 api,它生成(在成功登錄時)一個 JWT 令牌,其中包含一個聲明身份,該身份傳遞信息,例如經過身份驗證的用戶的用戶名、權限和角色.

                  I have an .net core 2.2 api which generates (on a successful login) a JWT token which contains a claims identity that passes along information such as the username, permissions and roles of the authenticated user.

                  在我的 .net 核心 2.2 中.Web 應用程序我有一個登錄機制,它通過控制器的用戶檢索 JWT 令牌.

                  In my .net core 2.2. web app I have a login mechanism which retrieves the JWT token via the user of a controller.

                  我的問題是.

                  如何從我的登錄控制器中擴展令牌并設置我的網絡應用程序以包括使用身份驗證機制,如 User.Identity.IsAuthenticatedUser.IsInRole("Admin") 和控制器操作,例如 [Authorize][Authorize(Roles="Admin")]

                  How can I expand the token from within my login controller and set up my web app to include the use of the authentication mechanisms like User.Identity.IsAuthenticated, User.IsInRole("Admin") and controller actions like [Authorize] and [Authorize(Roles="Admin")]

                  我一直致力于查看 facebook/google 等外部身份驗證提供程序背后的源代碼,但無濟于事.

                  I've been directed towards looking at the source code behind external authentication providers such as facebook/google but to no avail.

                  提前致謝.

                  推薦答案

                  第一步是在Startup.cs中使用cookie認證:

                  services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
                  .AddCookie();
                  
                  services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
                  

                  Configure 方法中,使用 UseAuthentication 方法調用設置 HttpContext.User 屬性的身份驗證中間件.在調用 UseMvcWithDefaultRouteUseMvc 之前調用 UseAuthentication 方法:

                  In the Configure method, use the UseAuthentication method to invoke the Authentication Middleware that sets the HttpContext.User property. Call the UseAuthentication method before calling UseMvcWithDefaultRoute or UseMvc:

                  app.UseAuthentication();
                  

                  然后在您的身份驗證控制器中,獲取令牌并解碼以獲取聲明后,您應該創建新的 ClaimsIdentity ,添加您的聲明并登錄用戶:

                  Then in your auth controller , after getting token and decode to get the claims , you should create new ClaimsIdentity , add your claims and sign-in user :

                  if (!User.Identity.IsAuthenticated)
                  {
                      var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme, ClaimTypes.Name, ClaimTypes.Role);
                      identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, YourName));
                      identity.AddClaim(new Claim(ClaimTypes.Name, YourName));
                      identity.AddClaim(new Claim(ClaimTypes.Role, "Admin"));
                  
                      //Add your custom claims
                  
                      var principal = new ClaimsPrincipal(identity);
                      await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties { IsPersistent = true });
                  
                  }
                  

                  之后,您可以使用User.Identity.IsAuthenticatedUser.IsInRole("Admin")[Authorize(Roles="Admin")]:

                  After that , you can useUser.Identity.IsAuthenticated, User.IsInRole("Admin") and [Authorize(Roles="Admin")]:

                  [Authorize(Roles = "Admin")]
                  public IActionResult About()
                  {
                      var result = User.IsInRole("Admin");
                      return View();
                  }
                  

                  這篇關于ASP .NET CORE 2.2 JWT &amp;聲明網站身份認證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
                    <tfoot id='fLBeL'></tfoot>

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

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

                            <i id='fLBeL'><tr id='fLBeL'><dt id='fLBeL'><q id='fLBeL'><span id='fLBeL'><b id='fLBeL'><form id='fLBeL'><ins id='fLBeL'></ins><ul id='fLBeL'></ul><sub id='fLBeL'></sub></form><legend id='fLBeL'></legend><bdo id='fLBeL'><pre id='fLBeL'><center id='fLBeL'></center></pre></bdo></b><th id='fLBeL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='fLBeL'><tfoot id='fLBeL'></tfoot><dl id='fLBeL'><fieldset id='fLBeL'></fieldset></dl></div>
                          • <legend id='fLBeL'><style id='fLBeL'><dir id='fLBeL'><q id='fLBeL'></q></dir></style></legend>
                            主站蜘蛛池模板: 日韩欧美久久 | 99免费在线观看 | 免费看的av| 欧美精品tv| 日韩一区二区三区在线观看 | 青青久久| 欧美一级黄色片 | 一区二区三区中文字幕 | 国产精品国产馆在线真实露脸 | 米奇狠狠鲁 | 69亚洲精品 | 91国内精品久久 | 婷婷99 | 97国产爽爽爽久久久 | 一区二区福利视频 | 天堂一区在线观看 | 91在线电影| 亚洲一区二区三区在线视频 | 久久久久国产精品人 | 欧美国产亚洲一区二区 | 久久久精| 亚洲国产成人精品在线 | 国产日产欧产精品精品推荐蛮挑 | 国产农村妇女精品一区 | 欧美色综合网 | a毛片| 国产三区视频在线观看 | 天天曰夜夜 | 国产精品久久久久久影院8一贰佰 | 91久久看片 | 鸳鸯谱在线观看高清 | 亚洲成人免费在线观看 | 毛片毛片毛片毛片毛片 | 99久久99热这里只有精品 | 色婷婷亚洲国产女人的天堂 | 亚洲一区播放 | 激情一区二区三区 | 免费v片在线观看 | 亚洲一区二区电影在线观看 | 天天天堂 | 无码一区二区三区视频 |