Swagger Client - ResponseType = Token not working
Confirm you've already contributed to this project or that you sponsor it
- [X] I confirm I'm a sponsor or a contributor
Version
5.8.0
Question
I have recently converted from IdentityServer4 to OpenIddict and have managed to get basically all of the flows working for my client apps, internal services (client credentials) and external identity providers.
The last one I cannot figure out is the Swagger authentication.
When I click Authorize via my app's swagger page, it makes the following call to the identity service (using OpenIddict).
https://localhost:5000/connect/authorize?response_type=token&client_id=swaggerClient&redirect_uri=https%3A%2F%2Flocalhost%3A5001%2Foauth2-redirect.html&scope=Domain&state=RnJpIFNlcCAyNyAyMDI0IDExOjQ5OjIxIEdNVCswMjAwIChTb3V0aCBBZnJpY2EgU3RhbmRhcmQgVGltZSk%3D
Which returns:
error:unsupported_response_type
error_description:The specified 'response_type' is not supported.
error_uri:https://documentation.openiddict.com/errors/ID2032
OpenIddict logged the following:
I have checked and my swaggerClient does have the "token" response_type saved:
I am assuming there is some validation middleware kicking in as the request is not hitting my Authorize endpoint, which gets hit when the other apps authorize, but I cannot figure out what is wrong with the config.
Any assistance will be appreciated.
Hey,
Looks like GitHub didn't recognize you as a sponsor. Did you sponsor the project via your company/employer?
Cheers.
Yes, company is Singular Systems: https://github.com/SingularSystems
Yes, company is Singular Systems: https://github.com/SingularSystems
Great, thanks! ❤️
I am assuming there is some validation middleware kicking in as the request is not hitting my Authorize endpoint, which gets hit when the other apps authorize, but I cannot figure out what is wrong with the config.
Your screenshot shows that the app has the correct permissions attached - implicit grant type + token response type - so it's likely you simply forgot to enable implicit flow support at the global level, in the server options. Calling options.AllowImplicitFlow() should fix that.
That said, the OAuth 2.0-only token response type is a legacy thing that shouldn't be used in 2024. If possible, consider updating your Swagger client to use the OAuth 2.0/OIDC authorization code flow, which is a much better option even for browser-based apps.
Hope it'll help. All the best.
options.AllowImplicitFlow() did the trick, thank you!
Will certainly look into changing our swagger config, but I did hear that .net 9 was bringing in their own swagger replacement, so may wait for that.
Thanks so much for your help!
Thanks so much for your help!
My pleasure! Thanks for sponsoring the project! 😃
On an unrelated note, you may also want to enable the status code pages middleware integration to avoid the "plain-text errors" returned by OpenIddict by default: https://documentation.openiddict.com/integrations/aspnet-core#status-code-pages-middleware-integration 😃
Cheers.