I'm sure this is possible but not certain how to achieve. I have an OWIN OAUTH implementation that currently accepts the users Username and Password and authenticates them against a database. I would like to extend this to pass in a SmartCard Uid to support single sign-on with a SmartCard.
Can I pass in additional parameters in the OWIN login and if so how? The basic premise is that a user can login with a username/password combination Or a SmartCard uid (if passing a SmartCard uid and that is found in the database then the application will log the user in)
I am currently passing in username
, password
and grant_type
and I would like to add uid
to that list and pick that up in the my AuthorizationServiceProvider
.
I can see UserName
, Password
and ClientId
on the OAuthGrantResourceOwnerCredentialsContext
but I cannot see any other properties that would support what I am trying to achieve.
This is what I currently have in my service provider
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);
}
I want to be able to get Uid from the context as well but cannot see anyway of achieving this, any help is greatly appreciated.