3

I am using swagger open API 3 in the Micronaut application with Authorization + PKCE flow as below

enter image description here

@SecurityScheme(name = "Open Id Connect",
        type = SecuritySchemeType.OAUTH2,
        scheme = "bearer",
        bearerFormat = "jwt",
        flows = @OAuthFlows(
                authorizationCode = @OAuthFlow(
                        authorizationUrl = "https://dev-6271510.okta.com/oauth2/default/v1/authorize",
                        tokenUrl = "https://dev-6271510.okta.com/oauth2/default/v1/token",
                        refreshUrl = "",
                        extensions ={@Extension(name = "client_id",properties = {@ExtensionProperty(name = "client_id", value = "ssssss")})},
                        scopes = {@OAuthScope(name = "openid", description= "Open Id scope"),
                                @OAuthScope(name = "profile", description= "Name scope"),
                                @OAuthScope(name = "email" , description= "Email scope")}
                ))
)

The client_id and client_secret are not mapped and I don't know how can I map, currently I am putting it manually.

When the Open Id redirect to the Identity provider, I am able to perform successful authentication.

Now, when the Identity provider redirects back to the micronaut swagger UI, the redirect URI is http://localhost:8084/oauth2-redirect.html which can't be found in the Micronaut Swagger and I can't call any end point because it doesn't contain access_token

I think the micronaut swagger should have a URI https://localhost:8084/swagger/oauth2-redirect.html and the Identity provider should redirect to this URL.

San Jaisy
  • 15,327
  • 34
  • 171
  • 290
  • You need to configure Swagger UI with [`usePkceWithAuthorizationCodeGrant`](https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/oauth2.md) = true. – Helen Jan 12 '21 at 20:10
  • @Helen Thanks for the info, but I don't know how to set it with Micronaut. I didn't find any setting on the Micronaut documentation. – San Jaisy Jan 12 '21 at 21:08
  • 2
    If Micronaut doesn't have a way to change Swagger UI configs, a possible solution might be to host Swagger UI [dist assets](https://github.com/swagger-api/swagger-ui/tree/master/dist) manually. – Helen Jan 12 '21 at 21:21
  • If you want the generated swagger UI to pre-populate the `clientId` field, you can add the following to `openapi.properties`: `swagger-ui.oauth2.clientId=sssssss` with your clientId. – djKianoosh Feb 09 '23 at 15:42

0 Answers0