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
2 Answers
Reset to default 2auth.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/