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

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

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

      3. <legend id='K4JTl'><style id='K4JTl'><dir id='K4JTl'><q id='K4JTl'></q></dir></style></legend>

        Swashbuckle .NET Core 2 中 JWT 承載的授權

        Authorization for JWT bearer in Swashbuckle .NET Core 2(Swashbuckle .NET Core 2 中 JWT 承載的授權)
              <tbody id='gMQEn'></tbody>

            <tfoot id='gMQEn'></tfoot>

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

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

                • <bdo id='gMQEn'></bdo><ul id='gMQEn'></ul>
                  本文介紹了Swashbuckle .NET Core 2 中 JWT 承載的授權的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我使用身份驗證服務為我的應用生成的令牌.那里沒有問題.現在我已經介紹了 Swashbuckle 來記錄我的 API,我可以通過使用此代碼在每個請求中發送 JWT 來進行如下身份驗證;

                  I use tokens generated by an authentication service for my app. No problems there. Now I have introduced Swashbuckle to document my API an I can authenticate as follows by sending the JWT with every request using this code;

                  services.AddSwaggerGen(c =>
                  {
                      var a = new ApiKeyScheme();
                      //c.AddSecurityDefinition("Bearer", new ApiKeyScheme()
                      //{ In = "header", Description = "Please insert JWT with Bearer into field", Name = "Authorization", Type = "apiKey" });
                  
                      c.OperationFilter<AuthorizationHeaderParameterOperationFilter>();
                  
                      c.SwaggerDoc("v2", new Info
                      {
                          Version = "v2",
                          Title = "MyTitle",
                          Description = "An interface for ...",
                          TermsOfService = "None",
                          Contact = new Contact() { Name = "MyApp", Email = "a@example.com", Url = "www.example.com" }
                      });
                      // Set the comments path for the Swagger JSON and UI.
                      var basePath = AppContext.BaseDirectory;
                      var xmlPath = Path.Combine(basePath, "cpDataCore.xml");
                      c.IncludeXmlComments(xmlPath);
                  });
                  
                  public class AuthorizationHeaderParameterOperationFilter : IOperationFilter
                  {
                      public void Apply(Operation operation, OperationFilterContext context)
                      {
                          var filterPipeline = context.ApiDescription.ActionDescriptor.FilterDescriptors;
                          var isAuthorized = filterPipeline.Select(filterInfo => filterInfo.Filter).Any(filter => filter is AuthorizeFilter);
                          var allowAnonymous = filterPipeline.Select(filterInfo => filterInfo.Filter).Any(filter => filter is IAllowAnonymousFilter);
                  
                          if (isAuthorized && !allowAnonymous)
                          {
                              if (operation.Parameters == null)
                                  operation.Parameters = new List<IParameter>();
                  
                              operation.Parameters.Add(new NonBodyParameter
                              {
                                  Name = "Authorization",
                                  In = "header",
                                  Description = "access token",
                                  Required = true,
                                  Type = "string"
                              });
                          }
                      }
                  }
                  

                  這給了我以下標題 - 正如預期的那樣

                  Which gives me the following header - as expected

                  accept:application/json
                  Accept-Encoding:gzip, deflate, br
                  Accept-Language:en-AU,en;q=0.9
                  Authorization:Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9naXZlbm5hbWUiOiJEZW5uaXMiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9zdXJuYW1lIjoiR2FzY29pZ25lIiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvbmFtZSI6ImRlbm5pc2ciLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9zaWQiOiI1NCIsIlJlZnJlc2hUb2tlbiI6IjY5OTA1NTFmLTNhOTQtNDVmYi1hYjc2LTZlOTQyNGE3NjJmOCIsIkFsbERhdGFSZWFkT25seUZvckFwcHJvdmVycyI6IlRydWUiLCJQcm9qZWN0SUQiOiI2IiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoic3lzYWRtaW4iLCJuYmYiOjE1MTk2MzY2NDIsImV4cCI6MTUxOTYzODQ0MiwiaXNzIjoiaHR0cHM6Ly9kYXRhLmNpdmlscHJvc29mdHdhcmUuY29tLyIsImF1ZCI6Imh0dHBzOi8vcm1zLmNpdmlscHJvc29mdHdhcmUuY29tLyJ9.nBEZgzcmZVGhFJmKI8u7p7g7xPU13HEAGJu_lrWylnc
                  Connection:keep-alive
                  Cookie:username=demo; jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9naXZlbm5hbWUiOiJUcm95IiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvc3VybmFtZSI6IkVsZGVyIiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvbmFtZSI6InRyb3kiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9zaWQiOiI1IiwiUmVmcmVzaFRva2VuIjoiMTNhNzRmNDQtNmVmOC00MDQ3LTlmYWYtOWQ3MzI4MmNhZjQ4IiwiUHJvamVjdElEIjoiLTEiLCJuYmYiOjE1MDUwOTc3MjEsImV4cCI6MTUwNTA5ODYyMSwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo2MDAwMC8iLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjYwMDAwLyJ9.8You0XiUlvdHb2TRuDzaiXv6r74v7ga1Av_Z3ikmblU
                  Host:localhost:60000
                  Referer:http://localhost:60000/swagger/
                  User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36
                  

                  雖然,我不確定 Cookie 是從哪里來的.這與我的代碼無關.我只是忽略它 - 到目前為止一切都很好.

                  Although, I am not sure where the Cookie is coming from. That is nothing to do with my code. I just ignore it - so far so good.

                  問題在于,這意味著每次請求都必須輸入令牌,這很痛苦.理想情況下,我想使用內置的 swagger 接口進行身份驗證 - 根據幾篇文章,我應該能夠做到這一點;

                  The problem is that this means the token has to be entered with every request which is a pain. Ideally, I would want to authenticate using the inbuilt swagger interface - according to several articles, I should be able to do this;

                  c.AddSecurityDefinition("Bearer", new ApiKeyScheme()
                  { In = "header", Description = "Please insert JWT with Bearer into field", Name = "Authorization", Type = "apiKey" });
                  

                  這很好用,我可以添加令牌,我似乎缺少將令牌添加到每個請求的標頭的步驟.如果我只是添加身份驗證,那么這會給我以下標頭,這當然無法通過身份驗證.

                  This works fine, and I can add the token, there just seems to be a step I am missing to add the token to the header of every request. If I just add the auth, then this gives me the following header, which of course fails the authentication.

                  GET /api/ApprovalItemTypes HTTP/1.1
                  Host: localhost:60000
                  Connection: keep-alive
                  accept: application/json
                  User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36
                  Referer: http://localhost:60000/swagger/
                  Accept-Encoding: gzip, deflate, br
                  Accept-Language: en-AU,en;q=0.9
                  Cookie: username=demo; jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW5_xxx__LTEiLCJuYmYiOjE1MDUwOTc3MjEsImV4cCI6MTUwNTA5ODYyMSwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo2MDAwMC8iLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjYwMDAwLyJ9.8You0XiUlvdHb2TRuDzaiXv6r74v7ga1Av_Z3ikmblU
                  

                  為了讓請求包含每個后續請求的令牌,我還需要做什么?

                  What else do I need to do in order to get the request to include the token for every subsequent request?

                  推薦答案

                  最后我搬到了 NSwag,所以我不確定最初的問題是什么.Nswag中的解決方案如下;

                  In the end I moved to NSwag so I am not sure what the original issue was. The solution in Nswag is as follows;

                      services.AddSwaggerDocument(document =>
                          {
                              document.DocumentName = "CPSwagger";
                              document.Title = "My Mobile API";
                              document.Version = "v10.3.4";
                              document.Description = "An interface for some software.";
                  
                              document.DocumentProcessors.Add(
                                  new SecurityDefinitionAppender("JWT token", new NSwag.OpenApiSecurityScheme
                                  {
                                      Type = NSwag.OpenApiSecuritySchemeType.ApiKey,
                                      Name = "Authorization",
                                      Description = "Copy 'Bearer ' + valid JWT token into field",
                                      In = NSwag.OpenApiSecurityApiKeyLocation.Header
                                  }));
                              document.OperationProcessors.Add(new OperationSecurityScopeProcessor("JWT token"));
                          });
                  

                  這篇關于Swashbuckle .NET Core 2 中 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)
                      <bdo id='Jwlgy'></bdo><ul id='Jwlgy'></ul>
                        <tfoot id='Jwlgy'></tfoot>

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

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

                            主站蜘蛛池模板: 亚洲欧美aⅴ | 九一在线观看 | 色在线免费视频 | 成人a网 | 亚洲高清在线免费观看 | 亚洲一区二区三区四区五区中文 | 午夜精品一区二区三区在线观看 | 国产激情自拍视频 | 午夜小影院 | 一区二区久久电影 | 久久一二区 | 日本人做爰大片免费观看一老师 | 另类视频区 | 国产在线精品一区二区三区 | 在线视频国产一区 | 亚洲人人 | 亚洲精品久久久久久国产精华液 | 日本在线视频一区二区 | 国产精品久久久久久久久婷婷 | 欧美一区二区三区四区视频 | 91se在线 | 国产高清免费视频 | 日韩久久久久久久久久久 | 最新国产视频 | 久久精品国产免费 | 91福利网 | 中文久久 | 亚洲视频二区 | 中文字幕精品一区 | 激情综合五月 | 免费成人在线网站 | 国产一区在线免费观看视频 | 中文成人无字幕乱码精品 | 欧美激情一区二区三区 | 亚洲国产欧美日韩 | 成人精品一区亚洲午夜久久久 | 婷婷午夜天 | 国产乱人伦 | 免费在线观看一区二区 | 国产一区二区精品在线观看 | 色婷婷影院 |