added socialite and some hacks via vendor sideload to add social login

This commit is contained in:
2018-07-08 23:59:32 +02:00
parent d1fa087121
commit 6e2040249b
123 changed files with 4356 additions and 6 deletions
+4
View File
@@ -0,0 +1,4 @@
/vendor
composer.phar
composer.lock
.DS_Store
+11
View File
@@ -0,0 +1,11 @@
language: php
php:
- 5.5
- 5.6
before_script:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev
script: phpunit
+30
View File
@@ -0,0 +1,30 @@
{
"name": "socialnorm/google",
"description": "Google provider for SocialNorm",
"authors": [
{
"name": "Adam Wathan",
"email": "adam.wathan@gmail.com"
}
],
"license": "MIT",
"require": {
"php": ">=5.5.0",
"guzzlehttp/guzzle": "^6.0",
"socialnorm/socialnorm": "^0.2"
},
"require-dev": {
"mockery/mockery": "~0.8",
"phpunit/phpunit": "^4.8"
},
"autoload": {
"psr-4": {
"SocialNorm\\Google\\": "src/"
}
},
"autoload-dev": {
"files": [
"tests/TestCase.php"
]
}
}
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
+3
View File
@@ -0,0 +1,3 @@
## SocialNorm Google Provider
@todo: Add docs :)
@@ -0,0 +1,78 @@
<?php namespace SocialNorm\Google;
use SocialNorm\Exceptions\InvalidAuthorizationCodeException;
use SocialNorm\Providers\OAuth2Provider;
class GoogleProvider extends OAuth2Provider
{
protected $authorizeUrl = "https://accounts.google.com/o/oauth2/auth";
protected $accessTokenUrl = "https://accounts.google.com/o/oauth2/token";
protected $userDataUrl = "https://www.googleapis.com/userinfo/v2/me";
protected $scope = [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email',
];
protected $headers = [
'authorize' => [],
'access_token' => [
'Content-Type' => 'application/x-www-form-urlencoded'
],
'user_details' => [],
];
protected function compileScopes()
{
return implode(' ', $this->scope);
}
protected function getAuthorizeUrl()
{
return $this->authorizeUrl;
}
protected function getAccessTokenBaseUrl()
{
return $this->accessTokenUrl;
}
protected function getUserDataUrl()
{
return $this->userDataUrl;
}
protected function parseTokenResponse($response)
{
return $this->parseJsonTokenResponse($response);
}
protected function parseUserDataResponse($response)
{
return json_decode($response, true);
}
protected function userId()
{
return $this->getProviderUserData('id');
}
protected function nickname()
{
return $this->getProviderUserData('email');
}
protected function fullName()
{
return $this->getProviderUserData('given_name') . ' ' . $this->getProviderUserData('family_name');
}
protected function avatar()
{
return $this->getProviderUserData('picture');
}
protected function email()
{
return $this->getProviderUserData('email');
}
}
@@ -0,0 +1,75 @@
<?php
use Mockery as M;
use SocialNorm\Google\GoogleProvider;
use SocialNorm\Request;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Client as HttpClient;
class GoogleProviderTest extends TestCase
{
private function getStubbedHttpClient($fixtures = [])
{
$mock = new MockHandler($this->createResponses($fixtures));
$handler = HandlerStack::create($mock);
return new HttpClient(['handler' => $handler]);
}
private function createResponses($fixtures)
{
$responses = [];
foreach ($fixtures as $fixture) {
$response = require $fixture;
$responses[] = new Response($response['status'], $response['headers'], $response['body']);
}
return $responses;
}
/** @test */
public function it_can_retrieve_a_normalized_user()
{
$client = $this->getStubbedHttpClient([
__DIR__ . '/_fixtures/google_accesstoken.php',
__DIR__ . '/_fixtures/google_user.php',
]);
$provider = new GoogleProvider([
'client_id' => 'abcdefgh',
'client_secret' => '12345678',
'redirect_uri' => 'http://example.com/login',
], $client, new Request(['code' => 'abc123']));
$user = $provider->getUser();
$this->assertEquals('103904294571447333816', $user->id);
$this->assertEquals('adam.wathan@example.com', $user->nickname);
$this->assertEquals('Adam Wathan', $user->full_name);
$this->assertEquals('adam.wathan@example.com', $user->email);
$this->assertEquals('https://lh3.googleusercontent.com/-w0_RpDnsIE4/AAAAAAAAAAI/AAAAAAAAAKM/NEiV3jig1HA/photo.jpg', $user->avatar);
$this->assertEquals('ya29.8xFOTYpQK48RgPH8KjQpSu9SrcANcOQx9JtRnEu52dNsXqai8VD4iY3nFzUBURWnAPeTPtPeIBNjIF', $user->access_token);
}
/**
* @test
* @expectedException SocialNorm\Exceptions\ApplicationRejectedException
*/
public function it_fails_to_retrieve_a_user_when_the_authorization_code_is_omitted()
{
$client = $this->getStubbedHttpClient([
__DIR__ . '/_fixtures/google_accesstoken.php',
__DIR__ . '/_fixtures/google_user.php',
]);
$provider = new GoogleProvider([
'client_id' => 'abcdefgh',
'client_secret' => '12345678',
'redirect_uri' => 'http://example.com/login',
], $client, new Request([]));
$user = $provider->getUser();
}
}
@@ -0,0 +1,12 @@
<?php
use Mockery as M;
class TestCase extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
M::close();
parent::tearDown();
}
}
@@ -0,0 +1,24 @@
<?php
return [
'status' => 200,
'headers' => [
'Content-Type' => 'application/json; charset=utf-8',
'Cache-Control' => 'no-cache, no-store, max-age=0, must-revalidate',
'Pragma' => 'no-cache',
'Expires' => 'Fri, 01 Jan 1990 00:00:00 GMT',
'Date' => 'Thu, 19 Mar 2015 13:14:56 GMT',
'Content-Disposition' => 'attachment; filename="json.txt"; filename*=UTF-8\'\'json.txt',
'X-Content-Type-Options' => 'nosniff',
'X-Frame-Options' => 'SAMEORIGIN',
'X-XSS-Protection' => '1; mode=block',
'Server' => 'GSE',
'Alternate-Protocol' => '443:quic,p=0.5',
'Accept-Ranges' => 'none',
'Vary' => 'Accept-Encoding',
'Transfer-Encoding' => 'chunked'
],
'body' => '{"access_token" :"ya29.8xFOTYpQK48RgPH8KjQpSu9SrcANcOQx9JtRnEu52dNsXqai8VD4iY3nFzUBURWnAPeTPtPeIBNjIF","token_type" :"Bearer","expires_in" :3600,"id_token" :"6XFIidpthpu8iFNhyo5xjcGa9bUdiTL1zKnZz2dN-35IFzlCJ_IcmHYcA1i03iA5YVMOM1nLGiAbRaLTaMoWM5X_j0MyFBknwGMs3MM2WmdiIhdC7uNiXY2US8mWvCiVNwMnchpkJJUGIMbTNNPQd5_08XQvNi3TINiYOwZLxOIJ6X3pi9hNVY0dNNtUYwYdiNgwIW3ClRNNY1jiZxciXSckj18jb2jbSMMYujDKbw9ipMOIUxlnm5zIzEjNLV1BcMFMbjQWBnhjFUW4li-QTjcSnfj5iMdUIkjlGvkWcoLQ3pNNOwMhwjZFhdv0G3DTyT2nyOIR3eejckDXGWGw4l2Ni3izRwMYctNF1I_VstkDwn1idZoMOdR3b-zEO5C9ItMzl0TyNJjeb73VFrQIwXpHcTTQMgym2o3mijwJTn2ypu9NP0jjM1lcjd0Euh0OLJYxIYTIfbBC5WuCDcDMZxCbcz7oYLMl2yYDmI0akcuiVZyDO2I1aS2DAIUip.oTuI0HnAbtiA5y.Tnywh3VU0JTZ2Iu9OhJnYkvYmhzOm2AYbu5P9Q71UQObK2tLNcYQmBDmZGsQNIMwh1tQtl0sDTXj9WTVETuYAx4WK9hoOzcOVEY8iNHcl"}'
];
@@ -0,0 +1,23 @@
<?php
return [
'status' => 200,
'headers' => [
'Cache-Control' => 'no-cache, no-store, max-age=0, must-revalidate',
'Pragma' => 'no-cache',
'Expires' => 'Fri, 01 Jan 1990 00:00:00 GMT',
'Date' => 'Thu, 19 Mar 2015 13:15:29 GMT',
'Vary' => 'X-Origin, Origin,Accept-Encoding',
'Content-Type' => 'application/json; charset=UTF-8',
'X-Content-Type-Options' => 'nosniff',
'X-Frame-Options' => 'SAMEORIGIN',
'X-XSS-Protection' => '1; mode=block',
'Server' => 'GSE',
'Alternate-Protocol' => '443:quic,p=0.5',
'Accept-Ranges' => 'none',
'Transfer-Encoding' => 'chunked'
],
'body' => '{"id":"103904294571447333816","email":"adam.wathan@example.com","verified_email":true,"name":"Adam Wathan","given_name":"Adam","family_name":"Wathan","link":"https://plus.google.com/103904294571447333816","picture":"https://lh3.googleusercontent.com/-w0_RpDnsIE4/AAAAAAAAAAI/AAAAAAAAAKM/NEiV3jig1HA/photo.jpg","gender":"male","locale":"en"}'
];