Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/updraftp.../includes/Google/Auth
File: OAuth2.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* Copyright 2008 Google Inc.
[2] Fix | Delete
*
[3] Fix | Delete
* Licensed under the Apache License, Version 2.0 (the "License");
[4] Fix | Delete
* you may not use this file except in compliance with the License.
[5] Fix | Delete
* You may obtain a copy of the License at
[6] Fix | Delete
*
[7] Fix | Delete
* http://www.apache.org/licenses/LICENSE-2.0
[8] Fix | Delete
*
[9] Fix | Delete
* Unless required by applicable law or agreed to in writing, software
[10] Fix | Delete
* distributed under the License is distributed on an "AS IS" BASIS,
[11] Fix | Delete
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
[12] Fix | Delete
* See the License for the specific language governing permissions and
[13] Fix | Delete
* limitations under the License.
[14] Fix | Delete
*/
[15] Fix | Delete
[16] Fix | Delete
if (!class_exists('UDP_Google_Client')) {
[17] Fix | Delete
require_once dirname(__FILE__) . '/../autoload.php';
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Authentication class that deals with the OAuth 2 web-server authentication flow
[22] Fix | Delete
*
[23] Fix | Delete
*/
[24] Fix | Delete
class Google_Auth_OAuth2 extends Google_Auth_Abstract
[25] Fix | Delete
{
[26] Fix | Delete
const OAUTH2_REVOKE_URI = 'https://accounts.google.com/o/oauth2/revoke';
[27] Fix | Delete
const OAUTH2_TOKEN_URI = 'https://accounts.google.com/o/oauth2/token';
[28] Fix | Delete
const OAUTH2_AUTH_URL = 'https://accounts.google.com/o/oauth2/auth';
[29] Fix | Delete
const CLOCK_SKEW_SECS = 300; // five minutes in seconds
[30] Fix | Delete
const AUTH_TOKEN_LIFETIME_SECS = 300; // five minutes in seconds
[31] Fix | Delete
const MAX_TOKEN_LIFETIME_SECS = 86400; // one day in seconds
[32] Fix | Delete
const OAUTH2_ISSUER = 'accounts.google.com';
[33] Fix | Delete
[34] Fix | Delete
/** @var Google_Auth_AssertionCredentials $assertionCredentials */
[35] Fix | Delete
private $assertionCredentials;
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* @var string The state parameters for CSRF and other forgery protection.
[39] Fix | Delete
*/
[40] Fix | Delete
private $state;
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* @var array The token bundle.
[44] Fix | Delete
*/
[45] Fix | Delete
private $token = array();
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* @var UDP_Google_Client the base client
[49] Fix | Delete
*/
[50] Fix | Delete
private $client;
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Instantiates the class, but does not initiate the login flow, leaving it
[54] Fix | Delete
* to the discretion of the caller.
[55] Fix | Delete
*/
[56] Fix | Delete
public function __construct(UDP_Google_Client $client)
[57] Fix | Delete
{
[58] Fix | Delete
$this->client = $client;
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Perform an authenticated / signed apiHttpRequest.
[63] Fix | Delete
* This function takes the apiHttpRequest, calls apiAuth->sign on it
[64] Fix | Delete
* (which can modify the request in what ever way fits the auth mechanism)
[65] Fix | Delete
* and then calls apiCurlIO::makeRequest on the signed request
[66] Fix | Delete
*
[67] Fix | Delete
* @param Google_Http_Request $request
[68] Fix | Delete
* @return Google_Http_Request The resulting HTTP response including the
[69] Fix | Delete
* responseHttpCode, responseHeaders and responseBody.
[70] Fix | Delete
*/
[71] Fix | Delete
public function authenticatedRequest(UDP_Google_Http_Request $request)
[72] Fix | Delete
{
[73] Fix | Delete
$request = $this->sign($request);
[74] Fix | Delete
return $this->client->getIo()->makeRequest($request);
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* @param string $code
[79] Fix | Delete
* @throws Google_Auth_Exception
[80] Fix | Delete
* @return string
[81] Fix | Delete
*/
[82] Fix | Delete
public function authenticate($code)
[83] Fix | Delete
{
[84] Fix | Delete
if (strlen($code) == 0) {
[85] Fix | Delete
throw new Google_Auth_Exception("Invalid code");
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
// We got here from the redirect from a successful authorization grant,
[89] Fix | Delete
// fetch the access token
[90] Fix | Delete
$request = new UDP_Google_Http_Request(
[91] Fix | Delete
self::OAUTH2_TOKEN_URI,
[92] Fix | Delete
'POST',
[93] Fix | Delete
array(),
[94] Fix | Delete
array(
[95] Fix | Delete
'code' => $code,
[96] Fix | Delete
'grant_type' => 'authorization_code',
[97] Fix | Delete
'redirect_uri' => $this->client->getClassConfig($this, 'redirect_uri'),
[98] Fix | Delete
'client_id' => $this->client->getClassConfig($this, 'client_id'),
[99] Fix | Delete
'client_secret' => $this->client->getClassConfig($this, 'client_secret')
[100] Fix | Delete
)
[101] Fix | Delete
);
[102] Fix | Delete
$request->disableGzip();
[103] Fix | Delete
$response = $this->client->getIo()->makeRequest($request);
[104] Fix | Delete
[105] Fix | Delete
if ($response->getResponseHttpCode() == 200) {
[106] Fix | Delete
$this->setAccessToken($response->getResponseBody());
[107] Fix | Delete
$this->token['created'] = time();
[108] Fix | Delete
return $this->getAccessToken();
[109] Fix | Delete
} else {
[110] Fix | Delete
$decodedResponse = json_decode($response->getResponseBody(), true);
[111] Fix | Delete
if ($decodedResponse != null && $decodedResponse['error']) {
[112] Fix | Delete
$errorText = $decodedResponse['error'];
[113] Fix | Delete
if (isset($decodedResponse['error_description'])) {
[114] Fix | Delete
$errorText .= ": " . $decodedResponse['error_description'];
[115] Fix | Delete
}
[116] Fix | Delete
}
[117] Fix | Delete
throw new Google_Auth_Exception(
[118] Fix | Delete
sprintf(
[119] Fix | Delete
"Error fetching OAuth2 access token, message: '%s'",
[120] Fix | Delete
$errorText
[121] Fix | Delete
),
[122] Fix | Delete
$response->getResponseHttpCode()
[123] Fix | Delete
);
[124] Fix | Delete
}
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Create a URL to obtain user authorization.
[129] Fix | Delete
* The authorization endpoint allows the user to first
[130] Fix | Delete
* authenticate, and then grant/deny the access request.
[131] Fix | Delete
* @param string $scope The scope is expressed as a list of space-delimited strings.
[132] Fix | Delete
* @return string
[133] Fix | Delete
*/
[134] Fix | Delete
public function createAuthUrl($scope)
[135] Fix | Delete
{
[136] Fix | Delete
$params = array(
[137] Fix | Delete
'response_type' => 'code',
[138] Fix | Delete
'redirect_uri' => $this->client->getClassConfig($this, 'redirect_uri'),
[139] Fix | Delete
'client_id' => $this->client->getClassConfig($this, 'client_id'),
[140] Fix | Delete
'scope' => $scope,
[141] Fix | Delete
'access_type' => $this->client->getClassConfig($this, 'access_type'),
[142] Fix | Delete
);
[143] Fix | Delete
[144] Fix | Delete
// Prefer prompt to approval prompt.
[145] Fix | Delete
if ($this->client->getClassConfig($this, 'prompt')) {
[146] Fix | Delete
$params = $this->maybeAddParam($params, 'prompt');
[147] Fix | Delete
} else {
[148] Fix | Delete
$params = $this->maybeAddParam($params, 'approval_prompt');
[149] Fix | Delete
}
[150] Fix | Delete
$params = $this->maybeAddParam($params, 'login_hint');
[151] Fix | Delete
$params = $this->maybeAddParam($params, 'hd');
[152] Fix | Delete
$params = $this->maybeAddParam($params, 'openid.realm');
[153] Fix | Delete
$params = $this->maybeAddParam($params, 'include_granted_scopes');
[154] Fix | Delete
[155] Fix | Delete
// If the list of scopes contains plus.login, add request_visible_actions
[156] Fix | Delete
// to auth URL.
[157] Fix | Delete
$rva = $this->client->getClassConfig($this, 'request_visible_actions');
[158] Fix | Delete
if (strpos($scope, 'plus.login') && strlen($rva) > 0) {
[159] Fix | Delete
$params['request_visible_actions'] = $rva;
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
if (isset($this->state)) {
[163] Fix | Delete
$params['state'] = $this->state;
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
return self::OAUTH2_AUTH_URL . "?" . http_build_query($params, '', '&');
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* @param string $token
[171] Fix | Delete
* @throws Google_Auth_Exception
[172] Fix | Delete
*/
[173] Fix | Delete
public function setAccessToken($token)
[174] Fix | Delete
{
[175] Fix | Delete
$token = json_decode($token, true);
[176] Fix | Delete
if ($token == null) {
[177] Fix | Delete
throw new Google_Auth_Exception('Could not json decode the token');
[178] Fix | Delete
}
[179] Fix | Delete
if (! isset($token['access_token'])) {
[180] Fix | Delete
throw new Google_Auth_Exception("Invalid token format");
[181] Fix | Delete
}
[182] Fix | Delete
$this->token = $token;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
public function getAccessToken()
[186] Fix | Delete
{
[187] Fix | Delete
return json_encode($this->token);
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
public function getRefreshToken()
[191] Fix | Delete
{
[192] Fix | Delete
if (array_key_exists('refresh_token', $this->token)) {
[193] Fix | Delete
return $this->token['refresh_token'];
[194] Fix | Delete
} else {
[195] Fix | Delete
return null;
[196] Fix | Delete
}
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
public function setState($state)
[200] Fix | Delete
{
[201] Fix | Delete
$this->state = $state;
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
public function setAssertionCredentials(Google_Auth_AssertionCredentials $creds)
[205] Fix | Delete
{
[206] Fix | Delete
$this->assertionCredentials = $creds;
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Include an accessToken in a given apiHttpRequest.
[211] Fix | Delete
* @param Google_Http_Request $request
[212] Fix | Delete
* @return Google_Http_Request
[213] Fix | Delete
* @throws Google_Auth_Exception
[214] Fix | Delete
*/
[215] Fix | Delete
public function sign(UDP_Google_Http_Request $request)
[216] Fix | Delete
{
[217] Fix | Delete
// add the developer key to the request before signing it
[218] Fix | Delete
if ($this->client->getClassConfig($this, 'developer_key')) {
[219] Fix | Delete
$request->setQueryParam('key', $this->client->getClassConfig($this, 'developer_key'));
[220] Fix | Delete
}
[221] Fix | Delete
[222] Fix | Delete
// Cannot sign the request without an OAuth access token.
[223] Fix | Delete
if (null == $this->token && null == $this->assertionCredentials) {
[224] Fix | Delete
return $request;
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
// Check if the token is set to expire in the next 30 seconds
[228] Fix | Delete
// (or has already expired).
[229] Fix | Delete
if ($this->isAccessTokenExpired()) {
[230] Fix | Delete
if ($this->assertionCredentials) {
[231] Fix | Delete
$this->refreshTokenWithAssertion();
[232] Fix | Delete
} else {
[233] Fix | Delete
$this->client->getLogger()->debug('OAuth2 access token expired');
[234] Fix | Delete
if (! array_key_exists('refresh_token', $this->token)) {
[235] Fix | Delete
$error = "The OAuth 2.0 access token has expired,"
[236] Fix | Delete
." and a refresh token is not available. Refresh tokens"
[237] Fix | Delete
." are not returned for responses that were auto-approved.";
[238] Fix | Delete
[239] Fix | Delete
$this->client->getLogger()->error($error);
[240] Fix | Delete
throw new Google_Auth_Exception($error);
[241] Fix | Delete
}
[242] Fix | Delete
$this->refreshToken($this->token['refresh_token']);
[243] Fix | Delete
}
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
$this->client->getLogger()->debug('OAuth2 authentication');
[247] Fix | Delete
[248] Fix | Delete
// Add the OAuth2 header to the request
[249] Fix | Delete
$request->setRequestHeaders(
[250] Fix | Delete
array('Authorization' => 'Bearer ' . $this->token['access_token'])
[251] Fix | Delete
);
[252] Fix | Delete
[253] Fix | Delete
return $request;
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
/**
[257] Fix | Delete
* Fetches a fresh access token with the given refresh token.
[258] Fix | Delete
* @param string $refreshToken
[259] Fix | Delete
* @return void
[260] Fix | Delete
*/
[261] Fix | Delete
public function refreshToken($refreshToken)
[262] Fix | Delete
{
[263] Fix | Delete
$this->refreshTokenRequest(
[264] Fix | Delete
array(
[265] Fix | Delete
'client_id' => $this->client->getClassConfig($this, 'client_id'),
[266] Fix | Delete
'client_secret' => $this->client->getClassConfig($this, 'client_secret'),
[267] Fix | Delete
'refresh_token' => $refreshToken,
[268] Fix | Delete
'grant_type' => 'refresh_token'
[269] Fix | Delete
)
[270] Fix | Delete
);
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
/**
[274] Fix | Delete
* Fetches a fresh access token with a given assertion token.
[275] Fix | Delete
* @param Google_Auth_AssertionCredentials $assertionCredentials optional.
[276] Fix | Delete
* @return void
[277] Fix | Delete
*/
[278] Fix | Delete
public function refreshTokenWithAssertion($assertionCredentials = null)
[279] Fix | Delete
{
[280] Fix | Delete
if (!$assertionCredentials) {
[281] Fix | Delete
$assertionCredentials = $this->assertionCredentials;
[282] Fix | Delete
}
[283] Fix | Delete
[284] Fix | Delete
$cacheKey = $assertionCredentials->getCacheKey();
[285] Fix | Delete
[286] Fix | Delete
if ($cacheKey) {
[287] Fix | Delete
// We can check whether we have a token available in the
[288] Fix | Delete
// cache. If it is expired, we can retrieve a new one from
[289] Fix | Delete
// the assertion.
[290] Fix | Delete
$token = $this->client->getCache()->get($cacheKey);
[291] Fix | Delete
if ($token) {
[292] Fix | Delete
$this->setAccessToken($token);
[293] Fix | Delete
}
[294] Fix | Delete
if (!$this->isAccessTokenExpired()) {
[295] Fix | Delete
return;
[296] Fix | Delete
}
[297] Fix | Delete
}
[298] Fix | Delete
[299] Fix | Delete
$this->client->getLogger()->debug('OAuth2 access token expired');
[300] Fix | Delete
$this->refreshTokenRequest(
[301] Fix | Delete
array(
[302] Fix | Delete
'grant_type' => 'assertion',
[303] Fix | Delete
'assertion_type' => $assertionCredentials->assertionType,
[304] Fix | Delete
'assertion' => $assertionCredentials->generateAssertion(),
[305] Fix | Delete
)
[306] Fix | Delete
);
[307] Fix | Delete
[308] Fix | Delete
if ($cacheKey) {
[309] Fix | Delete
// Attempt to cache the token.
[310] Fix | Delete
$this->client->getCache()->set(
[311] Fix | Delete
$cacheKey,
[312] Fix | Delete
$this->getAccessToken()
[313] Fix | Delete
);
[314] Fix | Delete
}
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
private function refreshTokenRequest($params)
[318] Fix | Delete
{
[319] Fix | Delete
if (isset($params['assertion'])) {
[320] Fix | Delete
$this->client->getLogger()->info(
[321] Fix | Delete
'OAuth2 access token refresh with Signed JWT assertion grants.'
[322] Fix | Delete
);
[323] Fix | Delete
} else {
[324] Fix | Delete
$this->client->getLogger()->info('OAuth2 access token refresh');
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
$http = new UDP_Google_Http_Request(
[328] Fix | Delete
self::OAUTH2_TOKEN_URI,
[329] Fix | Delete
'POST',
[330] Fix | Delete
array(),
[331] Fix | Delete
$params
[332] Fix | Delete
);
[333] Fix | Delete
$http->disableGzip();
[334] Fix | Delete
$request = $this->client->getIo()->makeRequest($http);
[335] Fix | Delete
[336] Fix | Delete
$code = $request->getResponseHttpCode();
[337] Fix | Delete
$body = $request->getResponseBody();
[338] Fix | Delete
if (200 == $code) {
[339] Fix | Delete
$token = json_decode($body, true);
[340] Fix | Delete
if ($token == null) {
[341] Fix | Delete
throw new Google_Auth_Exception("Could not json decode the access token");
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
if (! isset($token['access_token']) || ! isset($token['expires_in'])) {
[345] Fix | Delete
throw new Google_Auth_Exception("Invalid token format");
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
if (isset($token['id_token'])) {
[349] Fix | Delete
$this->token['id_token'] = $token['id_token'];
[350] Fix | Delete
}
[351] Fix | Delete
$this->token['access_token'] = $token['access_token'];
[352] Fix | Delete
$this->token['expires_in'] = $token['expires_in'];
[353] Fix | Delete
$this->token['created'] = time();
[354] Fix | Delete
} else {
[355] Fix | Delete
throw new Google_Auth_Exception("Error refreshing the OAuth2 token, message: '$body'", $code);
[356] Fix | Delete
}
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
/**
[360] Fix | Delete
* Revoke an OAuth2 access token or refresh token. This method will revoke the current access
[361] Fix | Delete
* token, if a token isn't provided.
[362] Fix | Delete
* @throws Google_Auth_Exception
[363] Fix | Delete
* @param string|null $token The token (access token or a refresh token) that should be revoked.
[364] Fix | Delete
* @return boolean Returns True if the revocation was successful, otherwise False.
[365] Fix | Delete
*/
[366] Fix | Delete
public function revokeToken($token = null)
[367] Fix | Delete
{
[368] Fix | Delete
if (!$token) {
[369] Fix | Delete
if (!$this->token) {
[370] Fix | Delete
// Not initialized, no token to actually revoke
[371] Fix | Delete
return false;
[372] Fix | Delete
} elseif (array_key_exists('refresh_token', $this->token)) {
[373] Fix | Delete
$token = $this->token['refresh_token'];
[374] Fix | Delete
} else {
[375] Fix | Delete
$token = $this->token['access_token'];
[376] Fix | Delete
}
[377] Fix | Delete
}
[378] Fix | Delete
$request = new UDP_Google_Http_Request(
[379] Fix | Delete
self::OAUTH2_REVOKE_URI,
[380] Fix | Delete
'POST',
[381] Fix | Delete
array(),
[382] Fix | Delete
"token=$token"
[383] Fix | Delete
);
[384] Fix | Delete
$request->disableGzip();
[385] Fix | Delete
$response = $this->client->getIo()->makeRequest($request);
[386] Fix | Delete
$code = $response->getResponseHttpCode();
[387] Fix | Delete
if ($code == 200) {
[388] Fix | Delete
$this->token = null;
[389] Fix | Delete
return true;
[390] Fix | Delete
}
[391] Fix | Delete
[392] Fix | Delete
return false;
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
/**
[396] Fix | Delete
* Returns if the access_token is expired.
[397] Fix | Delete
* @return bool Returns True if the access_token is expired.
[398] Fix | Delete
*/
[399] Fix | Delete
public function isAccessTokenExpired()
[400] Fix | Delete
{
[401] Fix | Delete
if (!$this->token || !isset($this->token['created'])) {
[402] Fix | Delete
return true;
[403] Fix | Delete
}
[404] Fix | Delete
[405] Fix | Delete
// If the token is set to expire in the next 30 seconds.
[406] Fix | Delete
$expired = ($this->token['created']
[407] Fix | Delete
+ ($this->token['expires_in'] - 30)) < time();
[408] Fix | Delete
[409] Fix | Delete
return $expired;
[410] Fix | Delete
}
[411] Fix | Delete
[412] Fix | Delete
// Gets federated sign-on certificates to use for verifying identity tokens.
[413] Fix | Delete
// Returns certs as array structure, where keys are key ids, and values
[414] Fix | Delete
// are PEM encoded certificates.
[415] Fix | Delete
private function getFederatedSignOnCerts()
[416] Fix | Delete
{
[417] Fix | Delete
return $this->retrieveCertsFromLocation(
[418] Fix | Delete
$this->client->getClassConfig($this, 'federated_signon_certs_url')
[419] Fix | Delete
);
[420] Fix | Delete
}
[421] Fix | Delete
[422] Fix | Delete
/**
[423] Fix | Delete
* Retrieve and cache a certificates file.
[424] Fix | Delete
*
[425] Fix | Delete
* @param $url string location
[426] Fix | Delete
* @throws Google_Auth_Exception
[427] Fix | Delete
* @return array certificates
[428] Fix | Delete
*/
[429] Fix | Delete
public function retrieveCertsFromLocation($url)
[430] Fix | Delete
{
[431] Fix | Delete
// If we're retrieving a local file, just grab it.
[432] Fix | Delete
if ("http" != substr($url, 0, 4)) {
[433] Fix | Delete
$file = file_get_contents($url);
[434] Fix | Delete
if ($file) {
[435] Fix | Delete
return json_decode($file, true);
[436] Fix | Delete
} else {
[437] Fix | Delete
throw new Google_Auth_Exception(
[438] Fix | Delete
"Failed to retrieve verification certificates: '" .
[439] Fix | Delete
$url . "'."
[440] Fix | Delete
);
[441] Fix | Delete
}
[442] Fix | Delete
}
[443] Fix | Delete
[444] Fix | Delete
// This relies on makeRequest caching certificate responses.
[445] Fix | Delete
$request = $this->client->getIo()->makeRequest(
[446] Fix | Delete
new UDP_Google_Http_Request(
[447] Fix | Delete
$url
[448] Fix | Delete
)
[449] Fix | Delete
);
[450] Fix | Delete
if ($request->getResponseHttpCode() == 200) {
[451] Fix | Delete
$certs = json_decode($request->getResponseBody(), true);
[452] Fix | Delete
if ($certs) {
[453] Fix | Delete
return $certs;
[454] Fix | Delete
}
[455] Fix | Delete
}
[456] Fix | Delete
throw new Google_Auth_Exception(
[457] Fix | Delete
"Failed to retrieve verification certificates: '" .
[458] Fix | Delete
$request->getResponseBody() . "'.",
[459] Fix | Delete
$request->getResponseHttpCode()
[460] Fix | Delete
);
[461] Fix | Delete
}
[462] Fix | Delete
[463] Fix | Delete
/**
[464] Fix | Delete
* Verifies an id token and returns the authenticated apiLoginTicket.
[465] Fix | Delete
* Throws an exception if the id token is not valid.
[466] Fix | Delete
* The audience parameter can be used to control which id tokens are
[467] Fix | Delete
* accepted. By default, the id token must have been issued to this OAuth2 client.
[468] Fix | Delete
*
[469] Fix | Delete
* @param $id_token
[470] Fix | Delete
* @param $audience
[471] Fix | Delete
* @return Google_Auth_LoginTicket
[472] Fix | Delete
*/
[473] Fix | Delete
public function verifyIdToken($id_token = null, $audience = null)
[474] Fix | Delete
{
[475] Fix | Delete
if (!$id_token) {
[476] Fix | Delete
$id_token = $this->token['id_token'];
[477] Fix | Delete
}
[478] Fix | Delete
$certs = $this->getFederatedSignonCerts();
[479] Fix | Delete
if (!$audience) {
[480] Fix | Delete
$audience = $this->client->getClassConfig($this, 'client_id');
[481] Fix | Delete
}
[482] Fix | Delete
[483] Fix | Delete
return $this->verifySignedJwtWithCerts($id_token, $certs, $audience, self::OAUTH2_ISSUER);
[484] Fix | Delete
}
[485] Fix | Delete
[486] Fix | Delete
/**
[487] Fix | Delete
* Verifies the id token, returns the verified token contents.
[488] Fix | Delete
*
[489] Fix | Delete
* @param $jwt string the token
[490] Fix | Delete
* @param $certs array of certificates
[491] Fix | Delete
* @param $required_audience string the expected consumer of the token
[492] Fix | Delete
* @param [$issuer] the expected issues, defaults to Google
[493] Fix | Delete
* @param [$max_expiry] the max lifetime of a token, defaults to MAX_TOKEN_LIFETIME_SECS
[494] Fix | Delete
* @throws Google_Auth_Exception
[495] Fix | Delete
* @return mixed token information if valid, false if not
[496] Fix | Delete
*/
[497] Fix | Delete
public function verifySignedJwtWithCerts(
[498] Fix | Delete
$jwt,
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function