8

I walkthrough this official ASP.NET tutorial, and the bearer token is published as below JSON.

{
    "access_token":"boQtj0SCGz2GFGz[...]",
    "token_type":"bearer",
    "expires_in":1209599,
    "userName":"Alice",
    ".issued":"Mon, 14 Oct 2013 06:53:32 GMT",
    ".expires":"Mon, 28 Oct 2013 06:53:32 GMT"
}

I'd like to add user profile properties along with the above result in order to reduce number of requests from clients. The example is as below...

{
    "access_token":"boQtj0SCGz2GFGz[...]",
    "token_type":"bearer",
    "expires_in":1209599,
    "userName":"Alice",
    ".issued":"Mon, 14 Oct 2013 06:53:32 GMT",
    ".expires":"Mon, 28 Oct 2013 06:53:32 GMT",
    "Notifications":35,
    "IsEventMember":true,
    "Promotion":324372
}

The oauth provider I use is from default ASP.NET template (ApplicationOAuthProvider.cs) and OAuthOption is as below.

            OAuthOptions = new OAuthAuthorizationServerOptions
        {
            TokenEndpointPath = new PathString("/Token"),
            Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
            AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
            AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
            AllowInsecureHttp = true
        };

How can I make it?

Note that my question is different from adding extra claims.

Youngjae
  • 24,352
  • 18
  • 113
  • 198

1 Answers1

14

Well here is the solution:

public override async Task TokenEndpoint(OAuthTokenEndpointContext context)
{
    context.AdditionalResponseParameters.Add("username", "user@mail.com");

    return Task.FromResult<object>(null);
}
JuChom
  • 5,717
  • 5
  • 45
  • 78