久久久久久久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.IsAuthenticated、User.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精品国产一区二区三区 | 91视频观看 | 欧美成人精品在线 | 亚洲欧美日韩在线一区二区 | 国产精品精品视频一区二区三区 | 欧美视频网 | 久久久久久久一区 | 久一精品 | 91精品国产高清一区二区三区 | 亚洲性视频 | 午夜国产羞羞视频免费网站 | 免费成年网站 | 国产高清在线 | 久久亚洲一区二区三 | 欧美精产国品一二三区 | 亚洲美乳中文字幕 | 国产在线播放av | 成人在线免费视频观看 | 国产成人小视频 | 欧美一级三级在线观看 | 狠狠干2020 | 成人国产免费观看 | 91久久精品一区二区二区 | 日韩国产一区 | 亚洲不卡在线观看 | 99视频在线 | 亚洲欧美久久 | 热久久性 | 日本小视频网站 | 亚洲国产情侣自拍 | 精品美女 | 91精品国产91 | 成人三级在线播放 | 日韩二三区 |