PHRAS-1751_GOOGLE-AUTH_master (#2384)

* PHRAS-1751_GOOGLE-AUTH_master
replace lib "alchemy/google-plus-api-client" by "google/apiclient"
had to downgrade facebook/php-sdk from 4 (does not exists ?) to 3 (abandoned anyway) to allow composer update.
see PHRAS-1752

* PHRAS-1751_GOOGLE-AUTH_master
revert composer.lock, only remove & update new google-sdk (composer full update make tests boot to fail. to see later)

* PHRAS-1751_GOOGLE-AUTH_master
fix unit test
This commit is contained in:
jygaulier
2017-11-30 10:45:56 +01:00
committed by GitHub
parent be811e8876
commit 8117d1ebc0
4 changed files with 583 additions and 119 deletions

View File

@@ -37,7 +37,6 @@
"alchemy-fr/tcpdf-clone": "~6.0", "alchemy-fr/tcpdf-clone": "~6.0",
"alchemy/embed-bundle": "^0.3.4", "alchemy/embed-bundle": "^0.3.4",
"alchemy/geonames-api-consumer": "~0.1.0", "alchemy/geonames-api-consumer": "~0.1.0",
"alchemy/google-plus-api-client": "~0.6.2",
"alchemy/mediavorus": "^0.4.4", "alchemy/mediavorus": "^0.4.4",
"alchemy/oauth2php": "1.0.0", "alchemy/oauth2php": "1.0.0",
"alchemy/phlickr": "0.2.9", "alchemy/phlickr": "0.2.9",
@@ -60,6 +59,7 @@
"firebase/php-jwt": "^3.0.0", "firebase/php-jwt": "^3.0.0",
"gedmo/doctrine-extensions": "~2.3.0", "gedmo/doctrine-extensions": "~2.3.0",
"goodby/csv": "^1.3.0", "goodby/csv": "^1.3.0",
"google/apiclient": "^2.0",
"guzzle/guzzle": "~3.0", "guzzle/guzzle": "~3.0",
"hoa/compiler": "~2.0", "hoa/compiler": "~2.0",
"hoa/console": "~2.0", "hoa/console": "~2.0",

551
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "2bd86f1f6bf73095e1d7aad61ee5dfd2", "content-hash": "1941059783baff5d381594756191e00a",
"packages": [ "packages": [
{ {
"name": "alchemy-fr/tcpdf-clone", "name": "alchemy-fr/tcpdf-clone",
@@ -273,44 +273,6 @@
], ],
"time": "2013-06-25T09:12:58+00:00" "time": "2013-06-25T09:12:58+00:00"
}, },
{
"name": "alchemy/google-plus-api-client",
"version": "0.6.6",
"source": {
"type": "git",
"url": "https://github.com/alchemy-fr/google-plus-api-client.git",
"reference": "d375b00e963984744b8a91bde2c8b87b3ee7d6f1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/alchemy-fr/google-plus-api-client/zipball/d375b00e963984744b8a91bde2c8b87b3ee7d6f1",
"reference": "d375b00e963984744b8a91bde2c8b87b3ee7d6f1",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Google",
"email": "noreply@google.com",
"homepage": "http://www.google.com/"
}
],
"description": "PHP Client for Google APIs",
"homepage": "https://code.google.com/p/google-api-php-client/",
"time": "2016-07-06T13:47:16+00:00"
},
{ {
"name": "alchemy/mediavorus", "name": "alchemy/mediavorus",
"version": "0.4.5", "version": "0.4.5",
@@ -2259,6 +2221,147 @@
], ],
"time": "2015-06-29T10:28:19+00:00" "time": "2015-06-29T10:28:19+00:00"
}, },
{
"name": "google/apiclient",
"version": "v2.2.1",
"source": {
"type": "git",
"url": "https://github.com/google/google-api-php-client.git",
"reference": "b69b8ac4bf6501793c389d4e013a79d09c85c5f2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/google/google-api-php-client/zipball/b69b8ac4bf6501793c389d4e013a79d09c85c5f2",
"reference": "b69b8ac4bf6501793c389d4e013a79d09c85c5f2",
"shasum": ""
},
"require": {
"firebase/php-jwt": "~2.0|~3.0|~4.0|~5.0",
"google/apiclient-services": "~0.13",
"google/auth": "^1.0",
"guzzlehttp/guzzle": "~5.3.1|~6.0",
"guzzlehttp/psr7": "^1.2",
"monolog/monolog": "^1.17",
"php": ">=5.4",
"phpseclib/phpseclib": "~0.3.10|~2.0"
},
"require-dev": {
"cache/filesystem-adapter": "^0.3.2",
"phpunit/phpunit": "~4",
"squizlabs/php_codesniffer": "~2.3",
"symfony/css-selector": "~2.1",
"symfony/dom-crawler": "~2.1"
},
"suggest": {
"cache/filesystem-adapter": "For caching certs and tokens (using Google_Client::setCache)"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
},
"autoload": {
"psr-0": {
"Google_": "src/"
},
"classmap": [
"src/Google/Service/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "Client library for Google APIs",
"homepage": "http://developers.google.com/api-client-library/php",
"keywords": [
"google"
],
"time": "2017-11-03T01:19:53+00:00"
},
{
"name": "google/apiclient-services",
"version": "v0.36",
"source": {
"type": "git",
"url": "https://github.com/google/google-api-php-client-services.git",
"reference": "2fd7d2876fbc0174faddba3241956a1393536159"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/google/google-api-php-client-services/zipball/2fd7d2876fbc0174faddba3241956a1393536159",
"reference": "2fd7d2876fbc0174faddba3241956a1393536159",
"shasum": ""
},
"require": {
"php": ">=5.4"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
},
"type": "library",
"autoload": {
"psr-0": {
"Google_Service_": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "Client library for Google APIs",
"homepage": "http://developers.google.com/api-client-library/php",
"keywords": [
"google"
],
"time": "2017-11-25T00:23:12+00:00"
},
{
"name": "google/auth",
"version": "v1.1.0",
"source": {
"type": "git",
"url": "https://github.com/google/google-auth-library-php.git",
"reference": "548d27d670f0236dc5258fa4cdde6e7b63464cfd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/google/google-auth-library-php/zipball/548d27d670f0236dc5258fa4cdde6e7b63464cfd",
"reference": "548d27d670f0236dc5258fa4cdde6e7b63464cfd",
"shasum": ""
},
"require": {
"firebase/php-jwt": "~2.0|~3.0|~4.0|~5.0",
"guzzlehttp/guzzle": "~5.3.1|~6.0",
"guzzlehttp/psr7": "~1.2",
"php": ">=5.4",
"psr/cache": "^1.0",
"psr/http-message": "^1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^1.11",
"phpunit/phpunit": "3.7.*"
},
"type": "library",
"autoload": {
"psr-4": {
"Google\\Auth\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "Google Auth Library for PHP",
"homepage": "http://github.com/google/google-auth-library-php",
"keywords": [
"Authentication",
"google",
"oauth2"
],
"time": "2017-10-10T17:01:45+00:00"
},
{ {
"name": "guzzle/guzzle", "name": "guzzle/guzzle",
"version": "v3.9.3", "version": "v3.9.3",
@@ -2355,6 +2458,187 @@
"abandoned": "guzzlehttp/guzzle", "abandoned": "guzzlehttp/guzzle",
"time": "2015-03-18T18:23:50+00:00" "time": "2015-03-18T18:23:50+00:00"
}, },
{
"name": "guzzlehttp/guzzle",
"version": "6.3.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/f4db5a78a5ea468d4831de7f0bf9d9415e348699",
"reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699",
"shasum": ""
},
"require": {
"guzzlehttp/promises": "^1.0",
"guzzlehttp/psr7": "^1.4",
"php": ">=5.5"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "^4.0 || ^5.0",
"psr/log": "^1.0"
},
"suggest": {
"psr/log": "Required for using the Log middleware"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "6.2-dev"
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"time": "2017-06-22T18:50:49+00:00"
},
{
"name": "guzzlehttp/promises",
"version": "v1.3.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"time": "2016-12-20T10:07:11+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "1.4.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Schultze",
"homepage": "https://github.com/Tobion"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"request",
"response",
"stream",
"uri",
"url"
],
"time": "2017-03-20T17:10:46+00:00"
},
{ {
"name": "guzzlehttp/ringphp", "name": "guzzlehttp/ringphp",
"version": "1.1.0", "version": "1.1.0",
@@ -2673,6 +2957,7 @@
"parameter", "parameter",
"protocol" "protocol"
], ],
"abandoned": "hoa/consistency",
"time": "2015-11-09T06:51:06+00:00" "time": "2015-11-09T06:51:06+00:00"
}, },
{ {
@@ -4949,6 +5234,98 @@
], ],
"time": "2015-07-25T16:39:46+00:00" "time": "2015-07-25T16:39:46+00:00"
}, },
{
"name": "phpseclib/phpseclib",
"version": "2.0.7",
"source": {
"type": "git",
"url": "https://github.com/phpseclib/phpseclib.git",
"reference": "f4b6a522dfa1fd1e477c9cfe5909d5b31f098c0b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/f4b6a522dfa1fd1e477c9cfe5909d5b31f098c0b",
"reference": "f4b6a522dfa1fd1e477c9cfe5909d5b31f098c0b",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phing/phing": "~2.7",
"phpunit/phpunit": "~4.0",
"sami/sami": "~2.0",
"squizlabs/php_codesniffer": "~2.0"
},
"suggest": {
"ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.",
"ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
"ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations."
},
"type": "library",
"autoload": {
"files": [
"phpseclib/bootstrap.php"
],
"psr-4": {
"phpseclib\\": "phpseclib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jim Wigginton",
"email": "terrafrost@php.net",
"role": "Lead Developer"
},
{
"name": "Patrick Monnerat",
"email": "pm@datasphere.ch",
"role": "Developer"
},
{
"name": "Andreas Fischer",
"email": "bantu@phpbb.com",
"role": "Developer"
},
{
"name": "Hans-Jürgen Petrich",
"email": "petrich@tronic-media.com",
"role": "Developer"
},
{
"name": "Graham Campbell",
"email": "graham@alt-three.com",
"role": "Developer"
}
],
"description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.",
"homepage": "http://phpseclib.sourceforge.net",
"keywords": [
"BigInteger",
"aes",
"asn.1",
"asn1",
"blowfish",
"crypto",
"cryptography",
"encryption",
"rsa",
"security",
"sftp",
"signature",
"signing",
"ssh",
"twofish",
"x.509",
"x509"
],
"time": "2017-10-23T05:04:54+00:00"
},
{ {
"name": "pimple/pimple", "name": "pimple/pimple",
"version": "v1.1.1", "version": "v1.1.1",
@@ -4995,6 +5372,102 @@
], ],
"time": "2013-11-22T08:30:29+00:00" "time": "2013-11-22T08:30:29+00:00"
}, },
{
"name": "psr/cache",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8",
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Cache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for caching libraries",
"keywords": [
"cache",
"psr",
"psr-6"
],
"time": "2016-08-06T20:24:11+00:00"
},
{
"name": "psr/http-message",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"time": "2016-08-06T14:39:51+00:00"
},
{ {
"name": "psr/log", "name": "psr/log",
"version": "1.0.2", "version": "1.0.2",

View File

@@ -27,7 +27,6 @@ class GooglePlus extends AbstractProvider
{ {
private $client; private $client;
private $guzzle; private $guzzle;
private $plus;
public function __construct(UrlGenerator $generator, SessionInterface $session, \Google_Client $google, ClientInterface $guzzle) public function __construct(UrlGenerator $generator, SessionInterface $session, \Google_Client $google, ClientInterface $guzzle)
{ {
@@ -36,18 +35,17 @@ class GooglePlus extends AbstractProvider
$this->client = $google; $this->client = $google;
$this->guzzle = $guzzle; $this->guzzle = $guzzle;
$this->plus = new \Google_PlusService($this->client);
$this->client->setScopes([ $this->client->setScopes([
'https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/plus.me',
'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
]); ]);
$this->client->setRedirectUri( $this->client->setRedirectUri(
$this->generator->generate( $this->generator->generate(
'login_authentication_provider_callback', [ 'login_authentication_provider_callback', [
'providerId' => $this->getId(), 'providerId' => $this->getId(),
], UrlGenerator::ABSOLUTE_URL ], UrlGenerator::ABSOLUTE_URL
) )
); );
@@ -98,26 +96,6 @@ class GooglePlus extends AbstractProvider
return $this->client; return $this->client;
} }
/**
* @param \Google_PlusService $plus
*
* @return GooglePlus
*/
public function setGooglePlusService(\Google_PlusService $plus)
{
$this->plus = $plus;
return $this;
}
/**
* @return \Google_PlusService
*/
public function getGooglePlusService()
{
return $this->plus;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@@ -173,21 +151,22 @@ class GooglePlus extends AbstractProvider
} }
try { try {
$this->client->authenticate($request->query->get('code')); $this->client->fetchAccessTokenWithAuthCode($request->query->get('code'));
$token = @json_decode($this->client->getAccessToken(), true); $token = @json_decode($this->client->getAccessToken(), true);
if (JSON_ERROR_NONE !== json_last_error()) { if (JSON_ERROR_NONE !== json_last_error()) {
throw new NotAuthenticatedException('Unable to parse Google+ JSON'); throw new NotAuthenticatedException('Unable to parse Google+ JSON', json_last_error());
} }
$ticket = $this->client->verifyIdToken($token['id_token']); $ticket = $this->client->verifyIdToken($token['id_token']);
} catch (\Google_Exception $e) { }
catch (\Google_Exception $e) {
throw new NotAuthenticatedException('Unable to authenticate through Google+', $e->getCode(), $e); throw new NotAuthenticatedException('Unable to authenticate through Google+', $e->getCode(), $e);
} }
$this->session->set('google-plus.provider.token', json_encode($token)); $this->session->set('google-plus.provider.token', $this->client->getAccessToken());
$this->session->set('google-plus.provider.id', $ticket->getUserId()); $this->session->set('google-plus.provider.id', $ticket['sub']);
} }
/** /**
@@ -209,45 +188,40 @@ class GooglePlus extends AbstractProvider
{ {
$identity = new Identity(); $identity = new Identity();
$token = @json_decode($this->session->get('google-plus.provider.token'), true); $accessToken = $this->client->getAccessToken();
$token = @json_decode($accessToken, true);
if (JSON_ERROR_NONE !== json_last_error()) { if (JSON_ERROR_NONE !== json_last_error()) {
throw new NotAuthenticatedException('Unable to parse Google+ JSON'); throw new NotAuthenticatedException('Unable to parse Google+ JSON');
} }
try { try {
$request = $this->guzzle->get(sprintf( if(is_array($ticket = $this->client->verifyIdToken($token['id_token']))){
'https://www.googleapis.com/oauth2/v1/tokeninfo?%s', $mapping = [
http_build_query(['access_token' => $token['access_token']], '', '&') 'email' => Identity::PROPERTY_EMAIL,
)); 'given_name' => Identity::PROPERTY_FIRSTNAME,
$response = $request->send(); 'family_name' => Identity::PROPERTY_LASTNAME,
} catch (GuzzleException $e) { 'picture' => Identity::PROPERTY_IMAGEURL,
throw new NotAuthenticatedException('Unable to retrieve Google+ tokeninfo', $e->getCode(), $e); 'sub' => Identity::PROPERTY_ID
];
foreach ($mapping as $src => $dest) {
if (array_key_exists($src, $ticket)) {
$identity->set($dest, $ticket[$src]);
}
}
}
else {
throw new NotAuthenticatedException('Google + has not authenticated');
}
}
catch (\Google_Exception $e) {
throw new NotAuthenticatedException('Google + has not authenticated');
} }
if (200 !== $response->getStatusCode()) { if(!$identity->has(Identity::PROPERTY_ID)) {
throw new NotAuthenticatedException('Error while retrieving user info'); throw new NotAuthenticatedException('Google + has not authenticated');
} }
try {
$plusData = $this->plus->people->get('me');
} catch (\Google_Exception $e) {
throw new NotAuthenticatedException('Error while retrieving user info', $e->getCode(), $e);
}
$data = @json_decode($response->getBody(true), true);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new NotAuthenticatedException('Unable to parse Google+ JSON');
}
$identity->set(Identity::PROPERTY_EMAIL, $data['email']);
$identity->set(Identity::PROPERTY_FIRSTNAME, $plusData['name']['givenName']);
$identity->set(Identity::PROPERTY_ID, $plusData['id']);
$identity->set(Identity::PROPERTY_IMAGEURL, $plusData['image']['url']);
$identity->set(Identity::PROPERTY_LASTNAME, $plusData['name']['familyName']);
return $identity; return $identity;
} }
@@ -351,3 +325,4 @@ class GooglePlus extends AbstractProvider
return new GooglePlus($generator, $session, $client, new Guzzle()); return new GooglePlus($generator, $session, $client, new Guzzle());
} }
} }

View File

@@ -125,7 +125,6 @@ class GooglePlusTest extends ProviderTestCase
protected function getProviderForSuccessIdentity() protected function getProviderForSuccessIdentity()
{ {
$this->markTestIncomplete('Incomplete flow for google plus API check');
$provider = $this->getProvider(); $provider = $this->getProvider();
$guzzle = $this->getMock('Guzzle\Http\ClientInterface'); $guzzle = $this->getMock('Guzzle\Http\ClientInterface');
@@ -166,24 +165,46 @@ class GooglePlusTest extends ProviderTestCase
$provider->setGuzzleClient($guzzle); $provider->setGuzzleClient($guzzle);
$provider->getSession()->set('google-plus.provider.id', '12345678'); $provider->getSession()->set('google-plus.provider.id', '12345678');
$people = $this->getMockBuilder('Google_PeopleServiceResource') $googleClient = $this->getMockBuilder('\Google_Client')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$people->expects($this->once()) $googleClient->expects($this->any())
->method('get') ->method("getAccessToken")
->will($this->returnValue([ ->will($this->returnValue(
'name' => [ json_encode([
'givenName' => self::FIRSTNAME, 'access_token' => 'fakeAccessToken',
'familyName' => self::LASTNAME, 'expires_in' => 3599,
], 'id_token' => 'fakeIdToken',
'id' => self::ID, 'token_type' => 'Bearer',
'image' => [ 'created' => 1511374176,
'url' => self::IMAGEURL ])
] ));
]));
$provider->getGooglePlusService()->people = $people; $googleClient->expects($this->any())
->method("verifyIdToken")
->with($this->equalTo("fakeIdToken"))
->will($this->returnValue(
[
'azp' => '1234azerty.apps.googleusercontent.com',
'aud' => '1234azerty.apps.googleusercontent.com',
'sub' => self::ID,
'hd' => 'somewhere.fr',
'email' => self::EMAIL,
'email_verified' => true,
'at_hash' => '123456789',
'iss' => 'https://accounts.google.com',
'iat' => 1511522056,
'exp' => 1511525656,
'name' => self::FIRSTNAME . ' ' . self::LASTNAME,
'picture' => self::IMAGEURL,
'given_name' => self::FIRSTNAME,
'family_name' => self::LASTNAME,
'locale' => 'fr',
]
));
$provider->setGoogleClient($googleClient);
return $provider; return $provider;
} }
@@ -256,12 +277,7 @@ class GooglePlusTest extends ProviderTestCase
->method('createAuthUrl') ->method('createAuthUrl')
->will($this->returnValue('https://www.google.com/auth')); ->will($this->returnValue('https://www.google.com/auth'));
$plus = $this->getMockBuilder('Google_PlusService')
->disableOriginalConstructor()
->getMock();
$google = new GooglePlus($this->getUrlGeneratorMock(), $this->getMockSession(), $googleMock, $this->getGuzzleMock()); $google = new GooglePlus($this->getUrlGeneratorMock(), $this->getMockSession(), $googleMock, $this->getGuzzleMock());
$google->setGooglePlusService($plus);
return $google; return $google;
} }