私はOAuth
GrantResourceOwnerCredentials
この方法をオーバーライド:OAuthのトークンとカスタムエラー
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
using (var userManager = _userManagerFactory())
{
var user = await userManager.FindAsync(context.UserName, context.Password);
if (user == null)
{
context.Rejected();
context.SetError("invalid_grant", "Invalid username or password");
return;
}
トークンエンドポイント:
OAuthOptions = new OAuthAuthorizationServerOptions
{
AuthenticationMode = AuthenticationMode.Active,
TokenEndpointPath = new PathString("/Token"),
それは作品と私はエラークライアント側を受信します。
responseText: "{"error":"invalid_grant"...ame or password"}"
responseJSON: Object { error="invalid_grant", error_description="Invalid username or password"}
status: 400
statusText: "Bad Request"
ここで、カスタムエラーを設定しようとすると、web.config
ファイル:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="403" subStatusCode="-1"/>
<remove statusCode="404" subStatusCode="-1"/>
<remove statusCode="500" subStatusCode="-1"/>
<error statusCode="403" path="/Error/Unauthorized" responseMode="ExecuteURL"/>
<error statusCode="404" path="/Error/NotFound" responseMode="ExecuteURL"/>
<error statusCode="500" path="/Error/ServerError" responseMode="ExecuteURL"/>
</httpErrors>
私は、JSONメッセージなしBad Request
を受け取る:
responseText:"Bad Request"
status 400
statusText:"Bad Request"
私は、カスタムエラーがすべての要求に影響を与え、正常な動作を妨げると思います。
私は、web.configファイルでこれを追加しようとしました:
<location path="Token">
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<httpErrors errorMode="DetailedLocalOnly" existingResponse="PassThrough">
<clear />
</httpErrors>
</system.webServer>
</location>
これは、運用サーバー上のIIS Express
しかしIIS 8.5
と私の開発マシン上で動作します、それを無視しているようです。
あなたはhereからサンプルプロジェクトをダウンロードすることができます。ちょうどページに行き、ログインボタンを押してください。私もweb.config
ファイルにコメントしました。
誰かが正しい方向に向かうことができますか?
_「それは作品と私はエラークライアント側を受ける。」_どのエラーコードとあなたはJSONを期待していますか? – khlr
質問を更新しました。 – danyolgiax
最小限の検証可能な例を提供できますか? – khlr