skip to Main Content

I have an application that has been working for several years. Login worked as it should, i.e. after redirection to Google login, access granted. The user was redirected to the address provided via setRedirectUri. I have been having a problem for a few weeks because suddenly, after successful login, the user is redirected to myaccount.google.com despite no modifications to the code.

I am attaching a code snippet

$credentials_file = $parameterBag->get('google_credentials');

$client = new Google_Client();
$client->setAuthConfig($credentials_file);

$client->setAccessType("offline");
$client->setIncludeGrantedScopes(true);

$client->setRedirectUri( $this->router->generate('oauth2callback', [], UrlGeneratorInterface::ABSOLUTE_URL) );
$client->setScopes(self::SCOPES);
$client->setPrompt('select_account consent');
$client->setApprovalPrompt('auto');

$code = $request->get('code', null);

if ( !$code ) {

    $auth_url = $client->createAuthUrl();
    return $this->redirect($auth_url);

} else {
    //magic with logged user
}

2

Answers


  1. Have you looked into Google’s side of things?

    Check Google Cloud Console :

    • Verify the Redirect URI
    • Check for Changes in Google’s API or Policies
    Login or Signup to reply.
    1. Have you setup your redirect url in the google admin panel.
    2. If you are using a local website try using http://localhost as your redirect domain and something like http://localhost/authorize for the redirect url and see if this works first, then change it afterwards if you need to.

    google redirect url

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search