Auth0 Home Blog Docs

Trying to authenticate a user and get the user's info.



I’m having trouble authenticating a user and getting the user’s information.
First in the browser I’m using the SDK to authenticate.

auth0 = new Auth0.WebAuth({
  domain: '',
  clientID: 'CLIENT_ID',
  redirectUri: ''
  connection: 'google-oauth2',
  responseType: 'code'

I get the code back from Auth0 and and send it to my server. On the server I
call the following bit of code.

  method: 'POST',
  url: '',
  timeout: 5000,
  form: {
    'client_id': 'CLIENT_ID',
    'client_secret': 'CLIENT_SECRET',
    'redirect_uri': '',
    'code': event.queryStringParameters.code,
    'grant_type': 'authorization_code'
}).then(function (parsedBody) {
  return request({
    method: 'GET',
    url: '' + parsedBody.access_token,
    timeout: 5000
}).then(function (userData) {
  done(200, userData);
}).catch(function (err) {
  done(500, err);

The first request comes back and I try to use the access_token to get the user’s
data. But durning the second request I get a 401 Unauthorized.

What am I doing wrong?


According to the API documentation:

This endpoint will work only if openid
was granted as a scope for the

Can you try adding the scope to your authorize call:

   connection: 'google-oauth2',
   responseType: 'code',
   scope: 'openid'