How to pass some more parameters to token endpoint

2019-07-12 19:30发布

i need to pass some more parameters to token endpoint as

grant_type=password&username=Alice&password=password123&peop1=value&Prop2=value

to get the token

How can i pass these and where i can get them on the server

3条回答
在下西门庆
2楼-- · 2019-07-12 19:40

Solution for OWIN but you can catch the idea.

Pass parameters:

grant_type=password&username=Alice&password=password123&peop1=value&Prop2=value

Get them in your authorization server provider:

public class YourAuthorizationServerProvider : OAuthAuthorizationServerProvider
{
    ...
    public override Task ValidateTokenRequest(OAuthValidateTokenRequestContext context)
    {
        context.Request.Body.Position = 0;
        var reader = new StreamReader(context.Request.Body);
        var body = reader.ReadToEnd();                         <-- you got them all!
        return base.ValidateTokenRequest(context);
    }
}

Don't forget to pass your authorization server provider in configuration:

...
var options = new OAuthAuthorizationServerOptions
{
    Provider = new YourAuthorizationServerProvider()
};
app.UseOAuthAuthorizationServer(options);
...
查看更多
不美不萌又怎样
3楼-- · 2019-07-12 19:54

OAuth2 resource owner password flow defines these parameters. If you need to do something else when authenticating a user you should look into the Implicit Flow -- that way you can code a custom login screen to accept any data you need from the user.

查看更多
地球回转人心会变
4楼-- · 2019-07-12 19:59

On your OWIN OAuthAuthorizationServerProvider you can catch your paramter like this :

public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
    string peop1 = context.Parameters["peop1"];

    //You can pass if you need the parameter to your GrantResourceOwnerCredentials
    context.OwinContext.Set<string>("as:peop1", peop1);
}


public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
    var peop1 = context.OwinContext.Get<string>("as:peop1");
查看更多
登录 后发表回答