Sto utilizzando Owin e ASP.NET Identity per utilizzare i token OAuth per proteggere i miei metodi API Web. Il sottosistema token è configurato come tale:Genera token nel controller
var oauthOptions = new OAuthAuthorizationServerOptions()
{
TokenEndpointPath = new PathString("/Token"),
Provider = new SimpleAuthorizationServerProvider(),
AccessTokenFormat = new TicketDataFormat(app.CreateDataProtector(typeof(OAuthAuthorizationServerMiddleware).Namespace, "Access_Token", "v1")),
RefreshTokenFormat = new TicketDataFormat(app.CreateDataProtector(typeof(OAuthAuthorizationServerMiddleware).Namespace, "Refresh_Token", "v1")),
AccessTokenProvider = new AuthenticationTokenProvider(),
RefreshTokenProvider = new AuthenticationTokenProvider(),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
AllowInsecureHttp = true
};
app.UseOAuthAuthorizationServer(oauthOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
E le grandi opere per la richiesta di token basati su username/password e quindi consumando quelle pedine. Tuttavia, poiché l'utente è già autenticato quando si colpisce il controller che esegue il rendering della SPA, mi piacerebbe generare il token nella mia vista e passarlo al codice Javascript, invece di dover accedere di nuovo nella SPA.
Quindi la mia domanda è: come posso generare manualmente il mio token in modo che possa includerlo nella mia visualizzazione SPA?
In API Web ASP.NET 2 questo è già statico e ora è stato rinominato da 'OAuthBearerOptions' a' OAuthOptions', quindi ora 'Startup.OAuthOptions.AccessTokenFormat.Protect (ticket)'. – Fred
È possibile impostare la proprietà 'ExpiresUtc' su' Startup.OAuthOptions.AccessTokenExpireTimeSpan'. – Fred
Come generare un token di aggiornamento tramite il controller? –