Reputation: 5987
I am trying to retrieve a user's profile information using this tutorial here: https://auth0.com/docs/quickstart/spa/react/02-user-profile
My scope looks like this:
auth0 = new auth0.WebAuth({
// ...
scope: 'openid profile'
});
Here are the two functions inside my Auth
file.
getAccessToken() {
const accessToken = localStorage.getItem('access_token');
if (!accessToken) {
throw new Error('No Access Token Found');
}
return accessToken;
}
getProfile() {
let accessToken = this.getAccessToken();
return new Promise((resolve, reject) => {
this.auth0.client.userInfo(accessToken, (err, profile) => {
console.log(profile);
if (profile) {
resolve(profile);
} else if (err) {
reject(err);
}
});
});
}
When I console log the profile I get this instead of the user's info.
{sub: "auth0|5aba531bbf06807d56cdb6c5"}
Upvotes: 0
Views: 471
Reputation: 1431
This worked for me:
Change the scope in auth0 object to include profile:
scope: 'openid profile email'
Set an empty user profile object
userProfile = {}
Then set the profile to the response from auth0.
getAccessToken() {
if (localStorage.getItem('access_token')) {
const accessToken = localStorage.getItem('access_token')
return accessToken
}
else {
console.log("No accessToken")
return null
}
}
getProfile() {
let accessToken = this.getAccessToken();
if(accessToken) {
this.auth0.client.userInfo(accessToken, (err, profile) => {
if (profile) {
this.userProfile = { profile };
console.log(this.userProfile)
}
});
}
}
Upvotes: 0
Reputation: 106
It seems that it is just returning the fields for the scope openid. Where did you specify the scope?
Upvotes: 1