I have a simple (for troubleshooting only) implementation of OAuthAuthorizationServerProvider
where I am overriding the GrantResourceOwnerCredentials
method like this:
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
context.SetError("invalid_grant", "The user name or password is incorrect.");
}
The first line enables CORS and the second line simply invalidates the context. When testing using Chrome, this works as expected - I get back a 400 (Bad Request) when I POST to the token endpoint.
However, the moment I introduce any reference to System.Web.Helpers.Crypto
, CORS no longer works and I get back No 'Access-Control-Allow-Origin' header is present on the requested resource. For example CORS fails if I change the above to this:
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
var salt = System.Web.Helpers.Crypto.GenerateSalt();
context.SetError("invalid_grant", "The user name or password is incorrect.");
}
This is, of course, a contrived example that I came up with while troubleshooting the problem. In the actual GrantResourceOwnerCredentials, Crypto.VerifyHashedPassword() is used which causes the exact same problem. Also, as a test, I quickly wrapped the call to Crypto in another class but the problem persists.
Have I encountered a strange bug? Any direction with this would be appreciated.
UPDATE: Further investigating revealed that this problem apparently occurs with any reference to System.Web.Helpers. In other words, it is not specific to the System.Web.Helpers.Crypto class.