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

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

      <bdo id='EoEcd'></bdo><ul id='EoEcd'></ul>
  • <legend id='EoEcd'><style id='EoEcd'><dir id='EoEcd'><q id='EoEcd'></q></dir></style></legend>

        <tfoot id='EoEcd'></tfoot>

        .NET Core 2.0 身份和 jwt?

        .NET Core 2.0 Identity AND jwt?(.NET Core 2.0 身份和 jwt?)
        <tfoot id='NJLwB'></tfoot>

        • <bdo id='NJLwB'></bdo><ul id='NJLwB'></ul>
            <legend id='NJLwB'><style id='NJLwB'><dir id='NJLwB'><q id='NJLwB'></q></dir></style></legend>
          • <small id='NJLwB'></small><noframes id='NJLwB'>

                <i id='NJLwB'><tr id='NJLwB'><dt id='NJLwB'><q id='NJLwB'><span id='NJLwB'><b id='NJLwB'><form id='NJLwB'><ins id='NJLwB'></ins><ul id='NJLwB'></ul><sub id='NJLwB'></sub></form><legend id='NJLwB'></legend><bdo id='NJLwB'><pre id='NJLwB'><center id='NJLwB'></center></pre></bdo></b><th id='NJLwB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='NJLwB'><tfoot id='NJLwB'></tfoot><dl id='NJLwB'><fieldset id='NJLwB'></fieldset></dl></div>
                    <tbody id='NJLwB'></tbody>
                  本文介紹了.NET Core 2.0 身份和 jwt?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時(shí)送ChatGPT賬號..

                  我一直在四處尋找并嘗試對 .NET Core Identity 進(jìn)行更多研究(https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.1&tabs=visual-studio%2Caspnetcore2x)和 Jwt(json 網(wǎng)絡(luò)令牌).我一直在我的 .NET Core 2.0 應(yīng)用程序中使用默認(rèn)身份作為身份驗(yàn)證/授權(quán),到目前為止它運(yùn)行良好.

                  I've been looking around and trying to do more research on .NET Core Identity (https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.1&tabs=visual-studio%2Caspnetcore2x) and Jwt (json web tokens). I've been rolling with the default Identity as authentication/authorization in my .NET Core 2.0 app and it has been working well so far.

                  我遇到了障礙,我認(rèn)為這是我理解 .NET Core 身份和 jwt 的方式.我的應(yīng)用程序有 MVC 和 web api.我理想地希望保護(hù) web api,但我聽說現(xiàn)在最好的方法是通過 jwt.好 - 酷.

                  I'm running into a roadblock and I think it's the way of my understanding of .NET Core identity and jwt. My application has MVC and an web api. I would ideally like to secure the web api, but I hear the best way to do that now is through jwt. Good - cool.

                  我可以繼續(xù)配置 jwt,然后將其用作我的身份驗(yàn)證/授權(quán) (https://blogs.msdn.microsoft.com/webdev/2017/04/06/jwt-validation-and-authorization-in-asp-net-core/),但是 - 我需要繼續(xù)啟動(dòng)一個(gè)新服務(wù)器作為 jwt 的授權(quán)服務(wù)器嗎?如果是這樣,我不會(huì)那樣做(太貴了).

                  I can go ahead and configure jwt and then use it as my authentication/authorization (https://blogs.msdn.microsoft.com/webdev/2017/04/06/jwt-validation-and-authorization-in-asp-net-core/), but - do I need to go ahead and spin up a new server to serve as the authorization server for jwt? If so, I'm not going to do that (too expensive).

                  如果我確實(shí)使用 jwt,我的 .NET Core 身份代碼會(huì)怎樣?那是不是必須要走了?如果它可以共存,我如何使用 Identity 授權(quán)我的 MVC 頁面并使用 jwt 授權(quán)我的 api 端點(diǎn)?

                  What about my .NET Core identity code if I do go with jwt? Does that have to go away then? If it can co-exist, how might I authorize my MVC pages with Identity and my api endpoints with jwt?

                  我知道這是一個(gè)開放式問題,但它的核心是:

                  I realize this is an open-ended question, but the core of it is:

                  .NET Core Identity 和 JWT 可以共存嗎?還是我必須選擇其中一個(gè)?我有 MVC 和一個(gè) web api,并希望保護(hù)兩者.

                  推薦答案

                  是的,你可以.邏輯過程在這個(gè)方法中:

                  Yes, you can. The logic process is in this method:

                  第 1 步:獲取用戶聲明

                  var identity = await GetClaimsIdentity(credentials.UserName, credentials.Password);

                  • 您將進(jìn)入 GetClaimsIdentity

                  • Into GetClaimsIdentity you will

                  private async Task<ClaimsIdentity> GetClaimsIdentity(string userName, string password)
                  {
                      if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
                          return await Task.FromResult<ClaimsIdentity>(null);
                  
                      var userToVerify = await _userManager.FindByNameAsync(userName);                
                  
                      if (userToVerify == null) {
                          userToVerify = await _userManager.FindByEmailAsync(userName);
                          if (userToVerify == null)  {
                              return await Task.FromResult<ClaimsIdentity>(null);
                          }
                      }
                      // check the credentials
                      if (await _userManager.CheckPasswordAsync(userToVerify, password))
                      {
                          _claims = await _userManager.GetClaimsAsync(userToVerify);
                  
                          return await Task.FromResult(_jwtFactory.GenerateClaimsIdentity(userToVerify.UserName, userToVerify.Id, _claims));
                      }
                      // Credentials are invalid, or account doesn't exist
                      return await Task.FromResult<ClaimsIdentity>(null);
                  }
                  

                  第 2 步:將您需要添加到令牌的所有用戶聲明分組 - 使用 System.Security.Claims

                   public ClaimsIdentity GenerateClaimsIdentity(string userName, string id, IList<Claim> claims)
                      {
                          claims.Add(new Claim(Helpers.Constants.Strings.JwtClaimIdentifiers.Id, id));
                  
                          // If your security is role based you can get then with the RoleManager and add then here as claims
                  
                          // Ask here for all claims your app need to validate later 
                  
                          return new ClaimsIdentity(new GenericIdentity(userName, "Token"), claims);
                      }
                  

                  第 3 步:然后返回您的方法,您必須生成并返回 JWT 令牌

                  jwt = await jwtFactory.GenerateEncodedToken(userName, identity);
                  return new OkObjectResult(jwt);
                  

                  • 要生成令牌,請執(zhí)行以下操作:

                    • To generate token do something like this:

                      public async Task<string> GenerateEncodedToken(string userName, ClaimsIdentity identity)
                      {
                          List<Claim> claims = new List<Claim>();
                          //Config claims
                          claims.Add(new Claim(JwtRegisteredClaimNames.Sub, userName));
                          claims.Add(new Claim(JwtRegisteredClaimNames.Jti, await _jwtOptions.JtiGenerator()));
                          claims.Add(new Claim(JwtRegisteredClaimNames.Iat, ToUnixEpochDate(_jwtOptions.IssuedAt).ToString(), ClaimValueTypes.Integer64));
                          //End Config claims
                          claims.AddRange(identity.FindAll(Helpers.Constants.Strings.JwtClaimIdentifiers.Roles));
                          claims.AddRange(identity.FindAll("EspecificClaimName"));
                      
                      
                          // Create the JWT security token and encode it.
                          var jwt = new JwtSecurityToken(
                              issuer: _jwtOptions.Issuer,
                              audience: _jwtOptions.Audience,
                              claims: claims,
                              notBefore: _jwtOptions.NotBefore,
                              expires: _jwtOptions.Expiration,
                              signingCredentials: _jwtOptions.SigningCredentials);
                      
                          var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt);
                      
                          return encodedJwt;
                      }
                      

                    • 有很多方法可以做到這一點(diǎn).最常見的是:驗(yàn)證身份用戶 --> 獲取用戶標(biāo)識符 --> 根據(jù)標(biāo)識符生成并返回令牌 --> 對端點(diǎn)使用授權(quán)

                      There are many ways to do this. The most common is: Validate Identity User --> Get User identifiers --> Generate and Return Token Based on Identifiers --> Use Authorization for endpoints

                      希望有幫助

                      這篇關(guān)于.NET Core 2.0 身份和 jwt?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                  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)
                        <tbody id='t5Y9Z'></tbody>

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

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

                            <tfoot id='t5Y9Z'></tfoot>
                            <legend id='t5Y9Z'><style id='t5Y9Z'><dir id='t5Y9Z'><q id='t5Y9Z'></q></dir></style></legend>
                            主站蜘蛛池模板: 夜夜骑av| 中文字幕一区二区三区乱码在线 | 欧美亚洲激情 | 免费一区二区三区 | 精品成人在线 | 成人av网站在线观看 | 91久久精品国产91久久性色tv | 一级免费看片 | 日本中文字幕一区 | 久久精品99| 欧美一区二区成人 | 久久国产精品99久久久大便 | 99久久久久久99国产精品免 | 亚洲一区 中文字幕 | 午夜精品久久久久久不卡欧美一级 | 好婷婷网 | 日本中文字幕在线视频 | 亚洲欧美精| www.蜜桃av| 国产精品欧美一区喷水 | 欧美视频免费在线 | 欧美精品网站 | 久久成人精品 | www.婷婷| 一本一道久久a久久精品蜜桃 | 亚洲欧美bt | 羞羞网站在线观看 | 亚洲最大av | 99视频在线免费观看 | 国产精品久久久久久久久久免费看 | 亚洲国产成人精 | 欧美精品一区三区 | 久久伊人精品一区二区三区 | 91不卡在线 | 在线视频国产一区 | 久在线| 国产精品一区二区三区四区 | 三级av免费 | 99精品视频一区二区三区 | 涩涩鲁亚洲精品一区二区 | 午夜精品久久久久久久久久久久 |