Open JadyNews opened 6 years ago
By default all server-set cookies are thrown away.
Cookies are preserved only by a copy of an agent (.agent()
) so create and use a copy of an agent for as long as you need its cookies.
@kornelski , I am new here, could you please confirm that if I use superagent.agent(). After .end() will the session be closed.
For example, user1 uses superagent.agent() to call an API to get response SAML back and do something, after it, user2 uses superagent.agent() to call same API. Will the user1's session still preserved when user2 making the call ?
The code snippet is below:
var request = require('superagent');
var agent = request.agent();
agent
.get(`${config.oktaAppURL}`)
.query({ sessionToken: sessionToken })
.set('Accept', '*/*')
.end(function(err, res) {
if (err) {
logger.error('Call okta app url to get SAML assertion: ' +
'can\'t not query to this app url');
callback(err);
}
else {
// do something
return callback(null, data);
}
else {
// do something
return callback(err);
}
}
});
Each instance of an agent has separate cookies. If you make two agents, they will be like two users.
We use superagent to get SAML integration with AWS, when posting request to the SAML IdP (Okta) we have to use agent to include cookies in order to get the SAML metadata back, but the cookies needs to detach/unset when making request to AWS to assume role.
Is that a way to implement it?
Thank you in advanced, Jady