基于Docker for windows部署C#.net Core后端服务如何调用其它认证服务

public class Startup

{

public Startup(IConfiguration configuration)

{

Configuration = configuration;

}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.

public void ConfigureServices(IServiceCollection services)

{

services.Configure<Configure>(Configuration.GetSection("Token"));

services.AddControllers();

var serverVersion = new MySqlServerVersion(new Version(8, 0, 25));

services.AddDbContext<DBServiceContext>(options =>

{

options.UseMySql(Configuration.GetConnectionString("DbConnection"), serverVersion);

});

services.AddSwaggerGen(c =>

{

c.SwaggerDoc("v1", new OpenApiInfo { Title = "一板一码模拟后台接口", Version = "v1" });

//c.IncludeXmlComments(string.Format("{0}/RunnerService.xml", AppDomain.CurrentDomain.BaseDirectory));

});

services.AddAuthentication(options =>

{

options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;

options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;

}).AddJwtBearer(x =>

{

x.RequireHttpsMetadata = false;

x.SaveToken = true;

x.TokenValidationParameters = new TokenValidationParameters

{

ValidateIssuerSigningKey = true,//是否调用对签名securityToken的SecurityKey进行验证

IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration.GetSection("Token").GetSection("Secret").Value.ToString())),//签名秘钥

ValidateIssuer = true,//是否验证颁发者

ValidIssuer = Configuration.GetSection("Token").GetSection("Issuer").Value.ToString(),

ValidateAudience = true, //是否验证接收者

ValidAudience = Configuration.GetSection("Token").GetSection("Audience").Value.ToString(),//接收者

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)

{

if (env.IsDevelopment())

{

app.UseDeveloperExceptionPage();

//app.UseSwagger();

//app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "RunnerService v1"));

//app.UseSwaggerUI(c =>

//{

// c.SwaggerEndpoint("/swagger/v1/swagger.json", "RunnerService v1");

// c.RoutePrefix = string.Empty;//设置根节点访问

//});

}

app.UseSwagger();

app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Service v1"));

app.UseHttpsRedirection();

app.UseRouting();

app.UseAuthentication();

app.UseAuthorization();

app.UseEndpoints(endpoints =>

{

endpoints.MapControllers();

});

}

}

配置数据

{

"Logging": {

"LogLevel": {

"Default": "Information",

"Microsoft": "Warning",

"Microsoft.Hosting.Lifetime": "Information"

}

},

"AllowedHosts": "*",

"ConnectionStrings": {

"DbConnection": "server=ip地址;port=3306;database=数据库名称;user=root;password=123456;"

},

"Token": {

"Issuer": "test",

"Audience": "test",

"Secret": "123456",

"AccessExpiration": "30"

}

}

相关推荐
咕噜签名-铁蛋2 分钟前
数据洪流时代的存储革命:从磁带到云原生的进化之路
服务器
robator11 分钟前
ubuntu 22.04 升级nvidia显卡驱动、cuda 和cudnn
linux·服务器·ubuntu
Eiceblue22 分钟前
通过 C# 将 RTF 文档转换为图片
开发语言·算法·c#
发光小北26 分钟前
SG-TCP232-110(单通道串口服务器)特点与功能介绍
服务器·网络·单片机
翼龙云_cloud29 分钟前
亚马逊云渠道商:AWS Lightsail的常见问题怎么解决?
运维·服务器·云计算·aws
风乍起吹皱一池春水32 分钟前
Linux 文件及用户的一些日常命令
linux·服务器
渡我白衣36 分钟前
计算机组成原理(5):计算机的性能指标
服务器·网络·c++·人工智能·网络协议·tcp/ip·网络安全
炼丹精神小伙39 分钟前
VS Code 多跳板机连到目标服务器
运维·服务器
同聘云41 分钟前
阿里云国际站服务器防火墙如何使用及防护???
服务器·阿里云·云计算
c#上位机1 小时前
halcon求图像灰度最大值和最小值——min_max_gray
图像处理·人工智能·计算机视觉·c#·上位机·halcon