The sid cookie is empty, and it seems this is the cookie I need to identify the session in the following requests.
Why is this cookie value empty? How do I correct that?
I define several functions in nodejs, which I copy here. When I chain primaryAuthentication and getCurrentSession, I get 404.
It is easily reproducible with Postman also.
You have to exchange the session token for a session cookie first, then the sessions API will work. Basically that means you need to pass the user’s browser through the Okta org with the session token, and Okta will set the session cookie into the browser, and then redirect the user to where you want them to go. Look at the second topic down from the start of the sessions doc: Sessions | Okta Developer.
the function getOktaOutboundUrl retrieves an embed link of a SAML Application in Okta.
It works well: the user is redirected, the sessionToken allows his authentication, a cookie is set on the browser, and the user lands on the target application page.
However, when I trigger getCurrentSession from my code afterwards, it does not work.
It seems that the redirection to the embed link sets the cookie in the browser, but this cookie is not captured by my javascript code running on the server side.
I am not able to logout and delete this cookie afterwards.
I tried to use the OKTA api Create Session from a session token, but I have a hard time understanding how to use the session created to log the user in the SAML application afterwards.
The session cookie is a first-party cookie after you go pick it up. JavaScript can’t see it, but it is there if you want to pass it with the XHR request. If the getCurrentSession code is the same as above you are simply not sending the session cookie. Try adding { withCredentials: true } to the axios get call.