Okta Sign-in Widget w/Heroku Node.js Backend

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).

My app is deployed here:
https://okta-agora-chat.herokuapp.com

As you can see, the Sign-in Widget is popping properly, as well as authenticating.

However, on the redirect, it brings me to a 404 error page. Here is my redirect URL:
https://dev-593690-admin.oktapreview.com/error/404?fromURI=%2Foauth2%2Fdefault%2Fv1%2Fauthorize%3Fclient_id%3D0oaecgnnsruRMmlvC0h7%26redirect_uri%3Dhttps%3A%2F%2Fokta-agora-chat.herokuapp.com%2F%26response_type%3Dtoken%20id_token%26response_mode%3Dfragment%26state%3DefGnc43cBhtpRgyYYaGkZZUBYTde5IUZHJ1zUQcLWF2P3q0dvgPP6t6aCPcjzbeM%26nonce%3DKw894Apa9fvGbRcHv5ruabbjpR8jisvMpI45igfplEa836D3N2QRxHvErTKZ3nAw%26display%3Dpage%26sessionToken%3D20111am7CsqLCQfX-Bm4jFV6fcr0k5C7E-coThXUydbGgCVDDcenBcB%26scope%3Dopenid%20email

Is there anything I’m doing wrong?

Thanks!

Can you share your widget config and a test username and password?

In addition to what Tom requested, can you share how your Application is configured in Okta?

Thanks guys!

Here is a test account:
Username: Frankie88.chen@gmail.com
Password: Agoraio1

Here’s my code snippet for the client side:

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);
            }
        );
    });
}

Here’s how my application is configured in Okta:

Thanks for posting your config!

Your baseUrl shouldn’t have -admin in it. Can you update that to https://dev-593690.oktapreview.com and see if it improves?

1 Like

Thanks! That was it! That solved the 404.

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);
            },

(Stays on https://okta-agora-chat.herokuapp.com)

Any ideas?

Thanks!

Never mind, got it working! Thanks for all the help!

1 Like