1

When authentication fails with in the GrantResourceOwnerCredentials method of SimpleAuthorizationServerProvider it returns;

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

However, I need to return my own JSON response by using a TEntity class, any help would be appreciated.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
bilmuhfk
  • 121
  • 2
  • 9
  • Please see the following for an answer: [Related post with answer][1] [1]: http://stackoverflow.com/questions/25032513/how-to-get-error-message-returned-by-dotnetopenauth-oauth2-on-client-side – Piotr Stulinski Sep 26 '15 at 06:01

1 Answers1

2

Would this do the trick for you ?

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

Returning

{
    "error": "MyCustomError",
    "error_description": "{\"NAME\":\"1\",\"name2\":\"2\",\"name3\":\"3\"}"
}
erPe
  • 558
  • 2
  • 11
  • 22
  • It's actually Owin's object which has properties as "error", "error_description" etc. However I need to serialize my own object as the result of failed authentication and give it to the clients as the response of their request to the service. Thank you, but unfortunately it is no help to my case. – bilmuhfk Apr 20 '15 at 21:07
  • And if you would do something like : context.Response.StatusCode = (int) HttpStatusCode.Unauthorized; context.Response.ReasonPhrase = "my own reason"; And on top of that one you could serialize your object and return it as body with context.Response.Body = ? – erPe Apr 20 '15 at 21:52