# Auth0 "Custom Social" for Google fails with "Invalid user id."

**URL:** <https://community.auth0.com/t/auth0-custom-social-for-google-fails-with-invalid-user-id/114724>\
**Category:** Get Help\
**Tags:** login-prompt-new-experience, login-experience\
**Created:** [August 29, 2023, 7:55am UTC](https://community.auth0.com/t/auth0-custom-social-for-google-fails-with-invalid-user-id/114724 "2023-08-29T07:55:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam.straughan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adam.straughan/32/50272_2.png) [@adam.straughan](https://community.auth0.com/u/adam.straughan)\
**Post date:** [August 29, 2023, 7:55am UTC](https://community.auth0.com/t/auth0-custom-social-for-google-fails-with-invalid-user-id/114724/1 "2023-08-29T07:55:41Z")

</div>

I setup Auth0 and Google credentials and had it working using the free trial period within Auth0. this is for a side-project so I need to switch to the free tier “Custom Social” Auth0 logins. [I followed these instructions](https://dev.to/victorioberra/auth0-custom-google-social-login-connection-1egg)but end up with the error “Invalid user id” in both the Auth0 test page and the app I had working with the Social Login that is pre-build by Auth0.

In GCP console I created a “Client ID for Web application”

- Authorised JavaScript origins = `https://MY_TENANT.uk.auth0.com`
- Authorised redirect URIs = `https://MY_TENANT.uk.auth0.com/login/callback`

GCP “OAuth consent screen”

- Publishing status = Testing
- User type = External

App Registration (just setting this to get it working)

- Application home page = `https://auth0.com`
- Application privacy policy link = `https://auth0.com`
- Application Terms of Service link = `https://auth0.com`
- Authorised domain = `auth0.com`
- Your non-sensitive scopes = `/auth/userinfo.email`
- Test users = `my email address`

It generates

- GCP\_CLIENT\_ID = `XXX.apps.googleusercontent.com`
- GCP\_CLIENT\_SECRET = `YYY`

Over in Auth0 I created a new Custom Socal Login

- Authorization URL = `https://accounts.google.com/o/oauth2/auth`
- Token URL = `https://oauth2.googleapis.com/token`
- Scope = `openid email` (spaces set on)
- Client ID = `GCP_CLIENT_ID`
- Client Secret = `GCP_CLIENT_SECRET`
- Fetch User Profile Script

```auto
function(accessToken, ctx, cb) {
  var p = {
    accessToken: accessToken,
    id_token: ctx.id_token
  };
  cb(null,p);
}

```

I also tried [Connect Apps to Generic OAuth2 Authorization Servers](https://auth0.com/docs/authenticate/identity-providers/social-identity-providers/oauth2#fetch-user-profile-script) using `https://www.googleapis.com/oauth2/v3/userinfo` as the endpoint in the function

Pres test, Login screen displayed, select test account, then the error is displayed

---

<div class="post-metadata">

**Author:** ![adam.straughan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adam.straughan/32/50272_2.png) [@adam.straughan](https://community.auth0.com/u/adam.straughan)\
**Post date:** [September 5, 2023, 9:55pm UTC](https://community.auth0.com/t/auth0-custom-social-for-google-fails-with-invalid-user-id/114724/2 "2023-09-05T21:55:21Z")

</div>

I solved it, see Stack Overflow

> <https://stackoverflow.com/questions/76995451/auth0-custom-social-for-google-fails-with-invalid-user-id/77047959#77047959>

---

<div class="post-metadata">

**Author:** ![apoorva.shirikanth](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/apoorva.shirikanth/32/60502_2.png) [@apoorva.shirikanth](https://community.auth0.com/u/apoorva.shirikanth)\
**Post date:** [January 8, 2025, 4:22am UTC](https://community.auth0.com/t/auth0-custom-social-for-google-fails-with-invalid-user-id/114724/3 "2025-01-08T04:22:19Z")

</div>

Thanks Adam! For anyone else facing this issue\*\*, here’s the updated `fetchUserProfile` script that worked for me

function fetchUserProfile(accessToken, context, callback) {  
request.get(  
{  
url: ‘[https://www.googleapis.com/oauth2/v3/userinfo](https://www.googleapis.com/oauth2/v3/userinfo)’,  
headers: {  
‘Authorization’: 'Bearer ’ + accessToken,  
}  
},  
(err, resp, body) =\> {  
if (err) {  
return callback(err);  
}  
if (resp.statusCode !== 200) {  
return callback(new Error(body));  
}  
let bodyParsed;  
try {  
bodyParsed = JSON.parse(body);  
} catch (jsonError) {  
return callback(new Error(body));  
}  
const profile = {  
user\_id: bodyParsed.sub, // ‘sub’ is the unique identifier for the user  
email: bodyParsed.email  
};  
callback(null, profile);  
}  
);  
}

---

<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:** [January 22, 2025, 4:22am UTC](https://community.auth0.com/t/auth0-custom-social-for-google-fails-with-invalid-user-id/114724/4 "2025-01-22T04:22:24Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
