I’m trying to get the Okta Sign-in Widget to work with my Heroku Node.js backend (which acts as both the server handling the redirect for the accessid and acccestokens, as well as the web server).
var oktaSignIn = new OktaSignIn({
baseUrl: “https://dev-593690-admin.oktapreview.com”,
clientId: “0oaecgnnsruRMmlvC0h7”,
authParams: {
issuer: “https://dev-593690-admin.oktapreview.com/oauth2/default”,
responseType: [‘token’, ‘id_token’],
display: ‘page’
}
});
if (oktaSignIn.token.hasTokensInUrl()) {
oktaSignIn.token.parseTokensFromUrl(
function success(res) {
// The tokens are returned in the order requested by responseType above
var accessToken = res[0];
var idToken = res[1]
// Say hello to the person who just signed in:
console.log('Hello, ' + idToken.claims.email);
// Save the tokens for later use, e.g. if the page gets refreshed:
oktaSignIn.tokenManager.add('accessToken', accessToken);
oktaSignIn.tokenManager.add('idToken', idToken);
// Remove the tokens from the window location hash
window.location.hash='';
},
function error(err) {
// handle errors as needed
console.error(err);
}
);
} else {
oktaSignIn.session.get(function (res) {
// Session exists, show logged in state.
if (res.status === 'ACTIVE') {
console.log('Welcome back, ' + res.login);
window.location.href = "meeting.html?account=" + res.login;
return;
}
// No session, show the login form
oktaSignIn.renderEl(
{ el: '#okta-login-container' },
function success(res) {
// Nothing to do in this case, the widget will automatically redirect
// the user to Okta for authentication, then back to this page if successful
res.session.setCookieAndRedirect("https://okta-agora-chat.herokuapp.com/meeting.html?account=" + res.login);
},
function error(err) {
// handle errors as needed
console.error(err);
}
);
});
}
Now, it doesn’t seem like it’s processing the redirect line properly:
{ el: '#okta-login-container' },
function success(res) {
// Nothing to do in this case, the widget will automatically redirect
// the user to Okta for authentication, then back to this page if successful
res.session.setCookieAndRedirect("https://okta-agora-chat.herokuapp.com/meeting.html?account=" + res.login);
},