2016-06-22 2 views
0

에 대한 엔드 포인트를 사용자 지정이웹 API (2) - 내가 할 노력하고있어 토큰

OAuthOptions = new OAuthAuthorizationServerOptions 
    { 
     TokenEndpointPath = new PathString("/MyCustomRoutepath/Token"), 
     Provider = new ApplicationOAuthProvider(), 
     AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(60), 
     AllowInsecureHttp = true, 
     AuthenticationMode = AuthenticationMode.Active 
    }; 

이것을 달성하는 방법을 잘하지 않습니다. Web API가/token 경로를 자동으로 생성하는 것처럼 보입니다. 기존의 이유로 인해 사용할 수 없습니다. 어떻게 이것을 달성합니까? 새 컨트롤러 메소드 및 조치 메소드를 작성하고 엔드 포인트 토큰이 수행해야하는 작업을 수행해야합니까?

올바른 방향으로 알려주십시오. 문서는, 당신은 당신이 원하는 어떤 경로를 사용할 수 있습니다 예를 들어 /Token을 제공하는 동안 당신이

// Summary: 
//  The request path client applications communicate with directly as part of 
//  the OAuth protocol. Must begin with a leading slash, like "/Token". If the 
//  client is issued a client_secret, it must be provided to this endpoint. 
public PathString TokenEndpointPath { get; set; } 

을 원하는

답변

0

귀하의 질문은 불분명하다, 그러나 당신은 TokenEndpointPath에 사용자 정의 토큰 라우팅 경로를 설정할 수 있습니다. owin middleware가 지정한 경로에서 auth를 처리하므로 사용자 자신의 컨트롤러를 작성할 필요가 없습니다.

var oAuthServerOptions = new OAuthAuthorizationServerOptions 
{ 
    TokenEndpointPath = new PathString("/MyCustomRoutepath/Token"), 
    Provider = new ApplicationOAuthProvider(), 
    AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(60), 
    AllowInsecureHttp = true, 
    AuthenticationMode = AuthenticationMode.Active 
}; 

// Token Generation 
app.UseOAuthAuthorizationServer(oAuthServerOptions); 
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions()); 

참조 : Token Based Authentication using ASP.NET Web API 2, Owin, and Identity - Step 9: Add support for OAuth Bearer Tokens Generation

관련 문제