Hi,
I am using the Okta SignIn Widget on my Web App, and I receive an access token which I then send to my backend server and verify using the Java Jwt Verifier (AccessTokenVerifier).
This all appears to be working fine, but how do I manage the Expiration time of the token? I would the expiration time to be reset while the user is active on the site, and not timeout after the preset time.
If I configure the user to have a 30min (or 2 hour) expiration time, what happens when that token expires? Do I need to use a Refresh Token? I cannot seem to get a refresh token from the SignIn Widget, and I cannot find what to do with it, if I were to receive one.
if you use widget, you can rely on underlying auth-js library for refreshing the access token. You only need to get subscribed to the token expiration event and request a new one in its callback. Read about tokenManager - https://github.com/okta/okta-auth-js#the-tokenmanager
Also, if you have a backend, canāt you establish a session cookie with it instead of using access token from Okta?
I do have an existing JSP servlet backend that has session management already that I could establish a session cookie with. Are you suggesting I do this with the Okta session management API, or the existing session management that is in place?
I also need to SSO to another application that is using Okta, but we do not have any control over that application. Would using a session cookie make this more difficult or easier, or no affect?
If itās your backend then you can have your own session based on initial id/access token received from Okta.
Iām almost sure that Okta session cookie will guarantee you signing into the second application w/o re-authenticating your users (unless there is a special policy for the application)
Thanks again fro your help @phi1ipp. It is really appreciated.
Using the SignIn Widget, how can I get the session cookie, and set it on the current server session? I am rather confused by this part.
I am currently using oktaSignIn.hasToeknsInUrl() and parsing the access and id tokens, and then passing those to my server for verification using the JwtVerifier. I can see that it sets two attributes on the session, okta-oauth-nonce and okta-oauth-state, but I cannot find any documentation that tells me what those are used for?
Are you talking about Okta session cookie or your backend server session?
Those canāt be used for purposes which we are discussing. They are used for OAuth authorization flow to protect from replay attacks and preserve a state of a client through the flow.
Hi @phi1ipp, I am talking about getting the Okta session token. I read in the documentation that I need to get the session token and use it to call the session APIs to get the session cookie.
If you are doing this, then you are already have session cookie with Okta. You can easily verify that by opening another tab and trying to go to your Okta dashboard URL. Widget exchanges your session token for a session cookie for you, when you do sign-in into OIDC application.
Hi @phi1ipp. I tried to verify the Okta session cookie by opening a new tab and going to Okta dashboard, but it still gave me the login prompt. On the server side, I am able to see the httpRequest cookies, and I do not see an Okta session cookie there. In the browserās Network tab, I can see the session token in the
https://dev-xxxxxx.okta.com/oauth2/default/v1/authorize? call, but I cannot seem to get or set the session cookie at all.
Good question. I thought I need the session cookie in order to SSO to the other application that we are trying to integrate with. Is that not true? Does the application just need to be in my ātrusted originsā?
Strictly speaking okta session cookie allows you to access Okta. So any URL you will try to access, will be available (subject to authorization decision in Okta of course)
But I see what you are trying to achieve. So you kinda have 2 application, each one hosts its own widget and you want to do SSO, after first one signed in. Wellā¦ Yeah, itās tricky If each one of your apps would be doing redirect to Okta to perform sign-in, itād be an easy task.
I think you can do though:
in app B check if user has active okta session by hitting sessions/me endpoint
setup your application the way when login can be initiated from Okta also (there is a setting in Okta for OIDC apps for that)
@phi1ipp Thatās fantastic. Iām hopeful the B app will be ready to test shortly. Thank you so much for the help.
Would I need to refresh the session on the server side at all with this workflow?
Iām not fully understand what you mean by ārefresh session on the server sideā. Are you talking about your backend and itās own session with your front-end? Or are you talking about Okta session with your browser?
Anyway it all in your hands, how you configure your session management in the application defines what has to be done in your communications with Okta. If you opt in to only get token once from Okta at the beginning and based on a successful response you establish your local backend server session, then you donāt need to go to Okta to refresh Oktaās session (though itās possible also).
Too many questionsā¦ I suggest you implement something and then figure exact questions/issues to be addressed.