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
@@ -0,0 +1,78 @@
<?php
use Mockery as M;
use SocialNorm\Facebook\FacebookProvider;
use SocialNorm\Request;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Client as HttpClient;
class FacebookProviderTest 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/facebook_accesstoken.php',
__DIR__ . '/_fixtures/facebook_user.php',
]);
$provider = new FacebookProvider([
'client_id' => 'abcdefgh',
'client_secret' => '12345678',
'redirect_uri' => 'http://example.com/login',
], $client, new Request(['code' => 'abc123']));
$user = $provider->getUser();
$this->assertEquals('187903669', $user->id);
$this->assertEquals('John Doe', $user->nickname);
$this->assertEquals('John Doe', $user->full_name);
$this->assertEquals('john@example.com', $user->email);
$this->assertEquals('https://graph.facebook.com/v2.4/187903669/picture', $user->avatar);
$this->assertEquals(
'RUXRIAxWwxVYKk3b1vrTACPUiAGImrszVsBXb2FQZZZXbd6JNzkZRAgZLCdAiCfKHrPanMTS8BAHLPqugidBcCNkUmz3y72XMZRZWw4SEGdczB2HygsA7oQOufDIbgZBtyA1KaznugApacfId5HIdZtIEh47ZLEa0BrJrBICZBf4uCWCGD5OBM40RpvTVaAux2vCv5wU9ZZzm91WAVtSC5ufoZmr3Ty',
$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/facebook_accesstoken.php',
__DIR__ . '/_fixtures/facebook_user.php',
]);
$provider = new FacebookProvider([
'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,19 @@
<?php
return [
'status' => 200,
'headers' => [
'Content-Type' => 'application/json; charset=UTF-8',
'Access-Control-Allow-Origin' => '*',
'X-FB-Rev' => '1669049',
'Pragma' => 'no-cache',
'Cache-Control' => 'private, no-cache, no-store, must-revalidate',
'Facebook-API-Version' => 'v2.3',
'Expires' => 'Sat, 01 Jan 2000 00:00:00 GMT',
'X-FB-Debug' => 'aWKI40XqPBE1YkeMX7Awln6RzgWl+JQpbYY7MWkiP2cRZ0TNadSG8rTnlHQovxjP+5fTYg1ZfkOVKsiMdJB9Jg==',
'Date' => 'Wed, 01 Apr 2015 12:47:40 GMT',
'Connection' => 'keep-alive',
'Content-Length' => '285'
],
'body' => '{"access_token":"RUXRIAxWwxVYKk3b1vrTACPUiAGImrszVsBXb2FQZZZXbd6JNzkZRAgZLCdAiCfKHrPanMTS8BAHLPqugidBcCNkUmz3y72XMZRZWw4SEGdczB2HygsA7oQOufDIbgZBtyA1KaznugApacfId5HIdZtIEh47ZLEa0BrJrBICZBf4uCWCGD5OBM40RpvTVaAux2vCv5wU9ZZzm91WAVtSC5ufoZmr3Ty","token_type":"bearer","expires_in":5183288}'
];
@@ -0,0 +1,21 @@
<?php
return [
'status' => 200,
'headers' => [
'Content-Type' => 'text/javascript; charset=UTF-8',
'Last-Modified' => '2014-12-21T00:04:42+0000',
'Access-Control-Allow-Origin' => '*',
'X-FB-Rev' => '1669049',
'ETag' => '"e732c03dd9c5d6f0a2aa6bb7b2e78e4e36bf5a4e"',
'Pragma' => 'no-cache',
'Cache-Control' => 'private, no-cache, no-store, must-revalidate',
'Facebook-API-Version' => 'v2.3',
'Expires' => 'Sat, 01 Jan 2000 00:00:00 GMT',
'X-FB-Debug' => 'WkWb9eeV7Aw1YJagx9Ffj0XzEQuDZhaUlOsNLGbf+es8H5Tq2aW4iBn6G0tUh1WRTG4Rbd+nIaTTR1Mbhz2b8Q==',
'Date' => 'Wed, 01 Apr 2015 12:49:00 GMT',
'Connection' => 'keep-alive',
'Content-Length' => '295'
],
'body' => '{"id":"187903669","birthday":"03\/15\/1987","email":"john\u0040example.com","first_name":"John","gender":"male","last_name":"Doe","link":"http:\/\/www.facebook.com\/187903669","locale":"en_US","name":"John Doe","timezone":-4,"updated_time":"2014-12-21T00:04:42+0000","verified":true}'
];