开源DDD设计模式框架YMNNetCoreFrameWork第五篇-Swagger增加权限认证

2021-04-19 04:28

阅读:561

标签:directory   uri   clu   cname   说明   attr   options   tac   name   

配置文件
services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Version = "v0.1.0",//版本号 Title = "尹大师框架说明,QQ:1390788386",//文档标题 Description = "框架说明文档",//文档描述 Contact = new OpenApiContact { Name = "道法自然", Email = "1390788386@qq.com"}//联系人 }); // Assign scope requirements to operations based on AuthorizeAttribute //options.OperationFilter(); //设置swagger的xml文档 //c.DocInclusionPredicate((docName, description) => true); //// Define the BearerAuth scheme that‘s in use //c.AddSecurityDefinition("bearerAuth", new ApiKeyScheme() //{ // Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", // Name = "Authorization", // In = "header", // Type = "apiKey" //}); //// Assign scope requirements to operations based on AuthorizeAttribute //c.OperationFilter(); // c.DocInclusionPredicate((docName, description) => true); //c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme //{ // Description = "Authorization format : Bearer {token}", // Name = "Authorization", // In = "header", // Type = "apiKey" //});//api界面新增authorize按钮 c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "西方输入Token,使用Bearer开头", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, BearerFormat = "JWT", Scheme = "Bearer" }); c.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } }, new string[] { } } }); string filepath = $"{AppContext.BaseDirectory}YMNNetCoreFrameWork.Host.xml"; c.IncludeXmlComments(filepath); });

技术图片

 

开源DDD设计模式框架YMNNetCoreFrameWork第五篇-Swagger增加权限认证

标签:directory   uri   clu   cname   说明   attr   options   tac   name   

原文地址:https://www.cnblogs.com/topguntopgun/p/12271530.html


评论


亲,登录后才可以留言!