-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple Client Id and Multiple Issuer URL. #243
Comments
You can try next approach. const oktaAuth1 = new OktaAuth(config1);
const oktaAuth2 = new OktaAuth(config2); You need to store tokens in different places, please use different const config1 = {
// clientId, issuer, redirectUri for app1
tokenManager: {
storageKey: 'app1',
},
};
const config2 = {
// clientId, issuer, redirectUri for app2
tokenManager: {
storageKey: 'app2',
},
}; Display 2 buttons for login that handles onClick accordingly: oktaAuth1.signInWithRedirect()
-or-
oktaAuth2.signInWithRedirect() Use different routes for employee and partner apps. <Security
oktaAuth={oktaAuth1}
onAuthRequired={customAuthHandler1}
restoreOriginalUri={restoreOriginalUri}
>
<Switch>
<Route path="/app1" component={Home1} />
<Route path="/app1/login/callback" component={LoginCallback} />
<SecureRoute path="/app1/profile" component={Profile1} />
</Switch>
</Security>
<Security
oktaAuth={oktaAuth2}
onAuthRequired={customAuthHandler2}
restoreOriginalUri={restoreOriginalUri}
>
<Switch>
<Route path="/app2" component={Home2} />
<Route path="/app2/login/callback" component={LoginCallback} />
<SecureRoute path="/app2/profile" component={Profile2} />
</Switch>
</Security> You can also ask in https://devforum.okta.com/ as it's not typical usage of okta-auth-js and okta-react |
Thanks for responding. We have single app only with single code base And on home page we need to display 2 cta. We do not have two different app. Same app with 2 different okta client I'd and issuer url. I have one login.jsx file having both the cta and one app.jsx file. Please suggest me how it can be handled. |
Then you can have 1 const oktaAuth1 = new OktaAuth(config1); // config for employee
const oktaAuth2 = new OktaAuth(config2); // config for partner Use them in login button handlers accordingly: <button onClick={() => oktaAuth1.signInWithRedirect()}>Employee login</button>
<button onClick={() => oktaAuth2.signInWithRedirect()}>Partner login</button> Please set up 2 different You can determine dynamically what OktaAuth instance of two should be passed to const clientIdFromToken = oktaAuth1.tokenManager.getTokensSync()?.accessToken?.claims?.cid;
const oktaAuth = clientIdFromToken === oktaAuth1.options.clientId || window.location.href.includes(oktaAuth1.options.redirectUri) ? oktaAuth1 : oktaAuth2; Then you can wrap your routes and components in single <Security
oktaAuth={oktaAuth}
onAuthRequired={customAuthHandler}
restoreOriginalUri={restoreOriginalUri}
>
<Switch>
<Route path="/" component={Home} />
<Route path="/employee/login/callback" component={LoginCallback} />
<Route path="/partner/login/callback" component={LoginCallback} />
<SecureRoute path="/profile" component={Profile} />
</Switch>
</Security> (Note 2 different routes handled by same |
@denysoblohin-okta could you explain how this should be setup in the event a single SPA needed to communicate with 2 different authorization servers? The above works fine if you need one or the other, but what if you needed to maintain multiple tokens? We have API A which is secured by AuthServer 1 and API B which is secured by AuthServer 2. The SPA needs to be able to talk with both APIs and therefore needs two separate tokens. Am I approaching this totally wrong? It feels like I'm fighting the tool. |
Can you explain the need of 2 issuers in your app? |
@denysoblohin-okta We have been following the best practices for Authorization Servers here https://developer.okta.com/docs/concepts/api-access-management/#authorization-server This suggests having one Authorization Server per API product. Our use case now dictates that our SPA now needs to communicate with two separate API's, each behind their own unique Authorization Server. I'm under the impression the SPA will need to obtain and store an access token for each authorization server. I have been able to use |
<Switch>
<Route path="/employee">
<Security oktaAuth={oktaAuth1}>
<Switch>
<Route path="/" component={Employee} />
<Route path="/employee/login/callback" component={LoginCallback} />
</Switch>
</Security>
</Route>
<Route path="/partner">
<Security oktaAuth={oktaAuth2}>
<Switch>
<Route path="/" component={Partner} />
<Route path="/partner/login/callback" component={LoginCallback} />
</Switch>
</Security>
</Route>
</Switch> Utilizing nested routes allows for the However, it may be easier to write your own |
Hello team,
we have a requirement of having 2 CTA on home page. Employee Login and partner login.
.
For Employee Login we have different client Id and issuer url.
For Partner Login we have different client Id and issuer url.
Our application is single page application with react.
Below are the okta library we are using
import { Security } from '@okta/okta-react';
import { OktaAuth, toRelativeUrl } from '@okta/okta-auth-js';
Please help me how handle this in react single page application.
The text was updated successfully, but these errors were encountered: