Owin 및 ASP.NET ID를 사용하여 웹 API 메서드를 보안하기 위해 OAuth 토큰을 사용하고 있습니다. 토큰 하위 시스템은 다음과 같이 설정됩니다.컨트롤러에 토큰 생성
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());
사용자 이름/암호를 기반으로 토큰을 요청한 다음 해당 토큰을 소비하는 데 유용합니다. 그러나 SPA를 렌더링하는 컨트롤러를 때면 사용자가 이미 인증 되었기 때문에 내보기에서 토큰을 생성하고 SPA에 다시 로그인하지 않고 Javascript 코드로 전달하려고합니다.
제 질문은 : 수동으로 내 토큰을 생성하여 SPA보기에 포함시킬 수 있습니까?
ASP.NET 웹 API 2에서는 이미 정적이며 이제는 'OAuthBearerOptions'에서'OAuthOptions'로 바뀌 었으므로 이제는 'Startup.OAuthOptions.AccessTokenFormat.Protect (티켓)'로 바뀌 었습니다. – Fred
'ExpiresUtc' 속성을'Startup.OAuthOptions.AccessTokenExpireTimeSpan'으로 설정할 수 있습니다. – Fred
컨트롤러를 통해 새로 고침 토큰을 생성하는 방법은 무엇입니까? –