Reputation: 47
We utilize Okta as the Identity Provider for our Spring Boot application. Employing the Authorization Code flow, once redirection and successful login occur, we establish our Spring session. Essentially, we manage two sessions: Okta (lasting 8 hours) and Spring (lasting 15 minutes). When the Spring session expires, users are automatically logged out from the application, and they lose the Okta state. How can we check the Okta authentication status without reinitiating the /authorize request? We need to handle this on the backend without prompting users to the Okta login page again.
Upvotes: 0
Views: 199
Reputation: 12629
To populate a session on the OAuth2 client (your Spring app with oauth2Login()
), you need tokens.
If former session is still there and if you had requested a refresh token (include offline_access
scope when running the preceding authorization-code flow), Spring Security should use that under the hood to get new tokens.
If the former session was destroyed, then refresh token (if any) was deleted with it. To get tokens for a user, the only option is with a new authorization code.
To get this authorization code, you need a new authorization-code flow to be initiated.
If the session on the authorization server is still active, this new authorization-code flow will happen silently (user is redirected to the authorization server and then back to the client without being prompted for anything).
Upvotes: 0
Reputation: 99
You can implement a session management mechanism on the back-end that periodically verifies the Okta session status using Okta's session management APIs.
Ensure that the Spring session timeout is set to a shorter duration compared to the Okta session timeout. This ensures that users are logged out from your Spring application before the Okta session expires, preventing any inconsistency between the two sessions.
If the Okta session is still active, you can optionally renew the user's Spring session by updating the session expiration time or performing a session refresh.
This approach allows you to synchronize the Spring session with the Okta session and provide a seamless user experience.
Upvotes: -1