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

**URL:** <https://community.auth0.com/t/trying-to-authenticate-a-user-and-get-the-users-info/6335>\
**Category:** Get Help\
**Tags:** auth, userinfo\
**Created:** [April 24, 2017, 3:13pm UTC](https://community.auth0.com/t/trying-to-authenticate-a-user-and-get-the-users-info/6335 "2017-04-24T15:13:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![justin.zaun](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/justin.zaun/32/5617_2.png) [@justin.zaun](https://community.auth0.com/u/justin.zaun)\
**Post date:** [April 24, 2017, 3:13pm UTC](https://community.auth0.com/t/trying-to-authenticate-a-user-and-get-the-users-info/6335/1 "2017-04-24T15:13:34Z")

</div>

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: 'domain.auth0.com',
  clientID: 'CLIENT_ID',
  redirectUri: 'http://server.com/#/auth/'
});
auth0.authorize({
  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.

```
request({
  method: 'POST',
  url: 'https://domain.auth0.com/oauth/token',
  timeout: 5000,
  form: {
    'client_id': 'CLIENT_ID',
    'client_secret': 'CLIENT_SECRET',
    'redirect_uri': 'http://server.com/#/auth/',
    'code': event.queryStringParameters.code,
    'grant_type': 'authorization_code'
  }
}).then(function (parsedBody) {
  return request({
    method: 'GET',
    url: 'https://domain.auth0.com/userinfo/?access_token=' + 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?

---

<div class="post-metadata">

**Author:** ![prashantT](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/prashantt/32/6002_2.png) [@prashantT](https://community.auth0.com/u/prashantT)\
**Post date:** [April 27, 2017, 11:13am UTC](https://community.auth0.com/t/trying-to-authenticate-a-user-and-get-the-users-info/6335/2 "2017-04-27T11:13:12Z")

</div>

According to the API documentation:

> This endpoint will work only if openid  
> was granted as a scope for the  
> access\_token.

Can you try adding the `scope` to your `authorize` call:

```
auth0.authorize({
   connection: 'google-oauth2',
   responseType: 'code',
   scope: 'openid'
 });

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:53am UTC](https://community.auth0.com/t/trying-to-authenticate-a-user-and-get-the-users-info/6335/3 "2018-03-02T05:53:27Z")

</div>


