0

I am new to Web Api 2. I am trying to build a project to explore token authorization. I created a new project in VS 2013 and selected the WebApi2 template and used Fiddler to emulate http requests. I didn't change anything in the template, just ran it as it was and tried to play with it with Fiddler. I successfully created a user by issuing request to /api/account/register but I can't login by issuing a POST request to the /Token endpoint. The request is:

http://localhost:YYYY/token?grant_type=password&password=admin123456&username=admin 

(i also tried to pass the parameters as a json object in the request body).

I get back this: {"error":"unsupported_grant_type"}

From other posts such as ASP.NET WEB API 2 OWIN Authentication unsuported grant_Type I learned that I needed to enable CORS for web api and at the token endpoint, but that hasn't worked for me.

Community
  • 1
  • 1
AunAun
  • 1,423
  • 2
  • 14
  • 25

2 Answers2

1

Are you sure that you are sending POST request message and not GET?

If you simply go to the URL with query string (or open connection to this URL from your code) you are sending GET message by default. It's not what WebAPI with "/token" path is listening for.

-1

If you are calling web service from same place, CORS is not needed. The error "unsupported_grant_type" could be in the format of the data you are passing server in post action.

Try sending with Content-Type application/x-www-form-urlencoded

JAL
  • 41,701
  • 23
  • 172
  • 300