【发布时间】:2015-10-05 04:47:44
【问题描述】:
我确信这是可能的,但不确定如何实现。我有一个 OWIN OAUTH 实现,它当前接受用户的用户名和密码,并根据数据库对它们进行身份验证。我想扩展它以传入 SmartCard Uid 以支持使用 SmartCard 进行单点登录。
我可以在 OWIN 登录中传递其他参数吗?如果可以,如何?基本前提是用户可以使用用户名/密码组合或 SmartCard uid 登录(如果传递 SmartCard uid 并且在数据库中找到,则应用程序将登录用户)
我目前正在传递username、password 和grant_type,我想将uid 添加到该列表中并在我的AuthorizationServiceProvider 中选择它。
我可以在OAuthGrantResourceOwnerCredentialsContext 上看到UserName、Password 和ClientId,但我看不到任何其他支持我想要实现的属性。
这是我目前在我的服务提供商中拥有的
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
var user = await this._userService.FindUser(context.UserName, context.Password);
if (user == null)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
identity.AddClaim(new Claim(ClaimTypes.Sid, user.Id.ToString()));
identity.AddClaim(new Claim(ClaimTypes.Role, "user"));
identity.AddClaim(new Claim("sub", context.UserName));
var secretKeyBytes = Encoding.UTF8.GetBytes(user.PasswordHash);
var props =
new AuthenticationProperties(
new Dictionary<string, string>
{
{ "dm:appid", user.Id.ToString() },
{ "dm:apikey", Convert.ToBase64String(secretKeyBytes) }
});
var ticket = new AuthenticationTicket(identity, props);
context.Validated(ticket);
}
我也希望能够从上下文中获取 Uid,但无论如何都看不到实现这一点,非常感谢任何帮助。
【问题讨论】:
标签: c# security authentication oauth owin