Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass other parameters to OWIN Login?

I've got an ASP.NET Web API site, which is doing OWIN authentication, passing username and password, which magically appear in my GrantResourceOwnerCredentials method, inside the UserName and Password properties of the OAuthGrantResourceOwnerCredentialsContext parameter. No idea how this works, but it does.

Anyway, now I want to pass another parameter to the login method, which I'd like to access in that same GrantResourceOwnerCredentials method. But since I don't know how this magic works, that takes the UserName and Password parameters from the login request and copies them to the OAuthGrantResourceOwnerCredentialsContext parameter, I have no idea now how I could get access to my new parameter.

How do I do it?

like image 254
Shaul Behr Avatar asked Feb 23 '16 14:02

Shaul Behr


2 Answers

Try:

//read all parameters
IFormCollection parameters = await context.Request.ReadFormAsync();

if (parameters == null)
{
    context.SetError("invalid_grant", "Invalid request");
    return;
}
//get desired parameter
var deviceId = parameters.Get("device_id");
//check if it was send
if (deviceId == null)
{
    context.SetError("invalid_grant", "parameter 'device_id' is required");
    return;
}

Based on: https://stackoverflow.com/a/21244952/965722

like image 115
Misiu Avatar answered Sep 19 '22 23:09

Misiu


Couldn't find any way to do it using regular POST body parameters, so I added the parameter to the header, where it is available through the context.Request.Headers collection.

This is my answer for now; if anyone has a way to do this the normal way, through the POST body, I'd love to hear it.

like image 39
Shaul Behr Avatar answered Sep 19 '22 23:09

Shaul Behr