Skip to content

Commit ca81cc9

Browse files
committed
Allow for valid cross client authentication requests
1 parent 523430f commit ca81cc9

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/Google/Auth/OAuth2.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,34 @@ public function authenticatedRequest(Google_Http_Request $request)
7878

7979
/**
8080
* @param string $code
81+
* @param boolean $crossClient
8182
* @throws Google_Auth_Exception
8283
* @return string
8384
*/
84-
public function authenticate($code)
85+
public function authenticate($code, $crossClient)
8586
{
8687
if (strlen($code) == 0) {
8788
throw new Google_Auth_Exception("Invalid code");
8889
}
8990

91+
$arguments = array(
92+
'code' => $code,
93+
'grant_type' => 'authorization_code',
94+
'client_id' => $this->client->getClassConfig($this, 'client_id'),
95+
'client_secret' => $this->client->getClassConfig($this, 'client_secret')
96+
);
97+
98+
if($crossClient !== true) {
99+
$arguments['redirect_uri'] = $this->client->getClassConfig($this, 'redirect_uri');
100+
}
101+
90102
// We got here from the redirect from a successful authorization grant,
91103
// fetch the access token
92104
$request = new Google_Http_Request(
93105
self::OAUTH2_TOKEN_URI,
94106
'POST',
95107
array(),
96-
array(
97-
'code' => $code,
98-
'grant_type' => 'authorization_code',
99-
'redirect_uri' => $this->client->getClassConfig($this, 'redirect_uri'),
100-
'client_id' => $this->client->getClassConfig($this, 'client_id'),
101-
'client_secret' => $this->client->getClassConfig($this, 'client_secret')
102-
)
108+
$arguments
103109
);
104110
$request->disableGzip();
105111
$response = $this->client->getIo()->makeRequest($request);

src/Google/Client.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,18 @@ public function getLibraryVersion()
114114

115115
/**
116116
* Attempt to exchange a code for an valid authentication token.
117+
* If $crossClient is set to true, the request body will not include
118+
* the request_uri argument
117119
* Helper wrapped around the OAuth 2.0 implementation.
118120
*
119121
* @param $code string code from accounts.google.com
122+
* @param $crossIdentity boolean, whether this is a cross-client authentication
120123
* @return string token
121124
*/
122-
public function authenticate($code)
125+
public function authenticate($code, $crossClient = false)
123126
{
124127
$this->authenticated = true;
125-
return $this->getAuth()->authenticate($code);
128+
return $this->getAuth()->authenticate($code, $crossClient);
126129
}
127130

128131
/**

0 commit comments

Comments
 (0)