码迷,mamicode.com
首页 > 其他好文 > 详细

Authorize requests in Swagger UI

时间:2018-06-18 01:20:04      阅读:565      评论:0      收藏:0      [点我收藏+]

标签:ref   rop   set   generator   hand   string   cat   lin   lca   

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

标签:ref   rop   set   generator   hand   string   cat   lin   lca   

原文地址:https://www.cnblogs.com/devin_zhou/p/9194189.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!