2016-06-22 7 views
0

のエンドポイントをカスタマイズし、このウェブAPI 2 - 私がやろうとしているトークン

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

これを達成する方法がわかりません。ウェブAPIが自動的に/トークンルートを作成するように見えます。私はいくつかの遺産の理由のためにそれを使用することはできません。どのように私はこれを達成するのですか?私は新しいコントローラメソッドとアクションメソッドを作成し、トークンエンドポイントが何をすべきであるかは何でもしてください。

正しい方向に指摘してください。ドキュメントは、あなたが望む任意のパスを使用することができ、例として/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ミドルウェアが指定したパスで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

関連する問題