2014-06-20 20 views
5

I walkthrough this official ASP.NET tutorial e il token al portatore è pubblicato come sotto JSON.Personalizza token Bearer token Risultato JSON 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" 
} 

Vorrei aggiungere le proprietà del profilo utente insieme al risultato precedente per ridurre il numero di richieste dai client. L'esempio è il seguente ...

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

Il fornitore di OAuth che uso è da template di default ASP.NET (ApplicationOAuthProvider.cs) e OAuthOption è il seguente.

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

Come posso fare?

Si noti che la mia domanda è diversa da adding extra claims.

+1

ho scoperto che la mia domanda è duplicato: http://stackoverflow.com/q/24078905/361100 – Youngjae

risposta

10

Bene ecco la soluzione:

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

    return Task.FromResult<object>(null); 
} 
Problemi correlati