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?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With