2014-06-20 10 views
5

Ich Durchlauf this official ASP.NET tutorial, und das Bearer-Token wird wie folgt JSON veröffentlicht.Bearer Token JSON Ergebnis in ASP.NET WebApi 2

{ 
    "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" 
} 

Ich möchte Benutzerprofileigenschaften zusammen mit dem obigen Ergebnis hinzufügen, um die Anzahl der Anfragen von Clients zu reduzieren. Das Beispiel ist als unten ...

{ 
    "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 
} 

Die oauth Provider ich benutze, ist von ASP.NET-Standardvorlage (ApplicationOAuthProvider.cs) und OAuthOption ist als unten.

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

Wie kann ich es machen?

Beachten Sie, dass meine Frage unterscheidet sich von adding extra claims.

+1

Ich fand, dass meine Frage dupliziert: http://stackoverflow.com/q/24078905/361100 – Youngjae

Antwort

10

Nun, hier ist die Lösung:

public override async Task TokenEndpoint(OAuthTokenEndpointContext context) 
{ 
    context.AdditionalResponseParameters.Add("username", "[email protected]"); 

    return Task.FromResult<object>(null); 
} 
Verwandte Themen