|
|
@ -5,21 +5,19 @@ using BBWY.Server.API.Filters; |
|
|
|
using BBWY.Server.API.Middlewares; |
|
|
|
using BBWY.Server.Business; |
|
|
|
using BBWY.Server.Model; |
|
|
|
using BBWY.Server.Model.Dto; |
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer; |
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Microsoft.IdentityModel.Tokens; |
|
|
|
using Microsoft.OpenApi.Models; |
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
using Newtonsoft.Json.Serialization; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Reflection; |
|
|
|
using System.Text; |
|
|
|
using Yitter.IdGenerator; |
|
|
|
|
|
|
|
namespace BBWY.Server.API |
|
|
@ -97,28 +95,28 @@ namespace BBWY.Server.API |
|
|
|
Title = "步步为盈API", |
|
|
|
Description = "注意事项\r\n1.返回参数名称采用大驼峰命名\r\n2.ApiResponse为基础返回对象(Code,Data,Message),接口中所有的返回值均属于Data属性\r\n3.正常返回Code=200" |
|
|
|
}); |
|
|
|
// JWTÈÏÖ¤
|
|
|
|
//c.AddSecurityDefinition(JwtBearerDefaults.AuthenticationScheme, new OpenApiSecurityScheme
|
|
|
|
//{
|
|
|
|
// Scheme = JwtBearerDefaults.AuthenticationScheme,
|
|
|
|
// BearerFormat = "JWT",
|
|
|
|
// Type = SecuritySchemeType.ApiKey,
|
|
|
|
// Name = "Authorization",
|
|
|
|
// In = ParameterLocation.Header,
|
|
|
|
// Description = "Authorization:Bearer {your JWT token}<br/>",
|
|
|
|
//});
|
|
|
|
//c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
|
|
|
// {
|
|
|
|
// {
|
|
|
|
// new OpenApiSecurityScheme{Reference = new OpenApiReference
|
|
|
|
// {
|
|
|
|
// Type = ReferenceType.SecurityScheme,
|
|
|
|
// Id = JwtBearerDefaults.AuthenticationScheme
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// new string[] { }
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
//JWTÈÏÖ¤
|
|
|
|
c.AddSecurityDefinition(JwtBearerDefaults.AuthenticationScheme, new OpenApiSecurityScheme |
|
|
|
{ |
|
|
|
Scheme = JwtBearerDefaults.AuthenticationScheme, |
|
|
|
BearerFormat = "JWT", |
|
|
|
Type = SecuritySchemeType.ApiKey, |
|
|
|
Name = "Authorization", |
|
|
|
In = ParameterLocation.Header, |
|
|
|
Description = "Authorization:Bearer {your JWT token}<br/>", |
|
|
|
}); |
|
|
|
c.AddSecurityRequirement(new OpenApiSecurityRequirement |
|
|
|
{ |
|
|
|
{ |
|
|
|
new OpenApiSecurityScheme{Reference = new OpenApiReference |
|
|
|
{ |
|
|
|
Type = ReferenceType.SecurityScheme, |
|
|
|
Id = JwtBearerDefaults.AuthenticationScheme |
|
|
|
} |
|
|
|
}, |
|
|
|
new string[] { } |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
var executingAssembly = Assembly.GetExecutingAssembly(); |
|
|
|
var assemblyNames = executingAssembly.GetReferencedAssemblies().Union(new AssemblyName[] { executingAssembly.GetName() }).ToArray(); |
|
|
@ -132,18 +130,40 @@ namespace BBWY.Server.API |
|
|
|
c.IncludeXmlComments(xmlPath, true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
var secret = Configuration.GetSection("Secret").Value; |
|
|
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, x => |
|
|
|
{ |
|
|
|
x.SaveToken = true; |
|
|
|
x.RequireHttpsMetadata = false; |
|
|
|
x.TokenValidationParameters = new TokenValidationParameters() |
|
|
|
{ |
|
|
|
ClockSkew = TimeSpan.Zero, |
|
|
|
ValidateIssuerSigningKey = true, |
|
|
|
ValidateIssuer = false, |
|
|
|
ValidateAudience = false, |
|
|
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secret)), |
|
|
|
//ValidIssuer = issuer,
|
|
|
|
//ValidAudience = audience,
|
|
|
|
//ValidateLifetime = true
|
|
|
|
}; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, YunDingBusiness yunDingBusiness) |
|
|
|
{ |
|
|
|
yunDingBusiness.RefreshKey(); |
|
|
|
//app.UseSwagger(c => c.SerializeAsV2 = true)
|
|
|
|
// .UseSwaggerUI(c =>
|
|
|
|
// {
|
|
|
|
// c.SwaggerEndpoint("/swagger/v1/swagger.json", "BBWY API");
|
|
|
|
// c.RoutePrefix = string.Empty;
|
|
|
|
// });
|
|
|
|
var isAllowedSwagger = Configuration.GetValue<bool>("AllowedSwagger"); |
|
|
|
if (isAllowedSwagger) |
|
|
|
{ |
|
|
|
app.UseSwagger(c => c.SerializeAsV2 = true) |
|
|
|
.UseSwaggerUI(c => |
|
|
|
{ |
|
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "BBWY API"); |
|
|
|
c.RoutePrefix = string.Empty; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
//if (env.IsDevelopment())
|
|
|
|
//{
|
|
|
|