title: Can't Authenticate desktop APP using Web API OWIN JWT Token
body: <p>I'm building a desktop APP using windows forms that needs to be authenticated via a WebAPI using Token authentication.</p>
  
  <p>The API is proved that work because a mobile APP is using it and also I can get results using POSTMAN</p>
  
  <p><a href="https://i.stack.imgur.com/q6kbt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q6kbt.png" alt="enter image description here"></a>
  The problem is when I'm calling the Authentication method from the desktop App.</p>
  
  <p>When I do the request, the API recieves it and it only goes until <code>ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)</code>, not reaching <code>GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)</code> in the Auth process.</p>
  
  <p>Here is my CustomAuthProvider</p>
  
  <pre><code>public class CustomOAuthProvider : OAuthAuthorizationServerProvider
  {
  
      public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
      {
              context.Validated();
              return Task.FromResult&lt;object&gt;(null);
      }
  
      public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
      {
          var allowedOrigin = "*";
          context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });
          var userManager = context.OwinContext.GetUserManager&lt;ApplicationUserManager&gt;();
  
          ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);
  
          if (user == null)
          {
              context.SetError("invalid_grant", "El nombre de usuario o contraseña son incorrectos");
              return;
          }
  
          ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager, "JWT");
          var ticket = new AuthenticationTicket(oAuthIdentity, null);
          context.Validated(ticket);
      }
  }
  </code></pre>
  
  <p>Here is my Startup class</p>
  
  <pre><code> public partial class Startup
  {
      public void Configuration(IAppBuilder app)
      {
          ConfigureAuth(app);
  
          HttpConfiguration httpConfig = new HttpConfiguration();
  
          ConfigureOAuthTokenGeneration(app);
          ConfigureOAuthTokenConsumption(app);
          ConfigureWebApi(httpConfig);
  
  
      }
  }
  </code></pre>
  
  <p>At the moment I'm trying two different ways to authenticate the APP.</p>
  
  <p>First One:</p>
  
  <pre><code>public LoginResponseModel Authenticate(LoginRequestModel applicationUser)
      {
          using (var client = new WebClient())
          {
              try
              {
  
                  client.Headers["Content-Type"] = "application/json";
  
                  var data = applicationUser.Serialize();
                  var response = client.UploadString(Context.ApiUrl + "Authenticate","POST", JsonConvert.SerializeObject(applicationUser));
                  var resultJson = JsonConvert.DeserializeObject&lt;LoginResponseModel&gt;(response);
  
                  return resultJson;
              }
              catch (Exception exception)
              {
              }
          }
          return null;
      }
  </code></pre>
  
  <p>And second one:</p>
  
  <pre><code>public async Task&lt;ApplicationUser&gt; Authenticate(LoginRequestModel applicationUser)
      {
          var client = new HttpClient();
  
              try
              {
                  client.DefaultRequestHeaders.Accept.Clear();
                  client.DefaultRequestHeaders.Accept.Add(
                      new MediaTypeWithQualityHeaderValue("application/json"));
              var data = applicationUser.Serialize();
                  var response = await client.PostAsJsonAsync(Context.ApiUrl + "Authenticate",data );
  
                  // return null by default (test)
                  return null;
              }
              catch (Exception exception)
              {
              }
          return null;
      }
  </code></pre>
  
  <p>And this is the model I'm using for the request </p>
  
  <pre><code>public class LoginRequestModel
  {
      public string Grant_type { get; set; } = "Password";
      public string UserName { get; set; }
      public string Password { get; set; }
  }
  </code></pre>
  
  <p>And this should be the response:</p>
  
  <pre><code>public class LoginResponseModel
  {
      public string Access_token { get; set; }
      public string Token_type { get; set; }
      public string Expires_in { get; set; }
  }
  </code></pre>
  
  <p>Ah the moment both ways of calling the API only reach the initial verification of the owin process (ValidateClientAuthentication). What can be happening? How I can fix this? What I need to do to make the process go to GrantResourceOwnerCredentials?</p>
  
  <p>thanks for the help</p>