Recently I faced with the following problem when tried to configure OAuth token-based authentication for Web API 2 project. I used the following article as a general guide: Token Based Authentication using ASP.NET Web API 2, Owin, and Identity. When you create new Web API project VS creates also default routes configuration which look like this:
And if we will follow the same technique as described in the article above for configuring OAuth authentication we will add the following OAuth config to the startup:
where AuthorizationServerProvider is your custom token provider. Note on TokenEndPointPath property of OAuthServerOptions which contains path to the token generation end point. Now if you will try to get token by accessing http://example.com/token (where instead of http://example.com you need to use your web api host) you will get the following error:
"Message": "No HTTP resource was found that matches the request URI 'http://example.com/token'.",
"MessageDetail": "No type was found that matches the controller named 'token'."
The problem is fixed by commenting out default routing configuration in WebApiConfig shown above:
But please note that after that it will be mandatory to decorate your controllers and actions by RoutePrefix and Route attributes correspondently;
After that token generation endpoint should start work.