-
Notifications
You must be signed in to change notification settings - Fork 116
配置 Token
Grissom edited this page Jul 19, 2018
·
1 revision
- 生成 token 的规则
var builder = new ServiceHostServerBuilder(new Autofac.ContainerBuilder())
.UseLog4netLogger()
.LoadServices(new string[] { })
.UseDotNettyForTransfer(options.Server, options.Port)
.UseConsulForDiscovery(options.ConsulIp, options.ConsulPort, options.ConsulServiceCategory, $"{options.Server}:{options.Port}")
.UseJoseJwtForOAuth<DotNettyAddress>(new JwtAuthorizationOptions
{
SecretKey = options.JwtSecret,
ExpireTimeSpan = new TimeSpan(3, 0, 0, 0),
ServerIp = options.Server,
ServerPort = options.Port,
TokenEndpointPath = "api/oauth/token?username=&password=",
CheckCredential = new Action<JwtAuthorizationContext>(ctx =>
{
if (ctx.UserName == "admin" && ctx.Password == "admin")
{
ctx.AddClaim("role", "admin");
}
else if (ctx.UserName == "test" && ctx.Password == "test")
{
ctx.AddClaim("role", "guest");
}
else
{
ctx.Rejected("username or password is incorrect.", "");
}
}),
ValidateLifetime = true,
})
;
ServerIp ServerPort SecretKey ValidateLifetime ExpireTimeSpan ValidateIssuer ValidIssuer ValidateAudience ValidAudience TokenEndpointPath CheckCredential
- 指定生成Token 时的一些配置项,包括
var builder = new ServiceHostServerBuilder(new Autofac.ContainerBuilder())
.UseLog4netLogger()
.LoadServices(options.Services)
.UseDotNettyForTransfer(options.Server, options.Port)
.UseConsulForDiscovery(options.ConsulIp, options.ConsulPort, options.ConsulServiceCategory, $"{options.Server}:{options.Port}")
.UseJoseJwtForOAuth<Jimu.DotNettyAddress>(new Jimu.Server.OAuth.JwtAuthorizationOptions
{
SecretKey = options.JwtSecret,
})
;
SecretKey 必填,和生成 token 服务器配置一致 ValidIssuer 可选,和生成 token 服务器配置一致 ValidAudience 可选,和生成 token 服务器配置一致