Authorize requests in Swagger UI

Posted devin_zhou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Authorize requests in Swagger UI相关的知识,希望对你有一定的参考价值。

Authorize requests in Swagger UI

前面的文章讲到了Swagger+ASP.NET Core的使用,这里讲怎么把授权认证加入Swagger中。

国外的一篇文章:https://ppolyzos.com/2017/10/30/add-jwt-bearer-authorization-to-swagger-and-asp-net-core/

 

 app.UseSwaggerUi3(typeof(Startup).GetTypeInfo().Assembly, settings =>
            {
                settings.GeneratorSettings.DefaultPropertyNameHandling = PropertyNameHandling.CamelCase;
                settings.PostProcess = document =>
                {
                    document.Info.Version = "v1";
                    document.Info.Title = "ApiGateWay";
                    document.Info.Description = "移动平台Api网关";
                    document.SecurityDefinitions.Add("Bearer", new NSwag.SwaggerSecurityScheme
                    {
                        Description = "JWT Authorization header using the Bearer scheme. Example: "Bearer {token}"",
                        Name = "Authorization",
                        Type = NSwag.SwaggerSecuritySchemeType.ApiKey,
                        In = NSwag.SwaggerSecurityApiKeyLocation.Header
                    });
                    document.Security.Add(new NSwag.SwaggerSecurityRequirement { { "Bearer", new string[] { } }, });
                };


            });

 

技术分享图片

以上是关于Authorize requests in Swagger UI的主要内容,如果未能解决你的问题,请参考以下文章

第三方重定向后,Django request.user 成为 AnonymousUser

SWA实战:使用SWA进行微调,提高模型的泛化

DHCP中继器

身份服务器在 /connect/authorize/callback 中一直显示“显示登录:用户未通过身份验证”

Request.UrlReferrer

SWA(Stochastic Weight Averaging)实验