1

Problems

  • I am using Swashbuckle 5.6.0 for ASP.NET Web Api 2 with OAuth2 token authentication. When I try to authorize a Controller action decorated with [Authorize] using the red exclamation mark button in SwaggerUI I receive the error

    unsupported_grant_type

  • Another problem seems to be that SwaggerUI makes a GET request to get the token. In Postman if I send a POST request to the token endpoint with the required Content-Type I get a valid token response. If I instead send a GET request in Postman it doesn't work either, I get

    unsupported_grant_type

Researched so far

  • Googling this error seems to indicate that the request to the Token endpoint needs a Content-Type "application/x-www-form-urlencoded". However, I cannot find any way to set this Content-Type in Swashbuckle for token requests (I can set headers successfully for Controller actions using IOperationFilters).

Question

So, is there any way through Swashbuckle I can configure SwaggerUI to use POST with a specific Content-Type header when targeting the OAuth2 Token endpoint?

Community
  • 1
  • 1
Dennis
  • 11
  • 1

1 Answers1

0

This depends on whether you have a 1) real oAuth/OpenID implementation or 2) 'just' a token endpoint and [Authorize] attributes on controllers.

If you've got #2 then the SO answer is here prompts for a username and password from the token endpoint of your choosing and set's the client_id from the apikey field (if required), and this SO answer allows you to paste in a Bearer token in the 'apikey' field.

If you've got #1 then you'll have to make sure you know your 'auth' and 'token' endpoints and mark them according to the swashbuckle oauth2 documentation

OzBob
  • 4,227
  • 1
  • 39
  • 48