Google Authentication

Solved
Hello, please I have a problem with the Google API. In fact, when I click to log in with my Google account on the website, it says there is a redirect error.
Authorization error
Error 400: redirect_uri_mismatch

You cannot connect to this app because it does not comply with Google's OAuth 2.0 regulations.

 session_start(); //Include Google client library include_once 'src/Google_Client.php'; include_once 'src/contrib/Google_Oauth2Service.php'; /* * Configuration and setup Google API */ $clientId = 'clientidxxxxxxxxx'; //Google client ID $clientSecret = 'clientsecretxxxxxx'; //Google client secret $redirectURL = 'http://localhost/tuto/index.php'; //Callback URL //Call Google API $gClient = new Google_Client(); $gClient->setApplicationName('Login to siteweb.com'); $gClient->setClientId($clientId); $gClient->setClientSecret($clientSecret); $gClient->setRedirectUri($redirectURL); $google_oauthV2 = new Google_Oauth2Service($gClient); 


Thank you.

Configuration: Windows / Chrome 96.0.4664.110

2 answers

  1. Moderator
    Hello
    The redirect URI (where the response is sent) must be registered in the API console, and the error indicates that you have either not done this or you have not done it correctly.

    Access your project console and look under API Access. You should see your client ID & client secret there, as well as a list of redirect URIs. If the desired URI is not listed, click on edit settings and add the URI to the list.

    Additionally, it definitely doesn't work on localhost.... It only works if Google can reach your URL from the outside.

    --
    .
    Best regards,
    Jordane
    -1