Sharing authentication with another domain

Hello,

I have two apps: a.mydomain.com, and b.mydomain.com. When I login to one app, I would like to also be logged into the other without having to re-authenticate. Is sharing authentication with another domain possible using Okta React or okta-auth-js?

Why not have the second app trigger its own /authorize request once user access it? At that point, they will already have an Okta session (created when logging into the first app) and will not be prompted to re-auth (provided the user does not need to provide additional verification specific to this application) when the second authorize call occurs.

In AuthJS, you would use getWithRedirect to trigger this manual /authorize request or getWithoutPrompt if your Okta domain is on the same domain as your applications (e.g. its hosted at login.mydomain.com)

Hi Andrea,

Thanks for the reply! A workaround was found in line with your suggestion. If a session already exists, we make a call to oktaAuth.token.getWithoutPrompt, and the tokens it returns without having to login again:

  useEffect(() => {
    oktaAuth.session.exists().then(exists => {
      if (exists) {
        // logged in
        oktaAuth.token
          .getWithoutPrompt({ responseType: 'id_token' })
          .then(res => {
            const { tokens } = res;

            oktaAuth.tokenManager.setTokens(tokens);
          })
      }
    });
  }, []);
1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.