googleapis / google-api-php-client

A PHP client library for accessing Google APIs
http://googleapis.github.io/google-api-php-client/
Apache License 2.0
9.32k stars 3.52k forks source link

Wrong redirect #2523

Closed unbreak closed 10 months ago

unbreak commented 10 months ago

My Application was working fine, but few weeks ago after logging in via Google account, the application suddenly started redirecting to myaccount.google.com instead of the address provided as redirectUri:

            $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');

            $auth_url = $client->createAuthUrl();
            return $this->redirect($auth_url);
vishwarajanand commented 10 months ago

At $this->redirect($auth_url); you can redirect to any URL you wish to. Consider saving the URL and redirecting to it.

unbreak commented 10 months ago

@vishwarajanand I don't think you fully understood what the problem was. The $this->redirect($auth_url) element redirects the user to the Google Account login address generated by Google Client. After logging in, the user, instead of returning to the application to the link set via $client->setRedirectUri($url), is redirected to the website myaccount.google.com

Your comment not resolve the problem.