Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sign-in is not working

I tried to use Google Sign-in for my website, however, it keeps giving me 400 error.

I referenced this article: https://developers.google.com/identity/sign-in/web/sign-in, and my code is really simple:

<html>
<head>
  <title>Test Google Login</title>
  <script src="https://apis.google.com/js/platform.js" async defer></script>
  <meta name="google-signin-client_id" content="<CHANGE IT>">
  <script>
  function onSignIn(googleUser) {
    var profile = googleUser.getBasicProfile();
    console.log('ID: ' + profile.getId());
    console.log('Name: ' + profile.getName());
    console.log('Image URL: ' + profile.getImageUrl());
    console.log('Email: ' + profile.getEmail());
  }
  </script>
</head>
<body>
  <div class="g-signin2" data-onsuccess="onSignIn"></div>
</body>
</html>

When I click Sign-in button, it popups a window, and after logged in, it gave me 400 error as below:

400. That’s an error.

The requested URL was not found on this server. That’s all we know.

I guess it's redirect issue, but I don't know how to configure it. So I checked url it returned to me:

https://accounts.google.com/o/oauth2/auth?fetch_basic_profile=true&scope=email+profile+openid&response_type=permission&e=3100087&redirect_uri=storagerelay://http/127.0.0.1:8000?id%3Dauth867179&ss_domain=http://127.0.0.1:8000&client_id=378468243311-9dt7m9ufa9mee305j1b12815put5betb.apps.googleusercontent.com&openid.realm&hl=en&from_login=1&as=1b5f0a407ea58e11&pli=1&authuser=0

Why is redirect_uri "storagerelay://http/127.0.0.1:8000?id%3Dauth867179"?

like image 463
david30xie Avatar asked Mar 23 '15 00:03

david30xie


2 Answers

Your code should work now.

Google fixed this issue. Origins with a trailing slash are also accepted now (Origin can be set in Google Developers Console > APIs & auth > Credentials).

like image 115
Jarosław Gomułka Avatar answered Nov 03 '22 22:11

Jarosław Gomułka


Redirect URIs

http://localhost:8000/      this **/** at end solve my problem

JavaScript origins

http://localhost:8000

NOTE: localhost and 127.0.0.1 conflicts can create problems for you sometime

like image 25
GrvTyagi Avatar answered Nov 03 '22 23:11

GrvTyagi