I am trying to figure out the correct flow and process to obtain an ID Token containing a user’s groups in a React app. I am using @okta/okta-react and @okta/okta-auth-js in my app.
On index.js I have the following code and it works to redirect after login to the authorize endpoint and I get an Id Token back in the browser’s location bar. How do I access and use it? Also after I get the Id Token back, I get a blank page, it doesn’t seem to be redirecting.
On auth.js I am trying to use @okta/okta-react to get the IdToken, but it returns an error, TypeError: oktaAuth.getIdToken().then is not a function.
My goal is to get, and use, what is returned from, https://{dev-123456.okta.com}/oauth2/v1/authorize?client_id={clientID}&response_type=id_token&scope=openid%20groups&redirect_uri=http://localhost:3000/login/callback&state=myState&nonce=myNonceValue
What am I missing or doing wrong? Any help would be appreciated.
The Okta library uses the PKCE so only minimal claims are returned. In order to retrieve the list of groups, you would need to make a request to the /userinfo endpoint, which you can use token.getUserInfo. (GitHub - okta/okta-auth-js: The official js wrapper around Okta's auth API) Also, I would confirm that you have “groups” included in the scopes config.
Is there another way to add ‘groups’ to my scope for the getUserInfo() call? When I add it to the config, I get an error. OAuthError: One or more scopes are not configured for the authorization server resource. Setting up an Auth Server is not an option to me even though I can use one in my dev instance of Okta… I am unable to use one in the Production instance.
Assuming you’re still using the same issuer (https://dev-123456.okta.com), can you confirm if the name of the groups claim matches what you can configured on the Sign On tab of the Okta app settings?