Andrew O'Hara
01/10/2023, 2:22 AMImplicitOAuthSecurity
) to work in their http4k-contract swagger ui?
val googleSecurity = ImplicitOAuthSecurity(
Uri.of("<https://accounts.google.com/o/oauth2/v2/auth>"),
listOf(OAuthScope("email")),
myAuthFilter
)
val api = contract {
renderer = OpenApi3(ApiInfo("My Api", "1")) // jackson renderer
descriptionPath = "/openapi"
routes += generateRoutes()
security = googleSecurity
}
val ui = swaggerUi(
descriptionRoute = Uri.of("/openapi"),
displayOperationId = true,
requestSnippetsEnabled = true
)
routes(api, ui)
.asServer(SunHttp(8000))
.start()
Here's what I can do so far:
1. On the Swagger UI, click the "Authorize" button, and see "oauthSecurityImplicit" as an available authorization
2. Under "oauthSecurityImplicit", I have to enter my client id, and then I can click "Authorize"
3. I'm redirected to Google Sign In, and can choose an account to sign in with
4. I get redirected back to <app_host>/oauth2-redirect.html
, which is a path that seems to have been selected by the Swagger UI (doesn't appear in the OpenApi spec)
5. 404, because my app doesn't have this path
Clearly, I'm not doing something ridiculous, because the Swagger UI seems to encourage this workflow. I'm just not sure what I need to do to get it to work.dave
01/10/2023, 12:09 PMdave
01/10/2023, 12:10 PMdave
01/10/2023, 12:12 PMAndrew O'Hara
01/10/2023, 9:43 PMswaggerUi
is a helper function built into http4k-contract, and it doesn't use a webjar, for obvious dependency reasons. I guess if this workflow was intended for use by a webjar, then that is the obvious explanation for why the redirect fails.
The current helper takes a leaf from Javalin's book and is just a static HTML document which loads swagger UI from CDN; perhaps that's a limitation of this no-dependency approach.
I'll try serving the UI via webjar and see if it helps. Thanks!Andrew O'Hara
01/11/2023, 2:25 AMurl
query arg, so I don't know if the webjar will be suitable anymore. I'm going to work on updating the http4k-contract swaggerUi
helper to also include the redirect html. I'm making good progress, but am encountering a potential google-specific issue that's slowing me down. In this particular case, I was relying on receiving the JWT id_token, but I now only receive an opaque access_token that I can't yet verify.
https://github.com/swagger-api/swagger-ui/issues/7702Andrew O'Hara
01/11/2023, 2:49 AMswaggerUi
helper.