Auth0 Home Blog Docs

Retrieving Google and Facebook Identity Provider Attributes

google
vuejs
facebook
identity
provider

#1

Hey guys,
So far I have been able to retrieve, email, email_verified, family_name, gender, given_name, locale, name, nickname and picture with following code

export default class AuthService {
  authenticated = this.isAuthenticated()
  authNotifier = new EventEmitter()

  constructor () {
    this.login = this.login.bind(this)
    this.setSession = this.setSession.bind(this)
    this.logout = this.logout.bind(this)
    this.isAuthenticated = this.isAuthenticated.bind(this)
  }

  auth0 = new auth0.WebAuth({
    domain: AUTH_CONFIG.domain,
    clientID: AUTH_CONFIG.clientId,
    redirectUri: AUTH_CONFIG.callbackUrl,
    audience: `https://${AUTH_CONFIG.domain}/userinfo`,
    responseType: 'token id_token',
    scope: 'openid email profile'
  })

  login () {
    this.auth0.authorize()
  }

  handleAuthentication () {
    this.auth0.parseHash((err, authResult) => {
      if (authResult && authResult.accessToken && authResult.idToken) {
        this.setSession(authResult)
        this.auth0.client.userInfo(authResult.accessToken, function (err, user) {
          localStorage.setItem('user_details', JSON.stringify(user))
          console.log(user)
          console.log(err)
        })

        router.replace('home')
      }
      else if (err) {
        router.replace('home')
        console.log(err)
        alert(`Error: ${err.error}. Check the console for further details.`)
      }
    })
  }

  setSession (authResult) {
    // Set the time that the access token will expire at
    let expiresAt = JSON.stringify(
      authResult.expiresIn * 1000 + new Date().getTime()
    )
    localStorage.setItem('access_token', authResult.accessToken)
    localStorage.setItem('id_token', authResult.idToken)
    localStorage.setItem('expires_at', expiresAt)
    this.authNotifier.emit('authChange', { authenticated: true })
  }

  logout () {
    // Clear access token and ID token from local storage
    localStorage.removeItem('access_token')
    localStorage.removeItem('id_token')
    localStorage.removeItem('expires_at')
    this.userProfile = null
    this.authNotifier.emit('authChange', false)
    // navigate to the home route
    router.replace('home')
  }

  getUser () {
    return JSON.parse(localStorage.getItem('user_details'))
  }
  isAuthenticated () {
    // Check whether the current time is past the
    // access token's expiry time
    let expiresAt = JSON.parse(localStorage.getItem('expires_at'))
    return new Date().getTime() < expiresAt
  }
}

I, however, would like to retrieve the Identity Provider Attributes. of a user. I am not quite what to modify in scope to get those attributes. Help would be greatly appreciated


#2

In OIDC compliant authentication the scopes value will only impact the information surfaced in the ID token or through the user info for standard OIDC user profile properties like email, name and nickname. Unless the information coming from the underlying identity provider follows the same terminology you won’t get the information simply by customizing the scopes you request. However, you can add any custom information to issued ID tokens or user info responses by adding that data as custom claims in a rule.

See: https://auth0.com/docs/api-auth/tutorials/adoption/scope-custom-claims#custom-claims


#3