Testing Google OAuth 2.0 with localhost?
Asked Answered
L

9

47

How do I test the Google OAuth 2.0 on my app with localhost, since Google requires a top private domain as the authorized domain?

a

I tried to look up solutions, but all the solutions given have been a while ago, and I think Google has changed their service since then.

Lyontine answered 4/6, 2019 at 2:9 Comment(2)
Katie, have you tried to use Google OAuth2 in your application running on localhost? If it doesn't work, what error do you get? I think you don't need to get localhost to the list of authorized domains.Roxie
Hi, have you managed to find a good solution for this?Wonderstricken
G
45

localhost is not a valid top-level domain, and it won't let you generate credentials without setting up a consent screen. You can add more than one authorized domain if you'd like, but you can't leave it empty. But you CAN delete the field if you have no domains / would not like to add domains for now. you just can't LEAVE it empty.

Notice the description -- "When a domain is used". so it's not an obligation to add authorized domain for consent screen. Moreover, the authorized domain here is only related with consent screen. Authorized origins and Authorized redirect URLs needs to be specified in the credentials part, which is all that matters; specifying the origin from which requests will be accepted and where it will be redirected. So just omit the authorized domain in the consent screen.

enter image description here

So how to delete it? Just in case if you haven't noticed, just hover over the field and this little man will pop up. delete it. that's all. Now you should be able to save and continue, where it might ask you to setup scopes.

enter image description here

I know it's really late, hoping it might help others..

Gybe answered 3/3, 2021 at 17:46 Comment(1)
Awesome – thanks. After this, the next step for me was to add the localhost URIs to the project here console.cloud.google.com/apis/credentials . It let me add the authorized domain URIs after having creating it without any authorized domains.Beadsman
A
3

In case anyone has struck out on the suggestions above, this answer did the trick for me. Set my authorized JavaScript origins URI to http://localhost:8080 in the google API console then emptied my Chrome cache.

Ayacucho answered 9/6, 2021 at 21:4 Comment(0)
B
2

The list of authorized domains is required before you submit a request for app verification. If you want to configure a localhost redirect URI, that is configurable in your web OAuth client ID configuration.

Bealle answered 4/6, 2019 at 14:45 Comment(1)
But how can I enable OAuth2 sign-in for a server running on my local machine that I navigate to using localhost? This question is specifically about how to add localhost to the Authorized Domains.Persis
S
2

After about an hour banging my head against the wall I found this article that has a step by step solution that works (as of July 2020).

Basically you need to create a service account, share the sheet with that account, and then it should work.

All of the other auth methods I tried either raised nonsense errors, or simply silently didn't work.

Seedbed answered 20/7, 2020 at 21:38 Comment(3)
For some reason people get kicks out of giving negative points instead of answers, but this did indeed solve the problem.Seedbed
How do you use that article to enable "mydomain.dev" in google oauth2?Lactam
This is for a service account, not for oauth2.Circumflex
A
0

You add your final domain for when you are ready to become verified. Until then you will generate an OAuth client ID and enable https://localhost:3000 in "Authorized JavaScript origins"

Simple screenshot of the field you can enter localhost

Agonist answered 20/7, 2022 at 4:22 Comment(0)
T
0

Just add an OAuth-consent-screen from here without a domain or valid domain that's up to you, after that create Credentials from here, then select OAuth client ID and enter your from here you can add javascript origin url and there you go you've done.

Tumulus answered 24/8, 2022 at 7:27 Comment(0)
P
0

Not beautiful, but works!

I've made local website(domain) on Xampp like test1.com, added that domain in Authorized domains and started Chrome from separate shortcut with parameter --ignore-certificate-errors Note, that when you start with this flag, Chrome must not be running!

It cause Chrome to open web site in the xampp\htdocs folder and I was forced to go to folder test1.git and then to public folder, where finally site opened and the url was: https://test1.com/test1.git/public

ps. Use port 80 in httpd-vhosts.conf and not 443!

Peephole answered 13/9, 2022 at 18:26 Comment(0)
F
0

As long as you are on localhost (before deployment), you can set the Google credentials like this:

google credentials screenshot

Freestyle answered 20/11, 2023 at 22:47 Comment(0)
S
0

I am suprised to see, but you can do another way: install ngrok

curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list && sudo apt update && sudo apt install ngrok

For other OS: https://ngrok.com/download

Then go to: https://dashboard.ngrok.com/get-started/setup/linux [Auth Token Command][1]

Add auth token for your respective OS, then scroll down and you get command to run server

ngrok http http://localhost:8080

Do it in project! It will be forwarding to a domain now, I got it

Spotlight answered 20/3 at 13:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.