<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
0D54z00007j1xnhCAAOkta Classic EngineIntegrationsAnswered2022-06-11T20:42:35.000Z2022-06-11T20:28:13.000Z2022-06-11T20:42:35.000Z

StoneS.70407 (Customer) asked a question.

How do I get what access a user has when they sign in using Okta to my SPA?

How do I get what access a user has when they sign in to my single page app (SPA) through Okta? I got Okta working in my front-end app using the @okta/okta-auth-js and @okta/okta-react NPM libraries. And I call the https://dev-XXXXXXXX.okta.com/oauth2/default/v1/userinfo endpoint using oktaAuth.getUser() and it returns me:

 

{

"sub":"XXXXXXXXXXXXXXXXXXXX",

"name":"Joe Smith",

"locale":"en_US",

"email":"joeSmith@example.com",

"preferred_username":"joeSmith@example.com",

"given_name":"Joe",

"family_name":"Smith",

"zoneinfo":"America/Los_Angeles",

"updated_at":1654829975,

"email_verified":true

}

 

and I was hoping it would also return what scopes the user has access to so that I could render the navigation bar according to their permissions. Is there a scope that I could add to the OktaAuth that would return that information?

 

const oktaAuth = new OktaAuth({

    issuer: issuer,

    clientId: clientId,

    redirectUri: signInRedirect,

    scopes: ['openid','profile','email'] // add some scope for supported user access/permissions/scopes?

})

 

Or another endpoint that would give me that information?

 

Additionally, I would prefer an endpoint that the frontend could call directly to the Okta API if that is possible. If it isn't I might have to create a microservice for the frontend to call and relays the call to an non-cors Okta endpoint.


  • StoneS.70407 (Customer)

    Found it. I was over thinking it.

     

    const { authState, oktaAuth } = useOktaAuth()

     

    It is in the authState.idToken.scopes.

This question is closed.
Loading
How do I get what access a user has when they sign in using Okta to my SPA?