Skip to content
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

getUserInfo() only returning email and sub #158

Open
2 tasks
mgug01 opened this issue Aug 5, 2021 · 5 comments
Open
2 tasks

getUserInfo() only returning email and sub #158

mgug01 opened this issue Aug 5, 2021 · 5 comments

Comments

@mgug01
Copy link

mgug01 commented Aug 5, 2021

I'm submitting a:

  • Bug report
  • Feature request
  • [x ] Other (Describe below)
  • Possibly user error

Current behavior

Following the documentation for okta-react, but running into an issue when attempting to call current user data. I am able to authenticate the user, but when I call the method getUserInfo(), I only receive the user's email, email_verified and sub.

Expected behavior

I would like to receive additional information on the user including name.

Minimal reproduction of the problem with instructions

import React, {useEffect, useState} from 'react';
import { useOktaAuth } from "@okta/okta-react";

export default function TestRoute(props){
    const { authState, oktaAuth } = useOktaAuth();
    const [userInfo, setUserInfo] = useState(null);

    useEffect(() => {
        console.log(authState, oktaAuth)
        if (!authState.isAuthenticated) {
          // When user isn't authenticated, forget any user info
          setUserInfo(null);
        } else {
          
          oktaAuth.token.getUserInfo().then(info => {
              console.log(info)
            setUserInfo(info);
          });
        }
      }, [authState, oktaAuth]); // Update if authState changes

    return(
        <>
       <div>Test</div>
       {userInfo && (
        <div>
          <p>Welcome back, {userInfo.name}!</p>
        </div>
      )}
      </>
    )
}

Extra information about the use case/user story you are trying to implement

Environment

  • Package version: 6.1.0
  • React version: 16.13.1
  • Browser: Chrome
  • OS: Mac

Configuration

  • Okta application type: React
@shuowu
Copy link
Contributor

shuowu commented Aug 5, 2021

@gugmi01 The getUserInfo method send request to /userinfo endpoint which returns all of the user's claims.

Many of these claims are also included in the ID token, but calling this endpoint always returns all of the user's claims. The ID token can be configured to include a subset of the user's claims. See Scope-dependent claims for more information.

Can you verify:

  1. if the request has been send from the network log?
  2. if the all user information have been added before the request?

@mgug01
Copy link
Author

mgug01 commented Aug 5, 2021

@gugmi01 The getUserInfo method send request to /userinfo endpoint which returns all of the user's claims.

Many of these claims are also included in the ID token, but calling this endpoint always returns all of the user's claims. The ID token can be configured to include a subset of the user's claims. See Scope-dependent claims for more information.

Can you verify:

  1. if the request has been send from the network log?
  2. if the all user information have been added before the request?

Thanks for the reply.

  1. Yes a successful GET request was sent to https://{MYURL}/oauth2/default/v1/userinfo with a response of {"sub":"{MYSUB}","email":"{MYEMAIL}","email_verified":true}

  2. I filled out my user information within "Directory > People > Profile". I completed my username, First name, Last name & Display name, but none of these are returned from the /userinfo endpoint

@shuowu
Copy link
Contributor

shuowu commented Aug 5, 2021

@gugmi01 Can you check if profile has been added to the scopes configuration when initialize oktaAuth instance.

@mgug01
Copy link
Author

mgug01 commented Aug 5, 2021

@gugmi01 Can you check if profile has been added to the scopes configuration when initialize oktaAuth instance.

Is this the scopes section you are referring to? I do see profile within the list:

image

@eponsonby
Copy link

@gugmi01, @shuowu is referring to the configuration in your code. You should be configuring scopes when you initialize the oktaAuth instance and that should include profile. See this page for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants