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,77 @@
<?php
use Mockery as M;
use SocialNorm\GitHub\GitHubProvider;
use SocialNorm\Request;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Client as HttpClient;
class GitHubProviderTest 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/github_accesstoken.php',
__DIR__ . '/_fixtures/github_user.php',
__DIR__ . '/_fixtures/github_email.php',
]);
$provider = new GitHubProvider([
'client_id' => 'abcdefgh',
'client_secret' => '12345678',
'redirect_uri' => 'http://example.com/login',
], $client, new Request(['code' => 'abc123']));
$user = $provider->getUser();
$this->assertEquals('4323180', $user->id);
$this->assertEquals('adamwathan', $user->nickname);
$this->assertEquals('Adam Wathan', $user->full_name);
$this->assertEquals('adam@example.com', $user->email);
$this->assertEquals('https://avatars.githubusercontent.com/u/4323180?v=3', $user->avatar);
$this->assertEquals('abcdefgh12345678', $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/github_accesstoken.php',
__DIR__ . '/_fixtures/github_user.php',
__DIR__ . '/_fixtures/github_email.php',
]);
$provider = new GitHubProvider([
'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,27 @@
<?php
return [
'status' => 200,
'headers' => [
'Server' => 'GitHub.com',
'Date' => 'Sat, 21 Feb 2015 18:44:34 GMT',
'Content-Type' => 'application/json; charset=utf-8',
'Transfer-Encoding' => 'chunked',
'Status' => '200 OK',
'Content-Security-Policy' => 'default-src *; script-src assets-cdn.github.com collector-cdn.github.com; object-src assets-cdn.github.com; style-src \'self\' \'unsafe-inline\' \'unsafe-eval\' assets-cdn.github.com; img-src \'self\' data: assets-cdn.github.com identicons.github.com www.google-analytics.com collector.githubapp.com *.githubusercontent.com *.gravatar.com *.wp.com; media-src \'none\'; frame-src \'self\' render.githubusercontent.com gist.github.com www.youtube.com player.vimeo.com checkout.paypal.com; font-src assets-cdn.github.com; connect-src \'self\' ghconduit.com:25035 live.github.com wss://live.github.com uploads.github.com www.google-analytics.com s3.amazonaws.com',
'Cache-Control' => 'no-cache',
'Vary' => 'X-PJAX, Accept-Encoding',
'X-UA-Compatible' => 'IE=Edge,chrome=1',
'Set-Cookie' => 'logged_in=no; domain=.github.com; path=/; expires=Wed, 21-Feb-2035 18:44:34 GMT; secure; HttpOnly, _gh_sess=eyJzZXNzaW9uX2lkIjoiNDZkZDdiMTMzNDIxMjQ5OTNjZjliNmUyMzg4OTM5MWUiLCJsYXN0X3dyaXRlIjoxNDI0NTQ0Mjc0NDgzfQ%3D%3D--4ca192ff94067bcf8922b053b0758d1f580f85a6; path=/; secure; HttpOnly',
'X-Request-Id' => 'f8898bcf19b20706de5712177bdf9eeb',
'X-Runtime' => '0.010527',
'X-Rack-Cache' => 'invalidate, pass',
'X-GitHub-Request-Id' => 'AE71B20F:0FF4:159043E3:54E8D212',
'Strict-Transport-Security' => 'max-age=31536000; includeSubdomains; preload',
'X-Content-Type-Options' => 'nosniff',
'X-XSS-Protection' => '1; mode=block',
'X-Frame-Options' => 'deny',
'X-Served-By' => 'a568c03544f42dddf712bab3bfd562fd'
],
'body' => '{"access_token":"abcdefgh12345678","token_type":"bearer","scope":"user:email"}'
];
@@ -0,0 +1,33 @@
<?php
return [
'status' => 200,
'headers' => [
'Server' => 'GitHub.com',
'Date' => 'Thu, 19 Mar 2015 03:42:05 GMT',
'Content-Type' => 'application/json; charset=utf-8',
'Content-Length' => '62',
'Status' => '200 OK',
'X-RateLimit-Limit' => '5000',
'X-RateLimit-Remaining' => '4948',
'X-RateLimit-Reset' => '1426740125',
'Cache-Control' => 'private, max-age=60, s-maxage=60',
'ETag' => '"06ddc2c2d17761bc98b0e6419aed512c"',
'X-OAuth-Scopes' => 'user:email',
'X-Accepted-OAuth-Scopes' => 'user, user:email',
'X-OAuth-Client-Id' => 'b80ba34640eb08f2b3e5',
'Vary' => 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding',
'X-GitHub-Media-Type' => 'github.v3',
'X-XSS-Protection' => '1; mode=block',
'X-Frame-Options' => 'deny',
'Content-Security-Policy' => 'default-src \'none\'',
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Expose-Headers' => 'ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval',
'Access-Control-Allow-Origin' => '*',
'X-GitHub-Request-Id' => 'AE71B20F:4EF8:83D06C:550A458D',
'Strict-Transport-Security' => 'max-age=31536000; includeSubdomains; preload',
'X-Content-Type-Options' => 'nosniff',
'X-Served-By' => 'b0ef53392caa42315c6206737946d931'
],
'body' => '[{"email": "adam@example.com","primary": true,"verified": true}]'
];
@@ -0,0 +1,34 @@
<?php
return [
'status' => 200,
'headers' => [
'Server' => 'GitHub.com',
'Date' => 'Sat, 21 Feb 2015 18:43:17 GMT',
'Content-Type' => 'application/json; charset=utf-8',
'Content-Length' => '1278',
'Status' => '200 OK',
'X-RateLimit-Limit' => '5000',
'X-RateLimit-Remaining' => '4961',
'X-RateLimit-Reset' => '1424546049',
'Cache-Control' => 'private, max-age=60, s-maxage=60',
'Last-Modified' => 'Sat, 21 Feb 2015 17:06:00 GMT',
'ETag' => '"7a29c845b431fa302144d2d2da66e7e3"',
'X-OAuth-Scopes' => 'user:email',
'X-Accepted-OAuth-Scopes' => '',
'X-OAuth-Client-Id' => 'b80ba34640eb08f2b3e5',
'Vary' => 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding',
'X-GitHub-Media-Type' => 'github.v3',
'X-XSS-Protection' => '1; mode=block',
'X-Frame-Options' => 'deny',
'Content-Security-Policy' => 'default-src \'none\'',
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Expose-Headers' => 'ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval',
'Access-Control-Allow-Origin' => '*',
'X-GitHub-Request-Id' => 'AE71B20F:202B:3ABE9811:54E8D1C5',
'Strict-Transport-Security' => 'max-age=31536000; includeSubdomains; preload',
'X-Content-Type-Options' => 'nosniff',
'X-Served-By' => '065b43cd9674091fec48a221b420fbb3'
],
'body' => '{"login":"adamwathan","id":4323180,"avatar_url":"https://avatars.githubusercontent.com/u/4323180?v=3","gravatar_id":"","url":"https://api.github.com/users/adamwathan","html_url":"https://github.com/adamwathan","followers_url":"https://api.github.com/users/adamwathan/followers","following_url":"https://api.github.com/users/adamwathan/following{/other_user}","gists_url":"https://api.github.com/users/adamwathan/gists{/gist_id}","starred_url":"https://api.github.com/users/adamwathan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamwathan/subscriptions","organizations_url":"https://api.github.com/users/adamwathan/orgs","repos_url":"https://api.github.com/users/adamwathan/repos","events_url":"https://api.github.com/users/adamwathan/events{/privacy}","received_events_url":"https://api.github.com/users/adamwathan/received_events","type":"User","site_admin":false,"name":"Adam Wathan","company":"Tighten Co","blog":"","location":"Ontario,Canada","email":"","hireable":false,"bio":null,"public_repos":38,"public_gists":12,"followers":54,"following":10,"created_at":"2013-05-02T15:35:48Z","updated_at":"2015-02-21T17:06:00Z"}'
];