天天看點

如何自定義oauthauthorizationserverprovider錯誤資訊?

We are using the <code>OAuthAuthorizationServerProvider</code> class to do authorization in our ASP.NET Web Api app.

If the provided username and password is invalid in <code>GrantResourceOwnerCredentials</code>, the call

Produces the following Json result:

Is there any way to customize this error result?

I would like to make it consistent with default error message format used in other parts of the API:

Is this possible to achieve with the <code>OAuthAuthorizationServerProvider</code>?

2016年10月12日24分24秒

This is how I did it.

2016年10月11日24分24秒

+1 for Dasun's answer. Here is how I extended it a bit further.

The .ToJsonString() is another extension method that uses the Newtonsoft.Json library.

Usage:

學習交流群:364976091