53

I'm trying to add a Google Sign In Authentication system to my app, but I keep getting a strange error that I haven't seen anyone get. I'm using EXACTLY the google example code.

I thought it could be some mistake when loading the api, so I checked the async loading and everything seems to be loading properly, but I keep getting this error in the console:

gapi.auth2.ExternallyVisibleError: Invalid cookiePolicy

I searched everywhere for people with the same problem, but I could not find anything similar.

Any ideas?

EDIT: I tried to create a page with ONLY the code of the tutorial, but the error still occurs.

BryanH
  • 5,826
  • 3
  • 34
  • 47
KoJoVe
  • 1,553
  • 2
  • 10
  • 9

5 Answers5

102

Well, turns out I was trying to test the API by directly acessing my files locally (index.html). The Google Sign In API only works in a running web server. I started a simple node.js server, ran my app trhough this server, and everthing worked just fine.

KoJoVe
  • 1,553
  • 2
  • 10
  • 9
9

As already answered by KoJoVe, you need to run inside a web server. If you are using Python 2.7 you might use python -m SimpleHTTPServer 8000 and then use localhost:8000 on your browser

Shreyas Gaonkar
  • 265
  • 2
  • 5
4

I've been trying to get a chrome extension to work for a very long time, and I recently decided to click into the error. The reason is because the google platform script checks window.location.protocol (which isn't https for chrome extension) and throws the error 'invalid cookie policy'.

My theory as to why Google won't fix this:

  1. They want to drive people into using paid OAuth2 endpoints

  2. They want to know who received the tokens, if possible (via certificate authorities)

neaumusic
  • 10,027
  • 9
  • 55
  • 83
  • Have you figured it out how to implement auth2 in chrome-extension because i'm strugling with this too – Naveen Kashyap Oct 26 '20 at 18:58
  • @NaveenKashyap I gave up, and there's a difference between OAuth and OpenID which is what I wanted to use. https://stackoverflow.com/questions/59556339/can-chrome-extensions-steal-oauth-tokens-from-redirect-uri – neaumusic Oct 26 '20 at 23:50
2

I was having this problem using react-google-login in a create-react-app, and I found that I was accessing the page with http://[::1]:3000/sign_in instead of localhost.

I think google does not like 127.0.0.1 or ::1 since we expose the IP directly or something

When I change to localhost:3000 and it worked.

Harry Yuan
  • 21
  • 1
  • 1
0

This worked in my case with python 3:

open python terminal and write the following code:

from http.server import SimpleHTTPRequestHandler as handler
import socketserver as socket
httpd = socket.TCPServer(("",8000),handler)
httpd.serve_forever()
Ahtisham
  • 9,170
  • 4
  • 43
  • 57