基于.NetCore3.1系列 ——认证授权方案之Swagger加锁

        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("V1", new OpenApiInfo
            {
                Version = "V1",   //版本 
                Title = $"XUnit.Core 接口文档-NetCore3.1",  //标题
                Description = $"XUnit.Core Http API v1",    //描述
                Contact = new OpenApiContact { Name = "艾三元", Email = "", Url = new Uri("http://i3yuan.cnblogs.com") },  
                License = new OpenApiLicense { Name = "艾三元许可证", Url = new Uri("http://i3yuan.cnblogs.com") }
            });
            var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);//获取应用程序所在目录(绝对,不受工作目录影响,建议采用此方法获取路径)
           //var basePath = AppContext.BaseDirectory;
            var xmlPath = Path.Combine(basePath, "XUnit.Core.xml");//这个就是刚刚配置的xml文件名
           // c.IncludeXmlComments(xmlPath);//默认的第二个参数是false,对方法的注释
             c.IncludeXmlComments(xmlPath,true); // 这个是controller的注释
            
            #region 加锁
            var openApiSecurity = new OpenApiSecurityScheme
            {
                Description = "JWT认证授权,使用直接在下框中输入Bearer {token}(注意两者之间是一个空格)\"",
                Name = "Authorization",  //jwt 默认参数名称
                In = ParameterLocation.Header,  //jwt默认存放Authorization信息的位置(请求头)
                Type = SecuritySchemeType.ApiKey
            };

            c.AddSecurityDefinition("oauth2", openApiSecurity);
            c.OperationFilter<AddResponseHeadersFilter>();
            c.OperationFilter<AppendAuthorizeToSummaryOperationFilter>();
            c.OperationFilter<SecurityRequirementsOperationFilter>();
            #endregion
        });

 

上一篇:The Ethereum devp2p and discv4 protocol Part II


下一篇:单元测试(一)——xUnit