Skip to content
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

Error Saving the Google Ads Refresh Token #179

Closed
graphiostudio opened this issue Mar 6, 2024 · 57 comments
Closed

Error Saving the Google Ads Refresh Token #179

graphiostudio opened this issue Mar 6, 2024 · 57 comments

Comments

@graphiostudio
Copy link

When trying to authenticate with Google Ads account, getting this: "Error Saving the Google Ads Refresh Token. Please Try Again!". Container volume is writable. Logs are as below:

[0] [Error] Getting Google Ads Refresh Token!
[0] error : GaxiosError: invalid_grant
[0]     at Gaxios._request (/app/node_modules/gaxios/build/src/gaxios.js:142:23)
[0]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[0]     at async OAuth2Client.getTokenAsync (/app/node_modules/google-auth-library/build/src/auth/oauth2client.js:137:21)
[0]     at async getAdwordsRefreshToken (/app/.next/server/pages/api/adwords.js:143:27)
[0]     at async Object.apiResolver (/app/node_modules/next/dist/server/api-utils/node.js:366:9)
[0]     at async NextNodeServer.runApi (/app/node_modules/next/dist/server/next-server.js:481:9)
[0]     at async Object.fn (/app/node_modules/next/dist/server/next-server.js:741:37)
[0]     at async Router.execute (/app/node_modules/next/dist/server/router.js:252:36)
[0]     at async NextNodeServer.run (/app/node_modules/next/dist/server/base-server.js:365:29)
[0]     at async NextNodeServer.handleRequest (/app/node_modules/next/dist/server/base-server.js:303:20) {
[0]   config: {
[0]     method: 'POST',
[0]     url: 'https://oauth2.googleapis.com/token',
[0]     data: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
[0]     headers: {
[0]       'Content-Type': 'application/x-www-form-urlencoded',
[0]       'User-Agent': 'google-api-nodejs-client/9.6.3',
[0]       'x-goog-api-client': 'gl-node/20.11.1'
[0]     },
[0]     paramsSerializer: [Function: paramsSerializer],
[0]     body: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
[0]     validateStatus: [Function: validateStatus],
[0]     responseType: 'unknown',
[0]     errorRedactor: [Function: defaultErrorRedactor]
[0]   },
[0]   response: {
[0]     config: {
[0]       method: 'POST',
[0]       url: 'https://oauth2.googleapis.com/token',
[0]       data: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
[0]       headers: [Object],
[0]       paramsSerializer: [Function: paramsSerializer],
[0]       body: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
[0]       validateStatus: [Function: validateStatus],
[0]       responseType: 'unknown',
[0]       errorRedactor: [Function: defaultErrorRedactor]
[0]     },
[0]     data: { error: 'invalid_grant', error_description: 'Bad Request' },
[0]     headers: {
[0]       'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
[0]       'cache-control': 'no-cache, no-store, max-age=0, must-revalidate',
[0]       'content-encoding': 'gzip',
[0]       'content-type': 'application/json; charset=utf-8',
[0]       date: 'Wed, 06 Mar 2024 10:30:44 GMT',
[0]       expires: 'Mon, 01 Jan 1990 00:00:00 GMT',
[0]       pragma: 'no-cache',
[0]       server: 'scaffolding on HTTPServer2',
[0]       'transfer-encoding': 'chunked',
[0]       vary: 'Origin, X-Origin, Referer',
[0]       'x-content-type-options': 'nosniff',
[0]       'x-frame-options': 'SAMEORIGIN',
[0]       'x-xss-protection': '0'
[0]     },
[0]     status: 400,
[0]     statusText: 'Bad Request',
[0]     request: { responseURL: 'https://oauth2.googleapis.com/token' }
[0]   },
[0]   error: undefined,
[0]   status: 400,
[0]   [Symbol(gaxios-gaxios-error)]: '6.3.0'
[0] }
@saschafoerster
Copy link

I got the same error. :)

@towfiqi
Copy link
Owner

towfiqi commented Mar 6, 2024

Can you guys please make sure:

  1. You have enabled the Google Ads API.
  2. In the oAuth Consent screen setup, you inserted the right redirect URI. If your serpbear instance URL is https://myserpbear.com/ then the redirect URL should be: https://myserpbear.com/api/adwords.

If you have set it up correctly, and it still does not work, try creating the AdWords accounts first by following steps 4 and 5 of the documentation.

@saschafoerster
Copy link

I have already an Adwords account. Does it need to be a new one? I will test ASAP.

@towfiqi
Copy link
Owner

towfiqi commented Mar 6, 2024

You need 2 AdWords accounts, a test account, and a manager account.

@bananasplit8041
Copy link

same problem here, cant fix it with the 2 adword accounts etc

@m4nug
Copy link

m4nug commented Mar 7, 2024

same here. Fresh install of SerpBear, did everything like described in the docs but after the oauth2 flow:
Error Saving the Google Ads Refresh Token. Please Try Again!

Logs show:

[0] [Error] Getting Google Ads Refresh Token!
[0] error : GaxiosError: invalid_grant
[0]     at Gaxios._request (/app/node_modules/gaxios/build/src/gaxios.js:142:23)
[0]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[0]     at async OAuth2Client.getTokenAsync (/app/node_modules/google-auth-library/build/src/auth/oauth2client.js:137:21)
[0]     at async getAdwordsRefreshToken (/app/.next/server/pages/api/adwords.js:143:27)
[0]     at async Object.apiResolver (/app/node_modules/next/dist/server/api-utils/node.js:366:9)
[0]     at async NextNodeServer.runApi (/app/node_modules/next/dist/server/next-server.js:481:9)
[0]     at async Object.fn (/app/node_modules/next/dist/server/next-server.js:741:37)
[0]     at async Router.execute (/app/node_modules/next/dist/server/router.js:252:36)
[0]     at async NextNodeServer.run (/app/node_modules/next/dist/server/base-server.js:365:29)
[0]     at async NextNodeServer.handleRequest (/app/node_modules/next/dist/server/base-server.js:303:20) {
[0]   config: {
[0]     method: 'POST',
[0]     url: 'https://oauth2.googleapis.com/token',
[0]     data: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
[0]     headers: {
[0]       'Content-Type': 'application/x-www-form-urlencoded',
[0]       'User-Agent': 'google-api-nodejs-client/9.6.3',
[0]       'x-goog-api-client': 'gl-node/20.11.1'
[0]     },
[0]     paramsSerializer: [Function: paramsSerializer],
[0]     body: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
[0]     validateStatus: [Function: validateStatus],
[0]     responseType: 'unknown',
[0]     errorRedactor: [Function: defaultErrorRedactor]
[0]   },
[0]   response: {
[0]     config: {
[0]       method: 'POST',
[0]       url: 'https://oauth2.googleapis.com/token',
[0]       data: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
[0]       headers: [Object],
[0]       paramsSerializer: [Function: paramsSerializer],
[0]       body: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
[0]       validateStatus: [Function: validateStatus],
[0]       responseType: 'unknown',
[0]       errorRedactor: [Function: defaultErrorRedactor]
[0]     },
[0]     data: { error: 'invalid_grant', error_description: 'Bad Request' },
[0]     headers: {
[0]       'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
[0]       'cache-control': 'no-cache, no-store, max-age=0, must-revalidate',
[0]       'content-encoding': 'gzip',
[0]       'content-type': 'application/json; charset=utf-8',
[0]       date: 'Thu, 07 Mar 2024 13:30:13 GMT',
[0]       expires: 'Mon, 01 Jan 1990 00:00:00 GMT',
[0]       pragma: 'no-cache',
[0]       server: 'scaffolding on HTTPServer2',
[0]       'transfer-encoding': 'chunked',
[0]       vary: 'Origin, X-Origin, Referer',
[0]       'x-content-type-options': 'nosniff',
[0]       'x-frame-options': 'SAMEORIGIN',
[0]       'x-xss-protection': '0'
[0]     },
[0]     status: 400,
[0]     statusText: 'Bad Request',
[0]     request: { responseURL: 'https://oauth2.googleapis.com/token' }
[0]   },
[0]   error: undefined,
[0]   status: 400,
[0]   [Symbol(gaxios-gaxios-error)]: '6.3.0'
[0] }

@m4nug
Copy link

m4nug commented Mar 7, 2024

Can you guys please make sure:

  1. You have enabled the Google Ads API.
  2. In the oAuth Consent screen setup, you inserted the right redirect URI. If your serpbear instance URL is https://myserpbear.com/ then the redirect URL should be: https://myserpbear.com/api/adwords.

If you have set it up correctly, and it still does not work, try creating the AdWords accounts first by following steps 4 and 5 of the documentation.

Yes Google Ads API is enabled.
Yes oauth redirect URI is correct.
Did try to go ahead and do step 4 & 5 first, but another try to connect with Google Ads afterwards resulted with the same error.

@towfiqi
Copy link
Owner

towfiqi commented Mar 7, 2024

Ok, I just ran a test with a fresh Google account. It worked fine. I didn't need to create the Google ads accounts.
What I did differently is

  1. Make sure, the docker instance's NEXT_PUBLIC_APP_URL environment variable matches the app URL in the browser address bar.
  2. Went to the Google OAuth Consent Edit screen and clicked the "Publish" button.

Can you please try the above?

@m4nug
Copy link

m4nug commented Mar 7, 2024

Ok, I just ran a test with a fresh Google account. It worked fine. I didn't need to create the Google ads accounts. What I did differently is

  1. Make sure, the docker instance's NEXT_PUBLIC_APP_URL environment variable matches the app URL in the browser address bar.
  2. Went to the Google OAuth Consent Edit screen and clicked the "Publish" button.

Can you please try the above?

  1. NEXT_PUBLIC_APP_URL is set correctly and matches the redirect URI (without the /api/adwords). (Note that i use a domain with https and not localhost)
  2. Did publish the app in the Google Console now, but the error remains after trying to connect again.

@towfiqi
Copy link
Owner

towfiqi commented Mar 7, 2024

I captured the whole client id and client secret creation process. Please watch the video and see if you are doing anything wrong: https://erevanto.sirv.com/videos/serpbear_adwords_step1.mp4

@bananasplit8041
Copy link

I missed to publish the application, this step was missing at https://docs.serpbear.com/miscellaneous/integrate-google-ads
and I set the NEXT_PUBLIC_APP_URL on fly.io and now it's working!
!

@m4nug
Copy link

m4nug commented Mar 7, 2024

I captured the whole process client id and client secret creation process. Please watch the video and see if you are doing anything wrong: https://erevanto.sirv.com/videos/serpbear_adwords_step1.mp4

I did everything exactly like in the video but still having the error.
I will try it with a fresh Google account now.

@bananasplit8041 do you run it on localhost?

@Raxiel1987
Copy link

i have the same problem, i'm on http not "s" and can't publish the app, maybe this is the problem?

@towfiqi
Copy link
Owner

towfiqi commented Mar 7, 2024

You don't have to have a https URL to publish the app. Notice in the video I shared, I used a non-https URL. What error do you get when you try to publish the consent screen?

@bananasplit8041
Copy link

bananasplit8041 commented Mar 7, 2024

I captured the whole process client id and client secret creation process. Please watch the video and see if you are doing anything wrong: https://erevanto.sirv.com/videos/serpbear_adwords_step1.mp4

I did everything exactly like in the video but still having the error. I will try it with a fresh Google account now.

@bananasplit8041 do you run it on localhost?

no i run it on fly.io!

now I'm failing at the dev token:
] [ERROR] Google Ads Response : The developer token is only approved for use with test accounts. To access non-test accounts, apply for Basic or Standard access.

EDIT: now its working! need to click on https://ads.google.com/nav/selectaccount?sf=mt
Add account and copy the ID

wow, magic! really like this tool!!

@Raxiel1987
Copy link

You don't have to have a https URL to publish the app. Notice the video I shared, I used a non-https URL. What error do you get when you try to publish the consent screen?

i have error on consent screen that public must have https and cannot publish on htttp

anyway in http://localhost i can publish the app but the error remains

@Raxiel1987
Copy link

no matther what i do.. i can't save that fucking google ads credential
i've successfully saved google search console but cannot save ads, that i need to scraping the keyword and use it for my clients

@MyWay
Copy link

MyWay commented Mar 7, 2024

I have tried running it locally, just to ensure it's not a Google account setting and it works. Behind a reverse proxy (domain with private ip associated) for me it doesn't.

@towfiqi
Copy link
Owner

towfiqi commented Mar 7, 2024

@MyWay Go to Google Cloud Dashboard > API & Services > Credentials > OAuth Consent Screen, click the "Edit App" button, and try adding your domain in the "Authorized Domains" section. Then wait a few minutes or an hour and try again.

@MyWay
Copy link

MyWay commented Mar 7, 2024

I did that already, but it doesn't work.

@towfiqi
Copy link
Owner

towfiqi commented Mar 7, 2024

@MyWay Did you check the log? What error do you get?

@MyWay
Copy link

MyWay commented Mar 7, 2024

Sometimes I get the same error as reported by others, sometimes I get redirect_uri_mismatch, though the uri is correct and I did set the same https://domain to NEXT_PUBLIC_APP_URL.

@m4nug
Copy link

m4nug commented Mar 7, 2024

Setting up the Google Cloud project and API with a different Google account didn't help, still the same error.
I'm also using the app with a reverse proxy.

@MyWay
Copy link

MyWay commented Mar 7, 2024

For those using a reverse proxy who don't want to wait for an official fix, I solved by running another instance on the fly locally, on localhost (using the same data for SECRET and so on, otherwise serpbear won't be able to decrypt data anymore) and then copied the settings.json from the local working instance to the remote one.

Please backup everything before proceeding. And remember to stop your instance before moving things. I cannot guarantee it will work for you too. I did test it on docker + reverse proxy.

@towfiqi
Copy link
Owner

towfiqi commented Mar 8, 2024

@MyWay I am not well-versed with reverse proxy stuff. Can you see if this helps:
https://groups.google.com/g/securesocial/c/eoe3eiZ80_8?pli=1

@m4nug
Copy link

m4nug commented Mar 8, 2024

I have written numerous OAuth2 integrations for various APIs, and we have never had to make any modifications to connect from localhost or production.
I'll have a look at your code when i find time today.

@towfiqi
Copy link
Owner

towfiqi commented Mar 8, 2024

@m4nug That would be very much appreciated!

@graphiostudio
Copy link
Author

I tried all of the above. I was on Synology/docker/reverse proxy, all steps were done as instructed, env variables were ok, app published, etc... still got the same error.

Deployed fresh on a DO droplet, assigned domain, SSL, and all, everything was done properly again with a new Google account/ new ads account, yet still getting the same error. So, clearly, something is wrong here.

@towfiqi
Copy link
Owner

towfiqi commented Mar 8, 2024

@graphiostudio Are you getting the same invalid_grant error in the DO droplet or is it something different?

Is your Google account a workspace account with a custom domain or [email protected] account?
Is your Google Cloud account fully active and have a credit card linked?

@graphiostudio
Copy link
Author

@graphiostudio Are you getting the same invalid_grant error in the DO droplet or is it something different?

Is your Google account a workspace account with a custom domain or [email protected] account? Is your Google Cloud account fully active and have a credit card linked?

cards linked to both accounts. first try was with gmail.com account, second one is a custom domain/workspace account.

I was getting the same error, then I played around with URLs, and SSL a bit and now getting this, but when I use correct URLs and SSL, still keeps getting the previous error. Hope it helps.

2024-03-08T09:17:59.739546640Z [0] [Error] Getting Google Ads Refresh Token!
2024-03-08T09:17:59.744534061Z [0] error : GaxiosError: redirect_uri_mismatch
2024-03-08T09:17:59.744570824Z [0]     at Gaxios._request (/app/node_modules/gaxios/build/src/gaxios.js:142:23)
2024-03-08T09:17:59.744578656Z [0]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-03-08T09:17:59.744585518Z [0]     at async OAuth2Client.getTokenAsync (/app/node_modules/google-auth-library/build/src/auth/oauth2client.js:137:21)
2024-03-08T09:17:59.744592126Z [0]     at async getAdwordsRefreshToken (/app/.next/server/pages/api/adwords.js:143:27)
2024-03-08T09:17:59.744616293Z [0]     at async Object.apiResolver (/app/node_modules/next/dist/server/api-utils/node.js:366:9)
2024-03-08T09:17:59.744623272Z [0]     at async NextNodeServer.runApi (/app/node_modules/next/dist/server/next-server.js:481:9)
2024-03-08T09:17:59.744629923Z [0]     at async Object.fn (/app/node_modules/next/dist/server/next-server.js:741:37)
2024-03-08T09:17:59.744636501Z [0]     at async Router.execute (/app/node_modules/next/dist/server/router.js:252:36)
2024-03-08T09:17:59.744643045Z [0]     at async NextNodeServer.run (/app/node_modules/next/dist/server/base-server.js:365:29)
2024-03-08T09:17:59.744649529Z [0]     at async NextNodeServer.handleRequest (/app/node_modules/next/dist/server/base-server.js:303:20) {
2024-03-08T09:17:59.744656133Z [0]   config: {
2024-03-08T09:17:59.744662381Z [0]     method: 'POST',
2024-03-08T09:17:59.744668816Z [0]     url: 'https://oauth2.googleapis.com/token',
2024-03-08T09:17:59.744675399Z [0]     data: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
2024-03-08T09:17:59.744682521Z [0]     headers: {
2024-03-08T09:17:59.744688856Z [0]       'Content-Type': 'application/x-www-form-urlencoded',
2024-03-08T09:17:59.744695221Z [0]       'User-Agent': 'google-api-nodejs-client/9.6.3',
2024-03-08T09:17:59.744701496Z [0]       'x-goog-api-client': 'gl-node/20.11.1'
2024-03-08T09:17:59.744707753Z [0]     },
2024-03-08T09:17:59.744713876Z [0]     paramsSerializer: [Function: paramsSerializer],
2024-03-08T09:17:59.744720222Z [0]     body: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
2024-03-08T09:17:59.744727110Z [0]     validateStatus: [Function: validateStatus],
2024-03-08T09:17:59.744733576Z [0]     responseType: 'unknown',
2024-03-08T09:17:59.744739981Z [0]     errorRedactor: [Function: defaultErrorRedactor]
2024-03-08T09:17:59.744746281Z [0]   },
2024-03-08T09:17:59.744752412Z [0]   response: {
2024-03-08T09:17:59.744758605Z [0]     config: {
2024-03-08T09:17:59.744764828Z [0]       method: 'POST',
2024-03-08T09:17:59.744770956Z [0]       url: 'https://oauth2.googleapis.com/token',
2024-03-08T09:17:59.744777302Z [0]       data: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
2024-03-08T09:17:59.744784028Z [0]       headers: [Object],
2024-03-08T09:17:59.744790188Z [0]       paramsSerializer: [Function: paramsSerializer],
2024-03-08T09:17:59.744797926Z [0]       body: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
2024-03-08T09:17:59.744804673Z [0]       validateStatus: [Function: validateStatus],
2024-03-08T09:17:59.744811056Z [0]       responseType: 'unknown',
2024-03-08T09:17:59.744817375Z [0]       errorRedactor: [Function: defaultErrorRedactor]
2024-03-08T09:17:59.744829315Z [0]     },
2024-03-08T09:17:59.744835806Z [0]     data: {
2024-03-08T09:17:59.744841971Z [0]       error: 'redirect_uri_mismatch',
2024-03-08T09:17:59.744848554Z [0]       error_description: 'Bad Request'
2024-03-08T09:17:59.744854752Z [0]     },
2024-03-08T09:17:59.744860929Z [0]     headers: {
2024-03-08T09:17:59.744867392Z [0]       'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
2024-03-08T09:17:59.744874047Z [0]       'cache-control': 'no-cache, no-store, max-age=0, must-revalidate',
2024-03-08T09:17:59.744880272Z [0]       'content-encoding': 'gzip',
2024-03-08T09:17:59.744886437Z [0]       'content-type': 'application/json; charset=utf-8',
2024-03-08T09:17:59.744892709Z [0]       date: 'Fri, 08 Mar 2024 09:17:59 GMT',
2024-03-08T09:17:59.744899001Z [0]       expires: 'Mon, 01 Jan 1990 00:00:00 GMT',
2024-03-08T09:17:59.744905393Z [0]       pragma: 'no-cache',
2024-03-08T09:17:59.744911494Z [0]       server: 'scaffolding on HTTPServer2',
2024-03-08T09:17:59.744917796Z [0]       'transfer-encoding': 'chunked',
2024-03-08T09:17:59.744924153Z [0]       vary: 'Origin, X-Origin, Referer',
2024-03-08T09:17:59.744930398Z [0]       'x-content-type-options': 'nosniff',
2024-03-08T09:17:59.744936529Z [0]       'x-frame-options': 'SAMEORIGIN',
2024-03-08T09:17:59.744942889Z [0]       'x-xss-protection': '0'
2024-03-08T09:17:59.744949258Z [0]     },
2024-03-08T09:17:59.744955402Z [0]     status: 400,
2024-03-08T09:17:59.744961574Z [0]     statusText: 'Bad Request',
2024-03-08T09:17:59.744967844Z [0]     request: { responseURL: 'https://oauth2.googleapis.com/token' }
2024-03-08T09:17:59.744974220Z [0]   },
2024-03-08T09:17:59.744980446Z [0]   error: undefined,
2024-03-08T09:17:59.744986715Z [0]   status: 400,
2024-03-08T09:17:59.744992944Z [0]   [Symbol(gaxios-gaxios-error)]: '6.3.0'
2024-03-08T09:17:59.744999327Z [0] }

@towfiqi
Copy link
Owner

towfiqi commented Mar 8, 2024

@graphiostudio Can you make sure your NEXT_PUBLIC_APP_URL env variable matches your DO Sperbear instance URL?

@graphiostudio
Copy link
Author

@graphiostudio Can you make sure your NEXT_PUBLIC_APP_URL env variable matches your DO Sperbear instance URL?

Hi, it does match. Still same issue whatever I do.

@m4nug
Copy link

m4nug commented Mar 8, 2024

I did try it within the dev environment which was successful and then (of course) it also worked after I have added a reverse proxy to the dev environment... So as @towfiqi i was not able to reproduce the error in dev, so it could be related to running the app in docker. I'll investigate further.

@saschafoerster
Copy link

I am using Nginx as a proxy and Serpbear in docker. I tried all different things and always get the same token error as from the logs above.

@dangson92
Copy link

Got same error, I am trying all of these way bellow but didn't working

  1. Enabled Google Ads API
  2. Confirmed that I input the right redirect URL
  3. Confirmed that I have the right NEXT_PUBLIC_APP_URL

Running on personal server

@towfiqi
Copy link
Owner

towfiqi commented Mar 11, 2024

@dangson92 Are you seeing redirect_uri_mismatch in the docker log? or is it invalid_grant ?

@dangson92
Copy link

@dangson92 Are you seeing redirect_uri_mismatch in the docker log? or is it invalid_grant ?

I see this
data: {
serpbear-app-1 | [0] error: 'redirect_uri_mismatch',
serpbear-app-1 | [0] error_description: 'Bad Request'
serpbear-app-1 | [0] },

@towfiqi
Copy link
Owner

towfiqi commented Mar 12, 2024

redirect_uri_mismatch means your NEXT_PUBLIC_APP_URL, your actual web app URL that you use to access the serpbear app, and the redirect URL in the Google Auth consent screen does not match. They all should match.

@graphiostudio
Copy link
Author

I think what people are trying to say is (my case too), even the steps are complete, ENV set and URLs perfectly matching (ENV url=GAuth URL), a lot of people are still having the same issue. They're matching, yet I'm still getting mismatch error. 3 accounts, 3 different deployments so far, same issue.

@towfiqi
Copy link
Owner

towfiqi commented Mar 13, 2024

@graphiostudio Your initial error was invalid_grant are you now getting the redirect_uri_mismatch error?

@graphiostudio
Copy link
Author

@graphiostudio Your initial error was invalid_grant are you now getting the redirect_uri_mismatch error?

Yeb... Funny thing is when I was getting invalid_grant my ENV wasn't set at all (somehow didn't need it, it was localhost). When I started setting it and matching URLs I started to get redirect_uri_mismatch. Some mysterious forces are at work here...

@towfiqi
Copy link
Owner

towfiqi commented Mar 13, 2024

when you approve the Google authentication by selecting your Google Account, you are redirected to a page that displays the error message. what is that URL? Does that URL match the redirect URL set in the Google Auth redirect setting?

@graphiostudio
Copy link
Author

graphiostudio commented Mar 13, 2024

VIDEO REMOVED

is this correct?

2024-03-13T04:21:50.053560832Z [0] [Error] Getting Google Ads Refresh Token!
2024-03-13T04:21:50.054262365Z [0] error : GaxiosError: redirect_uri_mismatch

That's the error I'm getting...

@towfiqi
Copy link
Owner

towfiqi commented Mar 13, 2024

can you please share a screenshot of the redirect URL you set in the Google Auth settings?

@graphiostudio
Copy link
Author

graphiostudio commented Mar 13, 2024

can you please share a screenshot of the redirect URL you set in the Google Auth settings?

Sure.

IMAGES REMOVED

Billing is ok too, using this account actively...

@towfiqi
Copy link
Owner

towfiqi commented Mar 13, 2024

Did you add a test user to your auth consent settings? The test user should be the user email address that you are using to authenticate the integration.

@graphiostudio
Copy link
Author

Did you add a test user to your auth consent settings? The test user should be the user email address that you are using to authenticate the integration.

Yes... If I don't publish the app and add test user with same email address (I actually tried different emails as well) I'm still getting the same error. If I publish the app I don't need test users anymore, but yeah, still same results.

I thought it might be browser, caching, cookies issue and tried different clean browsers as well, same results...

@towfiqi
Copy link
Owner

towfiqi commented Mar 13, 2024

That's very strange. All your settings are correct. I only tried the integration with localhost and not with an actual domain. However, another user mentioned, that it worked fine for them with an actual domain. I will run some tests with an actual domain and report back.

@graphiostudio
Copy link
Author

That's very strange. All your settings are correct. I only tried the integration with localhost and not with an actual domain. However, another user mentioned, that it worked fine for them with an actual domain. I will run some tests with an actual domain and report back.

All good man, just letting you know because we love this project and want to see it go places!!!... Just take it as a bug report :) hope it helps for further development

@dangson92
Copy link

@towfiqi I think problem from the my actual domain. I check everything and all well done. The NEXT_PUBLIC_APP_URL is ok, Return url when I authenticated with google is ok

@towfiqi
Copy link
Owner

towfiqi commented Mar 13, 2024

@graphiostudio Just ran the app on a live server with an actual domain, and everything worked fine. However, I did not use Docker. Are you running the app with Docker?

@towfiqi
Copy link
Owner

towfiqi commented Mar 13, 2024

Turns out it was a bug specific to how Nextjs handles the NEXT_PUBLIC_APP_URL variable. #17641 When the app is built, it actually uses the value that was set on the built machine which means it's almost hardcoded. This only happens with docker installation. In any case, had to workaround this by grabbing the domain name from the request header and building the redirect URL using that.

So, those who are having this issue, update to version 2.0.2, and the issue should be fixed.

@m4nug
Copy link

m4nug commented Mar 13, 2024

Great news. Thanks for your hard work and sorry I couldn't find more time to help you.

@towfiqi
Copy link
Owner

towfiqi commented Mar 14, 2024

@m4nug No worries!

@graphiostudio
Copy link
Author

Worked on the first try now :) awesome, thank you.

@saschafoerster
Copy link

Worked like a charm now. :)

@ingeniumdesign
Copy link

hi, i have a domain/portforward from duckdns to my fritzbox.
i edit and add the NEXT_PUBLIC_APP_URL for the new duckdns url with port.

Portainer: NEXT_PUBLIC_APP_URL http://XXXXX.duckdns.org:13000 => Port:3000

Edit and add the API URL: http://XXXXX.duckdns.org:13000/api/adwords

The tool works fine with the duckdns url...

The Google Search Console Integrate works fine.
The Scraping work fine.

but the Integrate Google Ads dont work, and i have the Error: "Error Saving the Google Ads Refresh Token . Details: redirect_uri_mismatch. Please Try Again!"

SerpBear v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants