Auth0 Home Blog Docs

Getting Swagger UI to work with Auth0

swagger

#1

We are using Auth0 with Swagger, and using the Swagger UI for testing. The UI is broken since implementing Auth0.

The securityDefinition in our swagger file looks like this:

securityDefinitions:
    xx:
        type: oauth2
        flow: implicit
        authorizationUrl: https://<domain>.auth0.com/authorize
        x-tokenInfoFunc: someFunc

Bringing up the Swagger UI displays an Authorize button, and clicking on it goes to this URL:
https://<domain>.auth0.com/authorize?response_type=token&redirect_uri=https%3A%2F%2F<hostname>%2Fapi%2Fv1%2Fui%2Fo2c.html&realm=your-realms&client_id=your-client-id&scope=&state=ui

Auth0 displays

Oops!, somthing went wrong

Looking at the URL, the realm and client id are clearly incorrect - these values are “your-realms” and “your-client-id”. How do these values get set? Adding ?client_id to the authorizationUrl results in another failure: the URL now has two query components, e.g. ?client_id= and the previous query component.

Swagger is a common use case, yet I don’t see anything in the documentation or Community that this works. Does anybody else have experience with this?


#2

Correction, the authorization url is:
authorizationUrl: https://domain.auth0.com/authorize

securityDefinitions:
xx:
type: oauth2
flow: implicit
authorizationUrl: https://domain.auth0.com/authorize
x-tokenInfoFunc: someFunc

Bringing up the Swagger UI displays an Authorize button, and clicking on it goes to this URL:
https://.auth0.com/authorize?response_type=token&amp;redirect_uri=https%3A%2F%2F%2Fapi%2Fv1%2Fui%2Fo2c.html&amp;realm=your-realms&amp;client_id=your-client-id&amp;scope=&amp;state=ui