0

As a follow up question to this one:

OWIN Web api 2 adding additional logic to Bearer authorization

Can I call context.SetError twice like the below, to give 2 values back to the requestor? If not, what's the right way to do that?

        if (user == null)
        {
            context.SetError("invalid_grant", "The user name or password is incorrect.");
            context.SetError("error_code", 69);

            return;
        }
Prasanth
  • 3,029
  • 31
  • 44
user230910
  • 2,353
  • 2
  • 28
  • 50

2 Answers2

1

You're right, you cannot call it twice. I found this answer to a similar issue to be very useful in my case: https://stackoverflow.com/a/32934494/6033048

I needed to add an error_code besides error and error_description so I extended OAuthGrantResourceOwnerCredentialsContext like in user2325333's example.

Community
  • 1
  • 1
nvrn23
  • 26
  • 3
0

Ok, so for those people visiting via future search engines:

NO. You cannot call it twice to provide 2 values back. I eventually just serialized (To Json) what I wanted to say and stuffed it into the error_description field. A developer with half a brain would be able to interpret it back into an object and use it appropriately.

user230910
  • 2,353
  • 2
  • 28
  • 50