Lock: getUserInfo() POST [...] 401 (Unauthorized)

Created on 9 Dec 2016  路  5Comments  路  Source: auth0/lock

Because I was getting the notification that getProfile() will be deprecated I have changed it to getUserInfo() but when I did this and I try to login but using this will not get the user profile and it will give me the error 401 (Unauthorized).

I am using Angular 2 and followed the configuration from: https://auth0.com/docs/quickstart/spa/angular2/04-user-profile

Changed getProfile to getUserInfo.

The code now looks like this:

// Add callback for the Lock `authenticated` event
    this.lock.on("authenticated", (authResult) => {
      localStorage.setItem('id_token', authResult.idToken);

      // Fetch profile information
      this.lock.getUserInfo(authResult.idToken, (error, profile) => {
        if (error) {
          // Handle error
          alert(error);
          return;
        }

        localStorage.setItem('profile', JSON.stringify(profile));
        this.userProfile = profile;

      });

Error

  • Lock version 10.7.2
  • Chrome, Win7, Win10
question

Most helpful comment

I experienced same issue several minutes ago and to make it worked I replaced id_token to accessToken.

this.lock.getUserInfo(authResult.accessToken, (error, profile) => {
  if (error) {
    // tmp error handling
    alert(`Auth service 2: ${error}`);
    return;
  }

  profile.user_metadata = profile.user_metadata || {};

  this.storage.set('profile', JSON.stringify(profile));
  this.user = profile;
});

Lock version: 10.7.2

I hope it will help you.

All 5 comments

You cannot use id_token with getUserInfo method.

you need to use authResult.accessToken

I tried this but accessToken is undefined.

I experienced same issue several minutes ago and to make it worked I replaced id_token to accessToken.

this.lock.getUserInfo(authResult.accessToken, (error, profile) => {
  if (error) {
    // tmp error handling
    alert(`Auth service 2: ${error}`);
    return;
  }

  profile.user_metadata = profile.user_metadata || {};

  this.storage.set('profile', JSON.stringify(profile));
  this.user = profile;
});

Lock version: 10.7.2

I hope it will help you.

you should use the access token, there is an example in the readme https://github.com/auth0/lock#example

@tomaszczechowski Thank you, changing authResult.idToken to authResult.accessToken worked.

This should be re-opened until the website is updated with the most recent documentation.

This document uses the latest version of Lock (version 10).

https://auth0.com/docs/libraries/lock#implementing-lock

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DavidWells picture DavidWells  路  5Comments

kjartanvalur picture kjartanvalur  路  8Comments

sedubois picture sedubois  路  4Comments

sedubois picture sedubois  路  7Comments

dharness picture dharness  路  6Comments