googleapis / google-api-php-client

A PHP client library for accessing Google APIs
Apache License 2.0
9.22k stars 3.52k forks source link

the queryParams added in createAuthUrl is not returned #2485

Closed rabol closed 11 months ago

rabol commented 11 months ago

Environment details

Steps to reproduce

  1. create a client.
  2. call the createAuthUrl method
  3. approve the request on the login
  4. observe that the passed queryParams is is NOT returned

Code example

# example

$client = new Client([
            'client_id' => config('services.google-drive.client_id'),
            'client_secret' => config('services.google-drive.client_secret'),
            'scopes' => [
                'https://www.googleapis.com/auth/drive.file',
                'https://www.googleapis.com/auth/drive',
            ],
            'redirect_uri' => route('users.integrations.google-drive.connect'), // NOTE: I do add the parameters here
            'approval_prompt' => 'force',
            'access_type' => 'offline',
        ]);

$authUrl = $client->createAuthUrl($client->getScopes(), ['igd' => $idg]);

the $authUrl is now:

https://accounts.google.com/o/oauth2/v2/auth?response_type=code&access_type=offline&client_id=XXXXXXXX&redirect_uri=YYYYYY&state&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.file%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&approval_prompt=force&igd=99df36fb-ee4a-4861-8d57-85b0b2905bcd

As one can see, the igd parameter is added, but this value is never returned to my web site after the approval

the return value is:

https://<my_return_url>?code=4%2F0Adeu5BWppRGhaAsAwDlDxbAMhbFIaEqk1rSHNdMKuQcKe-JXwcTE8fZZmMY3xLSv8XSs7g&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.file
chiragvels commented 11 months ago

Hi,

I think you need to use setState to get the added parameters after web site after the approval. $client->setState($sample_passthrough_value);

Reference: https://developers.google.com/identity/protocols/oauth2/web-server#creatingclient

rabol commented 11 months ago

Thanks that works