Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/Google/Auth/OAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,34 @@ public function authenticatedRequest(Google_Http_Request $request)

/**
* @param string $code
* @param boolean $crossClient
* @throws Google_Auth_Exception
* @return string
*/
public function authenticate($code)
public function authenticate($code, $crossClient = false)
{
if (strlen($code) == 0) {
throw new Google_Auth_Exception("Invalid code");
}

$arguments = array(
'code' => $code,
'grant_type' => 'authorization_code',
'client_id' => $this->client->getClassConfig($this, 'client_id'),
'client_secret' => $this->client->getClassConfig($this, 'client_secret')
);

if($crossClient !== true) {
$arguments['redirect_uri'] = $this->client->getClassConfig($this, 'redirect_uri');
}

// We got here from the redirect from a successful authorization grant,
// fetch the access token
$request = new Google_Http_Request(
self::OAUTH2_TOKEN_URI,
'POST',
array(),
array(
'code' => $code,
'grant_type' => 'authorization_code',
'redirect_uri' => $this->client->getClassConfig($this, 'redirect_uri'),
'client_id' => $this->client->getClassConfig($this, 'client_id'),
'client_secret' => $this->client->getClassConfig($this, 'client_secret')
)
$arguments
);
$request->disableGzip();
$response = $this->client->getIo()->makeRequest($request);
Expand Down
11 changes: 7 additions & 4 deletions src/Google/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

if (!class_exists('Google_Client')) {
require_once dirname(__FILE__) . '/../autoload.php';
require_once dirname(__FILE__) . '/autoload.php';
}

/**
Expand All @@ -25,7 +25,7 @@
*/
class Google_Client
{
const LIBVER = "1.1.4";
const LIBVER = "1.1.5";
const USER_AGENT_SUFFIX = "google-api-php-client/";
/**
* @var Google_Auth_Abstract $auth
Expand Down Expand Up @@ -114,15 +114,18 @@ public function getLibraryVersion()

/**
* Attempt to exchange a code for an valid authentication token.
* If $crossClient is set to true, the request body will not include
* the request_uri argument
* Helper wrapped around the OAuth 2.0 implementation.
*
* @param $code string code from accounts.google.com
* @param $crossClient boolean, whether this is a cross-client authentication
* @return string token
*/
public function authenticate($code)
public function authenticate($code, $crossClient = false)
{
$this->authenticated = true;
return $this->getAuth()->authenticate($code);
return $this->getAuth()->authenticate($code, $crossClient);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Google/Collection.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

if (!class_exists('Google_Client')) {
require_once dirname(__FILE__) . '/../autoload.php';
require_once dirname(__FILE__) . '/autoload.php';
}

/**
Expand Down