$clientId, 'clientSecret' => $clientSecret, 'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth', // Where to return the user to if they accept your request to access their account. // You must authorize this URI in the Google API Console. 'redirectUri' => $redirectURI, 'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token', 'scope' => $scopes, 'expiry' => \Google\Auth\OAuth2::DEFAULT_EXPIRY_SECONDS *24 ]); $client = new Client(['proxy' => 'http://127.0.0.1:1087']); $httpHandler = new Guzzle7HttpHandler($client); // The authorization URI will, upon redirecting, return a parameter called code. $code = $request->get('code'); if ($code == null || $code == "") { $authenticationUrl = $oauth2->buildFullAuthorizationUri(['access_type' => 'offline']); // dump($authenticationUrl); // redirect($authenticationUrl); header("Location: " . $authenticationUrl); // redirect()->to($authenticationUrl); } else { dump("code is " . $code); // With the code returned by the OAuth flow, we can retrieve the refresh token. $oauth2->setCode($code); $authToken = $oauth2->fetchAuthToken(); $refreshToken = $authToken['access_token']; // The UserRefreshCredentials will use the refresh token to 'refresh' the credentials when // they expire. $credentials = new UserRefreshCredentials( $scopes, [ 'client_id' => $clientId, 'client_secret' => $clientSecret, 'refresh_token' => $refreshToken ] ); session(['credentials' => $credentials]); // Return the user to the home page. dump("before redirect"); redirect('google/home/index'); // header("Location: index.php"); } }