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

}

}

相关推荐
我科绝伦(Huanhuan Zhou)32 分钟前
Systemctl 与 Systemd 全面指南:Linux 系统服务管理详解
linux·服务器·网络
gplitems1231 小时前
Petslist – Pet listing WordPress Theme Free Download
linux·服务器·前端
1白天的黑夜11 小时前
Linux (5)| 入门进阶:Linux 权限管理的基础规则与实践
linux·运维·服务器·centos
济南java开发,求内推1 小时前
mongodb一个服务器部署多个节点
服务器·数据库·mongodb
是木子啦2 小时前
wpf passwordbox控件 光标移到最后
c#·wpf
布伦鸽2 小时前
C# WPF DataGrid使用Observable<Observable<object>类型作为数据源
开发语言·c#·wpf
world-wide-wait3 小时前
python高级04——网络编程
linux·服务器·网络
迎風吹頭髮3 小时前
Linux内核架构浅谈26-Linux实时进程调度:优先级反转与解决方案
linux·服务器·架构
等风来不如迎风去3 小时前
用你本地已有的私钥(private key)去 SSH 登录远程 Ubuntu 服务器
服务器·ubuntu·ssh
tomcsdn413 小时前
SMTPman高效稳定的smtp服务器使用指南解析
服务器·邮件营销·外贸开发信·邮件群发·域名邮箱·邮件服务器·红人营销