Skip to content

Commit

Permalink
Merge branch '3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Nov 29, 2018
2 parents 4916023 + baac292 commit cf45ac5
Show file tree
Hide file tree
Showing 29 changed files with 732 additions and 219 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_style = space
indent_size = 2
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* text=auto

/tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
phpunit.xml.dist export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/vendor
composer.phar
composer.lock
phpunit.xml
.DS_Store
Thumbs.db
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ language: php
php:
- 7.0
- 7.1
- 7.2
- 7.3

sudo: false

install: travis_retry composer install --no-interaction --prefer-source
before_install:
- phpenv config-rm xdebug.ini || true

install: travis_retry composer install --no-interaction --prefer-dist --no-suggest

script: vendor/bin/phpunit --verbose
2 changes: 1 addition & 1 deletion LICENSE.txt → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) <Taylor Otwell>
Copyright (c) Taylor Otwell

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<p align="center"><img src="https://laravel.com/assets/img/components/logo-socialite.svg"></p>

<p align="center">
<a href="https://travis-ci.org/laravel/socialite"><img src="https://travis-ci.org/laravel/socialite.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/laravel/socialite"><img src="https://poser.pugx.org/laravel/socialite/d/total.svg" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel/socialite"><img src="https://poser.pugx.org/laravel/socialite/v/stable.svg" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel/socialite"><img src="https://poser.pugx.org/laravel/socialite/license.svg" alt="License"></a>
</p>

## Introduction

Laravel Socialite provides an expressive, fluent interface to OAuth authentication with Facebook, Twitter, Google, LinkedIn, GitHub, GitLab and Bitbucket. It handles almost all of the boilerplate social authentication code you are dreading writing.

**We are not accepting new adapters.**

**If you are using Laravel 5.3 or below, please use [Socialite 2.0](https://github.com/laravel/socialite/tree/2.0).**

Adapters for other platforms are listed at the community driven [Socialite Providers](https://socialiteproviders.github.io/) website.

## Official Documentation

Documentation for Socialite can be found on the [Laravel website](https://laravel.com/docs/socialite).

## License

Laravel Socialite is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
12 changes: 11 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
"description": "Laravel wrapper around OAuth 1 & OAuth 2 libraries.",
"keywords": ["oauth", "laravel"],
"license": "MIT",
"homepage": "https://laravel.com",
"support": {
"issues": "https://github.com/laravel/socialite/issues",
"source": "https://github.com/laravel/socialite"
},
"authors": [
{
"name": "Taylor Otwell",
"email": "taylorotwell@gmail.com"
"email": "taylor@laravel.com"
}
],
"require": {
Expand All @@ -27,6 +32,11 @@
"Laravel\\Socialite\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
Expand Down
4 changes: 3 additions & 1 deletion phpunit.xml → phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
syntaxCheck="false"
syntaxCheck="true"
verbose="true"
>
<testsuites>
<testsuite name="Package Test Suite">
Expand Down
13 changes: 0 additions & 13 deletions readme.md

This file was deleted.

19 changes: 18 additions & 1 deletion src/AbstractUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ abstract class AbstractUser implements ArrayAccess, Contracts\User
*/
public $avatar;

/**
* The user's raw attributes.
*
* @var array
*/
public $user;

/**
* Get the unique identifier for the user.
*
Expand Down Expand Up @@ -91,6 +98,16 @@ public function getAvatar()
return $this->avatar;
}

/**
* Get the raw user array.
*
* @return array
*/
public function getRaw()
{
return $this->user;
}

/**
* Set the raw user array from the provider.
*
Expand Down Expand Up @@ -123,7 +140,7 @@ public function map(array $attributes)
* Determine if the given raw user attribute exists.
*
* @param string $offset
* @return bool
* @return bool
*/
public function offsetExists($offset)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Facades/Socialite.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Socialite\Facades;

use Illuminate\Support\Facades\Facade;
use Laravel\Socialite\Contracts\Factory;

/**
* @see \Laravel\Socialite\SocialiteManager
Expand All @@ -16,6 +17,6 @@ class Socialite extends Facade
*/
protected static function getFacadeAccessor()
{
return 'Laravel\Socialite\Contracts\Factory';
return Factory::class;
}
}
92 changes: 80 additions & 12 deletions src/One/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,39 @@

use Illuminate\Http\Request;
use InvalidArgumentException;
use Illuminate\Http\RedirectResponse;
use League\OAuth1\Client\Server\Server;
use Symfony\Component\HttpFoundation\RedirectResponse;
use League\OAuth1\Client\Credentials\TokenCredentials;
use Laravel\Socialite\Contracts\Provider as ProviderContract;

abstract class AbstractProvider implements ProviderContract
{
/**
* The HTTP request instance.
*
* @var Request
* @var \Illuminate\Http\Request
*/
protected $request;

/**
* The OAuth server implementation.
*
* @var Server
* @var \League\OAuth1\Client\Server\Server
*/
protected $server;

/**
* A hash representing the last requested user.
*
* @var string
*/
protected $userHash;

/**
* Create a new provider instance.
*
* @param Request $request
* @param Server $server
* @param \Illuminate\Http\Request $request
* @param \League\OAuth1\Client\Server\Server $server
* @return void
*/
public function __construct(Request $request, Server $server)
Expand All @@ -40,11 +48,11 @@ public function __construct(Request $request, Server $server)
/**
* Redirect the user to the authentication page for the provider.
*
* @return RedirectResponse
* @return \Illuminate\Http\RedirectResponse
*/
public function redirect()
{
$this->request->getSession()->put(
$this->request->session()->put(
'oauth.temp', $temp = $this->server->getTemporaryCredentials()
);

Expand All @@ -54,6 +62,7 @@ public function redirect()
/**
* Get the User instance for the authenticated user.
*
* @throws \InvalidArgumentException
* @return \Laravel\Socialite\One\User
*/
public function user()
Expand All @@ -62,14 +71,51 @@ public function user()
throw new InvalidArgumentException('Invalid request. Missing OAuth verifier.');
}

$user = $this->server->getUserDetails($token = $this->getToken());
$token = $this->getToken();

$user = $this->server->getUserDetails(
$token, $this->shouldBypassCache($token->getIdentifier(), $token->getSecret())
);

$instance = (new User)->setRaw($user->extra)
->setToken($token->getIdentifier(), $token->getSecret());

return $instance->map([
'id' => $user->uid, 'nickname' => $user->nickname,
'name' => $user->name, 'email' => $user->email, 'avatar' => $user->imageUrl,
'id' => $user->uid,
'nickname' => $user->nickname,
'name' => $user->name,
'email' => $user->email,
'avatar' => $user->imageUrl,
]);
}

/**
* Get a Social User instance from a known access token and secret.
*
* @param string $token
* @param string $secret
* @return \Laravel\Socialite\One\User
*/
public function userFromTokenAndSecret($token, $secret)
{
$tokenCredentials = new TokenCredentials();

$tokenCredentials->setIdentifier($token);
$tokenCredentials->setSecret($secret);

$user = $this->server->getUserDetails(
$tokenCredentials, $this->shouldBypassCache($token, $secret)
);

$instance = (new User)->setRaw($user->extra)
->setToken($tokenCredentials->getIdentifier(), $tokenCredentials->getSecret());

return $instance->map([
'id' => $user->uid,
'nickname' => $user->nickname,
'name' => $user->name,
'email' => $user->email,
'avatar' => $user->imageUrl,
]);
}

Expand All @@ -80,7 +126,7 @@ public function user()
*/
protected function getToken()
{
$temp = $this->request->getSession()->get('oauth.temp');
$temp = $this->request->session()->get('oauth.temp');

return $this->server->getTokenCredentials(
$temp, $this->request->get('oauth_token'), $this->request->get('oauth_verifier')
Expand All @@ -97,10 +143,32 @@ protected function hasNecessaryVerifier()
return $this->request->has('oauth_token') && $this->request->has('oauth_verifier');
}

/**
* Determine if the user information cache should be bypassed.
*
* @param string $token
* @param string $secret
* @return bool
*/
protected function shouldBypassCache($token, $secret)
{
$newHash = sha1($token.'_'.$secret);

if (! empty($this->userHash) && $newHash !== $this->userHash) {
$this->userHash = $newHash;

return true;
}

$this->userHash = $this->userHash ?: $newHash;

return false;
}

/**
* Set the request instance.
*
* @param Request $request
* @param \Illuminate\Http\Request $request
* @return $this
*/
public function setRequest(Request $request)
Expand Down
9 changes: 6 additions & 3 deletions src/One/TwitterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function user()
throw new InvalidArgumentException('Invalid request. Missing OAuth verifier.');
}

$user = $this->server->getUserDetails($token = $this->getToken());
$user = $this->server->getUserDetails($token = $this->getToken(), $this->shouldBypassCache($token->getIdentifier(), $token->getSecret()));

$extraDetails = [
'location' => $user->location,
Expand All @@ -26,8 +26,11 @@ public function user()
->setToken($token->getIdentifier(), $token->getSecret());

return $instance->map([
'id' => $user->uid, 'nickname' => $user->nickname,
'name' => $user->name, 'email' => $user->email, 'avatar' => $user->imageUrl,
'id' => $user->uid,
'nickname' => $user->nickname,
'name' => $user->name,
'email' => $user->email,
'avatar' => $user->imageUrl,
'avatar_original' => str_replace('_normal', '', $user->imageUrl),
]);
}
Expand Down
Loading

0 comments on commit cf45ac5

Please sign in to comment.