javascript - How to get user info from Okta, other than name, surname and email? - Stack Overflow

I would like to get other info from Okta, because with this.props.auth.getUser() I’ll receive only emai

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 (/), 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.useranization",
    //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.useranization",
//PHONE = "this.state.user.primaryPhone",
//STATE = "this.state.user.state",
//STREET_ADDRESS = "this.state.user.streetAddress",
//ZIP_CODE = "this.state.user.zipCode",

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./), 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.useranization",
    //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.useranization",
//PHONE = "this.state.user.primaryPhone",
//STATE = "this.state.user.state",
//STREET_ADDRESS = "this.state.user.streetAddress",
//ZIP_CODE = "this.state.user.zipCode",
Share Improve this question edited Jan 14, 2019 at 16:48 Sebastian Simon 19.6k8 gold badges61 silver badges84 bronze badges asked Jan 14, 2019 at 16:02 FabioFabio 492 silver badges7 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 2

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"

You need to specify what you want as scope. Okta has default scopes which are the following offline_access, phone, address, email, profile, openid.In the configuration, you can use these docs https://developer.okta./authentication-guide/implementing-authentication/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745619033a4636408.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信