Okta - exchange a session token for session cookie
After you perform primary auth using Okta /authn API, you receive a session token.
This is a nice guide which explains the various ways you can redeem a session token for a session cookie, which is stored in your web browser.
https://developer.okta.com/docs/guides/session-cookie/overview/
I tried to see the different approaches listed in the above doc in action.
Learnings
1. All these are ways to set the session cookie (sid) after the user authenticates using the /authn API
2. The sessionToken returned by the /authn API is exchanged for a session cookie, which is set by Okta in the user's browser
3. The browser uses this sid cookie for subsequent requests to Okta, which achieves SSO
4. Now, if sid is available, why is there an OAuth2 /token call made from the browser? This is because for making API calls (XHR - XMLHttpRequests) the browser cant use certain cookies, like cookies which are set to HttpOnly, like the sid cookies in our case! This is because Javascript can manipulate cookies, and hence the HttpOnly tells the browser that JS (the API call in this case) cannot use the cookie. The reason is very well explained here - https://stackoverflow.com/a/15300769
Well ^^ is not entirely correct. Cookies are sent with XHR calls if the call is made from the same domain. The reason we make the token call is because some APIs are resticted by OAuth2 bearer tokens. This is the case with deployments outside Oka, like splitnot.com. Hence you see it make a call to /token endpoint, but shantanu-ok11.okta.com does not. However, sometimes shantanu-ok11.okta.com does call the /token endpoint. I still have to figure out why.
1. Retrieve a session cookie through the OpenID Connect authorization endpoint
Comments
Post a Comment