基于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"

}

}

相关推荐
小杰3125 分钟前
ZLMediakit源码梳理
服务器·音视频·流媒体·zlmediakit
吹晚风吧12 分钟前
解决vite打包,base配置前缀,nginx的dist包找不到资源
服务器·前端·nginx
不愿透露姓名的大鹏23 分钟前
Linux实操:ext4转换为xfs(含完整步骤+避坑指南)
linux·服务器
追雨潮28 分钟前
BGE-M3 多语言向量模型实战:.NET C# 从原理到落地
开发语言·c#·.net
一根狗尾巴草1 小时前
【Linux】linux软链接硬链接区别
linux·运维·服务器
春日见1 小时前
TEST文件夹:Pytest,集成测试,单元测试
服务器·人工智能·驱动开发·单元测试·计算机外设·集成测试·pytest
riNt PTIP1 小时前
RustDesk搭建公网中继服务器远控内网机器(完整版)
运维·服务器
不愿透露姓名的大鹏2 小时前
VMware vSphere开通用户和分配权限
linux·运维·服务器·vmware
CheerWWW2 小时前
GameFramework——Download篇
笔记·学习·unity·c#
童话的守望者2 小时前
matrix-breakout-2-morpheus靶机通关
linux·运维·服务器