mrjimin
11/12/2026, 7:06 AMAmir Golmoradi
11/12/2026, 7:10 AMmrjimin
11/12/2026, 1:03 PMmrjimin
11/12/2026, 1:03 PMmrjimin
11/12/2026, 1:03 PMAmir Golmoradi
11/12/2026, 1:04 PMmrjimin
11/12/2026, 1:05 PMmrjimin
11/12/2026, 1:06 PMAmir Golmoradi
11/12/2026, 1:06 PMAmir Golmoradi
11/12/2026, 1:06 PMmrjimin
11/12/2026, 1:07 PMAmir Golmoradi
11/12/2026, 1:11 PMmrjimin
11/12/2026, 1:15 PMAmir Golmoradi
11/12/2026, 1:16 PMAmir Golmoradi
11/12/2026, 1:24 PMonAuthenticated. Only AuthException is caught, so a DB failure in loginWithOAuth would give the user a 500 mid-redirect. A fallback catch (e: Exception) that logs at error and redirects to /login?error=server_error would fix that (rethrow CancellationException first). Also, respondRedirect(frontendUrl) currently sits inside the try, so I’d move it after the try to avoid a double redirect if it fails.
2. Email verification. emailVerified is passed to the service, but I can’t see where it’s enforced. If loginWithOAuth links accounts by email, it should reject emailVerified == false to avoid account takeover. Could you confirm where that’s handled?
3. Log the cause properly. "...failed: $cause" loses the stack trace. If cause is a Throwable, use log.warn("...", cause). Users cancelling the consent screen will also hit this path, so info may be better for that case.
Minor / non-blocking:
• suspend on configureSecurity may be unnecessary. Try dropping it and see if it compiles.
• Validate frontendUrl at startup (e.g. no trailing slash), since "$frontendUrl/login" breaks quietly otherwise.
• Pull the error codes (login_failed, auth_failed) into constants shared with the frontend contract.
• Consider extracting the UserInfo → OAuthIdentity mapping into a small function so it’s unit-testable.mrjimin
11/12/2026, 1:28 PMmrjimin
11/12/2026, 1:28 PMAmir Golmoradi
11/12/2026, 1:29 PMmrjimin
11/12/2026, 1:29 PMsuspend is absolutely necessary because oidc.identityProvider only runs in a non-blocking context.mrjimin
11/12/2026, 1:37 PMAmir Golmoradi
11/12/2026, 1:47 PMsuspend fun is necessary keep it.Amir Golmoradi
11/12/2026, 2:04 PMonAuthenticated is called.
If loginWithOAuth() rejects the user, the OIDC session may still remain active.
I’d recommend clearing it in both exception handlers using call.sessions.clear<OidcToken.Id>()mrjimin
11/12/2026, 2:06 PMmrjimin
11/12/2026, 2:07 PMauth...mrjimin
11/12/2026, 2:10 PMauthenticateWith(google.session) in call.principal.userInfo.subject..? Isn’t there another way?Amir Golmoradi
11/12/2026, 2:13 PMgoogle.session exposes the OIDC principal, which gives you Google’s user information, but not necessarily your application’s roles.
I’d recommend using google.session.mapPrincipal() to resolve the Google subject to your application’s user from the database, including their role.
Then you can use authenticateWith() for protected routes and withRoles() for admin-only routes. You don’t need to put everything inside `configureSecurity()`; you can reuse the authentication scheme across your routing modules.
Official docs:
ktor.io/docs/server-typed-auth.htmlmrjimin
11/12/2026, 2:31 PMmrjimin
11/12/2026, 2:32 PMAmir Golmoradi
11/12/2026, 2:33 PMmrjimin
11/12/2026, 4:06 PM