返回自定义"无效授权"来自GrantResourceOwnerCredentials的错误消息

时间:2015-03-10 16:52:15

标签: c# asp.net-web-api2 owin bearer-token

当身份验证失败时,SimpleAuthorizationServerProvider的GrantResourceOwnerCredentials方法返回;

context.SetError("invalid_grant", "The user name or password is incorrect.");

但是,我需要使用TEntity类返回自己的JSON响应,我们将不胜感激。

1 个答案:

答案 0 :(得分:1)

这会为你做到这一点吗?

            context.SetError("MyCustomError", JsonConvert.SerializeObject(new removeit()
            {
                NAME = "1",
               name2 = "2",
               name3 = "3"
            }));

返回

{
    "error": "MyCustomError",
    "error_description": "{\"NAME\":\"1\",\"name2\":\"2\",\"name3\":\"3\"}"
}