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?