Skip to content

Google Oauth breaks - Cannot destructure property clientId of 'undefined' or 'null' #6852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
srameshr opened this issue Aug 9, 2020 · 13 comments
Labels
type:question Support or code-level question

Comments

@srameshr
Copy link
Contributor

srameshr commented Aug 9, 2020

New Issue Checklist

Issue Description

Google oAuth login fails because of clientId cant be destructured because of a missing param

Steps to reproduce

user.linkWith('google', { authData: {
       id: '123',
    id_token: '123123',
    access_token: '23123'
}});

Actual Outcome

error: Uncaught internal server error.Cannot destructure property `clientId` of 'undefined' or 'null'. {"stack":"TypeError: Cannot destructure property `clientId` of 'undefined' or 'null'.\n    at verifyIdToken (node_modules/parse-server/lib/Adapters/Auth/google.js:66:4)\n    at Object.validateAuthData (node_modules/parse-server/lib/Adapters/Auth/google.js:107:10)\n    at node_modules/parse-server/lib/Adapters/Auth/index.js:93:20\n    at node_modules/parse-server/lib/RestWrite.js:361:12\n    at Array.map (<anonymous>)\n    at RestWrite.handleAuthDataValidation (node_modules/parse-server/lib/RestWrite.js:350:45)\n    at node_modules/parse-server/lib/RestWrite.js:496:17\n    at processTicksAndRejections (internal/process/task_queues.js:93:5)"}
TypeError: Cannot destructure property `clientId` of 'undefined' or 'null'.
    at verifyIdToken (node_modules/parse-server/lib/Adapters/Auth/google.js:66:4)
    at Object.validateAuthData (node_modules/parse-server/lib/Adapters/Auth/google.js:107:10)
    at node_modules/parse-server/lib/Adapters/Auth/index.js:93:20
    at node_modules/parse-server/lib/RestWrite.js:361:12
    at Array.map (<anonymous>)
    at RestWrite.handleAuthDataValidation (node_modules/parse-server/lib/RestWrite.js:350:45)
    at node_modules/parse-server/lib/RestWrite.js:496:17
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Expected Outcome

Should return a 201 with created resource.

Environment

Server

  • Parse Server version: 4.3.0
  • Operating system: MacOSX
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Localhost

Database

  • System (MongoDB or Postgres): Mongo
  • Database version: 4.X
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): Localhost

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): CloudCode + JS SDK
  • SDK version: 1.8

Logs

verbose: REQUEST for [POST] /parse/functions/post_sign_in: {
  "authData": {
    "platform": {
      "name": "google",
      "auth": {
        "id": "XXX",
        "id_token": "XXX.XXX.X-X-X-XX-X-X-X-X-X",
        "access_token": "X.X-XXX"
      }
    },
    "profile": {
      "email": "[email protected]",
      "avatar": "https://lh3.xxx,
      "firstName": "xxx",
      "lastName": "xxx"
    }
  }
} {"method":"POST","url":"/parse/functions/post_sign_in","headers":{"host":"localhost:8080","connection":"keep-alive","content-length":"1816","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36","dnt":"1","content-type":"text/plain","accept":"*/*","origin":"http://localhost:3000","sec-fetch-site":"same-site","sec-fetch-mode":"cors","sec-fetch-dest":"empty","referer":"http://localhost:3000/","accept-encoding":"gzip, deflate, br","accept-language":"en-US,en;q=0.9"},"body":{"authData":{"platform":{"name":"google","auth":{"id":"xxx","id_token":"xx.xxx.xxx-j6O22-xx-xx-xx-x-xx-xxxx-x","access_token":"xxx.xxx"}},"profile":{"email":"[email protected]","avatar":"https://lh3.xx.com/a-/xx=s96-c","firstName":"xxx","lastName":"R"}}}}
@mtrezza mtrezza added the state:duplicate Duplicate of already reported issue label Aug 9, 2020
@mtrezza mtrezza closed this as completed Aug 9, 2020
@mtrezza mtrezza reopened this Aug 9, 2020
@mtrezza
Copy link
Member

mtrezza commented Aug 9, 2020

Thanks for reporting.

@SebC99 since you are familiar with #6734, do you have any suggestion why this fails?

@srameshr
Copy link
Contributor Author

srameshr commented Aug 9, 2020

@mtrezza Its because the validate method is trying to destructure a key called { clientID } from its second parameter, from its definition but it is not set during the invocation.

@mtrezza
Copy link
Member

mtrezza commented Aug 9, 2020

Google Auth adapter changed in Parse Server 4.3.0 with #6734, it seems that change broke the adapter. I think we are also missing a test case here for Parse.User.linkWith() for Google. Would you want to add such a failing test to AuthenticationAdapters.spec.js?

@mtrezza mtrezza removed the state:duplicate Duplicate of already reported issue label Aug 9, 2020
@srameshr
Copy link
Contributor Author

srameshr commented Aug 9, 2020

Pressed for time as of now.

@SebC99
Copy link
Contributor

SebC99 commented Aug 9, 2020

That’s because google auth is not set in your auth settings in parse server configuration.
There’s already a PR (#6844) to allow empty settings

@srameshr
Copy link
Contributor Author

srameshr commented Aug 9, 2020

Oh ok, so the docs was misleading in mentioning that only FB and Twitter auth details are required while initialising Parse

@mtrezza
Copy link
Member

mtrezza commented Aug 9, 2020

I am glad to see we could help.

If you think there is anything that can be improved in the docs that would have helped you, in addition to what is already discussed in parse-community/docs#754, please feel free to open an issue in the docs repo.

I am closing this as it seems to be resolved. Feel free to comment if you have any further questions and we can re-open this issue.

@mtrezza mtrezza closed this as completed Aug 9, 2020
@srameshr
Copy link
Contributor Author

@mtrezza I have a PR here: parse-community/docs#760

@LilMoke
Copy link

LilMoke commented Aug 11, 2020

Ok, so I am posting this in hope it will re-open this issue. I posted an issues #6856 and was referred back to here.

I see that this issue was closed and that it appears help was given to someone, but what is the resolution?

I have tried a few things mentioned in here, but I cannot remove that error. Please help!!

@mtrezza
Copy link
Member

mtrezza commented Aug 11, 2020

The solution is indicated here: #6852 (comment) and further explained here: #6844

As I understand it, you need to properly configure the Google auth adapter in Parse Server. What is your current configuration? You need to at least set an empty object for the adapter.

@LilMoke
Copy link

LilMoke commented Aug 11, 2020

In this doc it does not show a google property: https://parseplatform.org/parse-server/api/master/ParseServerOptions.html

So, do I need to add an empty google: {} object where I create my ParseServer?

srameshr mentioned to add the empty google object, but I am not sure where it needs to be added? I have tried a few places but no luck.

@srameshr
Copy link
Contributor Author

srameshr commented Aug 11, 2020

@LilMoke For now add it under auth.

new ParseServer({
  ...yourOptions,
  auth: {
    google: {} // or google: { clientId: '' } makes no difference.
  }
})

@LilMoke
Copy link

LilMoke commented Aug 11, 2020

Awesome, thank you so much, I was not putting the auth: section as soon as I added that it al started working.

One last thing. Would you be able to tell me the best way to extend:

private fun buildGoogleSignInClient(context: Context): GoogleSignInClient {
	val signInOptions = GoogleSignInOptions.Builder()
		.requestId()
		.requestEmail()
		.requestIdToken(clientId)
		.build()
	return GoogleSignIn.getClient(context, signInOptions)
}

I want to add:

		.requestProfile()

Do I need to create my own ParseGoogleUtils, or can this be set somewhere?

Again, thanks for the help, it works perfect.

@mtrezza mtrezza added type:question Support or code-level question and removed 🔧 troubleshooting labels Jul 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

4 participants