public function testCreateAuthUrl() { $client = $this->getClient(); $oauth = new Google_Auth_OAuth2($client); $client->setClientId('clientId1'); $client->setClientSecret('clientSecret1'); $client->setRedirectUri('http://localhost'); $client->setDeveloperKey('devKey'); $client->setAccessType('offline'); $client->setApprovalPrompt('force'); $client->setRequestVisibleActions(array('http://foo')); $client->setLoginHint("*****@*****.**"); $authUrl = $oauth->createAuthUrl("http://googleapis.com/scope/foo"); $expected = "https://accounts.google.com/o/oauth2/auth" . "?response_type=code" . "&redirect_uri=http%3A%2F%2Flocalhost" . "&client_id=clientId1" . "&scope=http%3A%2F%2Fgoogleapis.com%2Fscope%2Ffoo" . "&access_type=offline" . "&approval_prompt=force" . "&login_hint=bob%40example.org"; $this->assertEquals($expected, $authUrl); // Again with a blank login hint (should remove all traces from authUrl) $client->setLoginHint(""); $client->setHostedDomain("example.com"); $client->setOpenidRealm("example.com"); $client->setPrompt("select_account"); $client->setIncludeGrantedScopes(true); $authUrl = $oauth->createAuthUrl("http://googleapis.com/scope/foo"); $expected = "https://accounts.google.com/o/oauth2/auth" . "?response_type=code" . "&redirect_uri=http%3A%2F%2Flocalhost" . "&client_id=clientId1" . "&scope=http%3A%2F%2Fgoogleapis.com%2Fscope%2Ffoo" . "&access_type=offline" . "&prompt=select_account" . "&hd=example.com" . "&openid.realm=example.com" . "&include_granted_scopes=true"; $this->assertEquals($expected, $authUrl); }
public function testCreateAuthUrl() { $client = $this->getClient(); $oauth = new Google_Auth_OAuth2($client); $client->setClientId('clientId1'); $client->setClientSecret('clientSecret1'); $client->setRedirectUri('http://localhost'); $client->setDeveloperKey('devKey'); $client->setAccessType('offline'); $client->setApprovalPrompt('force'); $client->setRequestVisibleActions(array('http://foo')); $authUrl = $oauth->createAuthUrl("http://googleapis.com/scope/foo"); $expected = "https://accounts.google.com/o/oauth2/auth" . "?response_type=code" . "&redirect_uri=http%3A%2F%2Flocalhost" . "&client_id=clientId1" . "&scope=http%3A%2F%2Fgoogleapis.com%2Fscope%2Ffoo" . "&access_type=offline" . "&approval_prompt=force"; $this->assertEquals($expected, $authUrl); }
private function authGoogle() { $_TokenGoogle = sha1(openssl_random_pseudo_bytes(1024)); $clientGoogle = new \Google_Auth_OAuth2($this->client); $urlAuth = $clientGoogle->createAuthUrl(\Google_Service_Oauth2::USERINFO_EMAIL . ' ' . \Google_Service_Oauth2::USERINFO_PROFILE . ' ' . \Google_Service_Calendar::CALENDAR . ' ' . \Google_Service_Drive::DRIVE); //\Session::put('_TokenGoogle',$_TokenGoogle); //\Session::save(); //$value = \Session::get('_TokenGoogle'); //$urlAuth="https://accounts.google.com/o/oauth2/auth?client_id=".$cfgGoogleApi['client_id']."&response_type=code&scope=profile&redirect_uri=".$cfgGoogleApi['redirect_uris'][0]."&login_hint=jose.hdez.bta@gmail.com&state=".$state; header('Location: ' . $urlAuth); exit; }