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

}

}

相关推荐
无言听风雨丶4 小时前
Linux 容器本质探秘:Cgroup 与 Namespace 深度解析与实战
linux·运维·服务器·kubernetes
数字新视界4 小时前
机房动环监控系统在提升数据中心能效与安全中的应用探索
大数据·服务器·数据库·动环监控系统·动力与环境监控系统
ManageEngineITSM6 小时前
工单分类怎么设计?类别、子类别与自动分派的实用方法
大数据·服务器·数据库·人工智能·分类·数据挖掘
WarPigs6 小时前
C#把byte[]以十六进制打印,带分割符
c#
CANI_PLUS6 小时前
电脑文件共享
运维·服务器
Linux界最忧郁之人6 小时前
华为云ECS&IMS&AS实战|弹性云服务器、私有镜像、弹性伸缩完整实验
linux·运维·服务器·centos·华为云·openstack
无言听风雨丶7 小时前
systemd 与信号 / 僵尸进程:Linux 进程管理的底层逻辑与排错
linux·服务器·网络
暴走约伯7 小时前
【VFX工具链源码拆解 04】拯救丢失的绑定:Timeline 一键克隆与层级相对路径重映射算法
unity·c#·游戏引擎·硬件工程
1-1=07 小时前
C# 反射
c#·.net·.netcore
小贾要学习7 小时前
【C++后端开发项目】Reactor 模型 / C++ 仿写 muduo HTTP 服务器:让底层网络库真正跑起网页
linux·服务器·c++·http·网络编程·muduo·reactor模型