title: "error": "invalid_client" from custom OWIN implementation
body: <p>I am implementing OWIN authentication on a mysql backend, I dont thnk thats a problem as my registration work pretty well. I have basically worked off <a href="http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/" rel="nofollow">this post</a> (i.e. nicked most of the code).</p>
  
  <p>I am also using DI via autofac so I have changed a few things around to inject dependencies into the <code>SimpleAuthorizationServerProvider</code></p>
  
  <p><strong>THE PROBLEM</strong>
  I post grant_type=password, username and password to <code>http://localhost/myappurl/token</code> and I get back "error":"invalid_client". I get no hits when I try to debug so its probably failing in the library and not getting to my own code. Does anyone know why this would be?</p>
  
  <p>Please pardon the lengthy code, I have no idea where the issue could be so I have posted everything I think is relevant, if anyone needs to see more code, please ask. </p>
  
  <p><strong>SimpleAuthorizationServerProvider</strong></p>
  
  <pre><code> public class SimpleAuthorizationServerProvider : OAuthAuthorizationServerProvider
  {
      private readonly IUserService _userService;
  
      public SimpleAuthorizationServerProvider(IUserService userService)
      {
          _userService = userService;
      }
      public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
      {
          context.Validated();
      }
  
      public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
      {
  
          context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
  
          var authenticate = await _userService.FindUser(context.UserName, context.Password);
  
              if (!authenticate)
              {
                  context.SetError("invalid_grant", "The user name or password is incorrect.");
                  return;
              }
  
          var identity = new ClaimsIdentity(context.Options.AuthenticationType);
          identity.AddClaim(new Claim("sub", context.UserName));
          identity.AddClaim(new Claim("role", "user"));
  
          context.Validated(identity);
  
      }
  }
  </code></pre>
  
  <p><strong>Startup</strong></p>
  
  <pre><code>public partial class Startup
  {               
      public void ConfigureAuth(IAppBuilder app)
      {
          HttpConfiguration config = new HttpConfiguration();
          ConfigureOAuth(app, (IOAuthAuthorizationServerProvider)config.DependencyResolver.GetService(typeof(IOAuthAuthorizationServerProvider)));
          app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
          app.UseWebApi(config);
      }
  
      public void ConfigureOAuth(IAppBuilder app, IOAuthAuthorizationServerProvider provider)
      {
          OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
          {
              AllowInsecureHttp = true,
              TokenEndpointPath = new PathString("/token"),
              AccessTokenExpireTimeSpan = TimeSpan.FromDays(90),
              Provider = provider,
              ApplicationCanDisplayErrors=true, 
          };
          app.UseOAuthAuthorizationServer(OAuthServerOptions);
          app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
  
      }
  }
  </code></pre>
  
  <p><strong>IocConfig</strong></p>
  
  <pre><code>public static class IocConfig
  {
  
      public static void Register(HttpConfiguration config)
      {
          var builder = new ContainerBuilder();
          // Configure the container 
  
          // Register individual components
          builder.Register(c =&gt; new MySQLContext()).As&lt;IMySqlContext&gt;().InstancePerRequest();
          builder.RegisterType&lt;SimpleAuthorizationServerProvider&gt;().As&lt;IOAuthAuthorizationServerProvider&gt;();
          builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
  
          var container = builder.Build();
          config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
  
      }
  }
  </code></pre>