How to get user info from Okta, other than name, surname and email?

I would like to get other info from Okta, because with this.props.auth.getUser() I’ll receive only email, name and surname about user. But there are many data on Okta for example state, city, street address, zip code and so on.

I’m creating a web app with ReactJS and Node express and the login is managed by Okta (https://developer.okta.com/), then I would like to store the Okta information about users in a database.

async checkAuthentication() {
  const authenticated = await this.props.auth.isAuthenticated();

  if (authenticated !== this.state.authenticated) {
const user = await this.props.auth.getUser();

console.log(this.props.auth);
this.setState({
  authenticated,
  user
});
this.getUsers();
  }
}

async getUsers() {
  let params = "";
  let url = "";

  if (this.state.user != null) {
params += "EMAIL=" + this.state.user.email;
  }

  url = params == null ? "/user" : "/user?";
  url += params;
  this.state.users = await this.fetch('get', url);

  if (this.state.users && Object.keys(this.state.users).length == 0) {
this.saveUser();
  }
}

async saveUser() {
  var user = {
EMAIL: this.state.user.email,
NAME: this.state.user.given_name,
SURNAME: this.state.user.family_name,
//ORGANIZATION: "this.state.user.organization",
//PHONE = "this.state.user.primaryPhone",
//STATE = "this.state.user.state",
//STREET_ADDRESS = "this.state.user.streetAddress",
//ZIP_CODE = "this.state.user.zipCode",
  };

  await this.fetch('post', '/user', user);
}

Here I would like to save the other data from Okta.

//ORGANIZATION: "this.state.user.organization",
//PHONE = "this.state.user.primaryPhone",
//STATE = "this.state.user.state",
//STREET_ADDRESS = "this.state.user.streetAddress",
//ZIP_CODE = "this.state.user.zipCode",

auth.getUser() returns the details available under /userinfo endpoint on the authorization server through which the user got authenticated and authorized, as described here.

If you would like to publish other details also on this /endpoint, please do the following:
• navigate from your Okta tenant to Admin >> API >> Authorization Server >> your authorization server
• under Claims tab, add new claims with the user’s profile values and, under “Include in token type”, select “ID Token” and “Userinfo / id_token request”

1 Like