Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

5
vendor/laravel/socialite/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
/vendor
composer.phar
composer.lock
.DS_Store
Thumbs.db

13
vendor/laravel/socialite/.travis.yml vendored Normal file
View File

@@ -0,0 +1,13 @@
language: php
php:
- 5.6
- 7.0
- 7.1
- hhvm
sudo: false
install: travis_retry composer install --no-interaction --prefer-source
script: vendor/bin/phpunit --verbose

View File

@@ -11,29 +11,26 @@
],
"require": {
"php": ">=5.4.0",
"guzzlehttp/guzzle": "~5.0|~6.0",
"illuminate/contracts": "~5.0",
"illuminate/http": "~5.0",
"illuminate/support": "~5.0",
"illuminate/contracts": "~5.4",
"illuminate/http": "~5.4",
"illuminate/support": "~5.4",
"guzzlehttp/guzzle": "~6.0",
"league/oauth1-client": "~1.0"
},
"require-dev": {
"mockery/mockery": "~0.9",
"phpunit/phpunit": "~4.0|~5.0"
"phpunit/phpunit": "~4.0"
},
"autoload": {
"psr-4": {
"Laravel\\Socialite\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}

18
vendor/laravel/socialite/phpunit.xml vendored Normal file
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=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@@ -1,136 +1,13 @@
# Laravel Socialite
[![Build Status](https://travis-ci.org/laravel/socialite.svg)](https://travis-ci.org/laravel/socialite)
[![Total Downloads](https://poser.pugx.org/laravel/socialite/d/total.svg)](https://packagist.org/packages/laravel/socialite)
[![Latest Stable Version](https://poser.pugx.org/laravel/socialite/v/stable.svg)](https://packagist.org/packages/laravel/socialite)
[![Latest Unstable Version](https://poser.pugx.org/laravel/socialite/v/unstable.svg)](https://packagist.org/packages/laravel/socialite)
[![License](https://poser.pugx.org/laravel/socialite/license.svg)](https://packagist.org/packages/laravel/socialite)
[![Dependency Status](https://www.versioneye.com/php/laravel:socialite/dev-master/badge?style=flat)](https://www.versioneye.com/php/laravel:socialite/dev-master)
## Introduction
Laravel Socialite provides an expressive, fluent interface to OAuth authentication with Facebook, Twitter, Google, LinkedIn, GitHub and Bitbucket. It handles almost all of the boilerplate social authentication code you are dreading writing.
**We are not accepting new adapters.**
## License
Laravel Socialite is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
## Official Documentation
In addition to typical, form based authentication, Laravel also provides a simple, convenient way to authenticate with OAuth providers using [Laravel Socialite](https://github.com/laravel/socialite). Socialite currently supports authentication with Facebook, Twitter, LinkedIn, Google, GitHub and Bitbucket.
Documentation for Socialite can be found on the [Laravel website](http://laravel.com/docs/authentication#social-authentication).
To get started with Socialite, add to your `composer.json` file as a dependency:
### License
composer require laravel/socialite
### Configuration
After installing the Socialite library, register the `Laravel\Socialite\SocialiteServiceProvider` in your `config/app.php` configuration file:
```php
'providers' => [
// Other service providers...
Laravel\Socialite\SocialiteServiceProvider::class,
],
```
Also, add the `Socialite` facade to the `aliases` array in your `app` configuration file:
```php
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
```
You will also need to add credentials for the OAuth services your application utilizes. These credentials should be placed in your `config/services.php` configuration file, and should use the key `facebook`, `twitter`, `linkedin`, `google`, `github` or `bitbucket`, depending on the providers your application requires. For example:
```php
'github' => [
'client_id' => 'your-github-app-id',
'client_secret' => 'your-github-app-secret',
'redirect' => 'http://your-callback-url',
],
```
### Basic Usage
Next, you are ready to authenticate users! You will need two routes: one for redirecting the user to the OAuth provider, and another for receiving the callback from the provider after authentication. We will access Socialite using the `Socialite` facade:
```php
<?php
namespace App\Http\Controllers\Auth;
use Socialite;
class AuthController extends Controller
{
/**
* Redirect the user to the GitHub authentication page.
*
* @return Response
*/
public function redirectToProvider()
{
return Socialite::driver('github')->redirect();
}
/**
* Obtain the user information from GitHub.
*
* @return Response
*/
public function handleProviderCallback()
{
$user = Socialite::driver('github')->user();
// $user->token;
}
}
```
The `redirect` method takes care of sending the user to the OAuth provider, while the `user` method will read the incoming request and retrieve the user's information from the provider. Before redirecting the user, you may also set "scopes" on the request using the `scope` method. This method will overwrite all existing scopes:
```php
return Socialite::driver('github')
->scopes(['scope1', 'scope2'])->redirect();
```
Of course, you will need to define routes to your controller methods:
```php
Route::get('auth/github', 'Auth\AuthController@redirectToProvider');
Route::get('auth/github/callback', 'Auth\AuthController@handleProviderCallback');
```
A number of OAuth providers support optional parameters in the redirect request. To include any optional parameters in the request, call the `with` method with an associative array:
```php
return Socialite::driver('google')
->with(['hd' => 'example.com'])->redirect();
```
When using the `with` method, be careful not to pass any reserved keywords such as `state` or `response_type`.
#### Retrieving User Details
Once you have a user instance, you can grab a few more details about the user:
```php
$user = Socialite::driver('github')->user();
// OAuth Two Providers
$token = $user->token;
$refreshToken = $user->refreshToken; // not always provided
$expiresIn = $user->expiresIn;
// OAuth One Providers
$token = $user->token;
$tokenSecret = $user->tokenSecret;
// All Providers
$user->getId();
$user->getNickname();
$user->getName();
$user->getEmail();
$user->getAvatar();
```
Laravel Socialite is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

View File

@@ -41,13 +41,6 @@ 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.
*
@@ -98,16 +91,6 @@ abstract class AbstractUser implements ArrayAccess, Contracts\User
return $this->avatar;
}
/**
* Get the raw user array.
*
* @return array
*/
public function getRaw()
{
return $this->user;
}
/**
* Set the raw user array from the provider.
*
@@ -140,7 +123,7 @@ abstract class AbstractUser implements ArrayAccess, Contracts\User
* Determine if the given raw user attribute exists.
*
* @param string $offset
* @return bool
* @return bool
*/
public function offsetExists($offset)
{

View File

@@ -13,22 +13,22 @@ abstract class AbstractProvider implements ProviderContract
/**
* The HTTP request instance.
*
* @var \Illuminate\Http\Request
* @var Request
*/
protected $request;
/**
* The OAuth server implementation.
*
* @var \League\OAuth1\Client\Server\Server
* @var Server
*/
protected $server;
/**
* Create a new provider instance.
*
* @param \Illuminate\Http\Request $request
* @param \League\OAuth1\Client\Server\Server $server
* @param Request $request
* @param Server $server
* @return void
*/
public function __construct(Request $request, Server $server)
@@ -40,11 +40,11 @@ abstract class AbstractProvider implements ProviderContract
/**
* Redirect the user to the authentication page for the provider.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* @return RedirectResponse
*/
public function redirect()
{
$this->request->session()->set(
$this->request->getSession()->put(
'oauth.temp', $temp = $this->server->getTemporaryCredentials()
);
@@ -54,7 +54,6 @@ abstract class AbstractProvider implements ProviderContract
/**
* Get the User instance for the authenticated user.
*
* @throws \InvalidArgumentException
* @return \Laravel\Socialite\One\User
*/
public function user()
@@ -81,7 +80,7 @@ abstract class AbstractProvider implements ProviderContract
*/
protected function getToken()
{
$temp = $this->request->session()->get('oauth.temp');
$temp = $this->request->getSession()->get('oauth.temp');
return $this->server->getTokenCredentials(
$temp, $this->request->get('oauth_token'), $this->request->get('oauth_verifier')
@@ -101,7 +100,7 @@ abstract class AbstractProvider implements ProviderContract
/**
* Set the request instance.
*
* @param \Illuminate\Http\Request $request
* @param Request $request
* @return $this
*/
public function setRequest(Request $request)

View File

@@ -1,8 +0,0 @@
<?php
namespace Laravel\Socialite\One;
class BitbucketProvider extends AbstractProvider
{
//
}

View File

@@ -5,9 +5,7 @@ namespace Laravel\Socialite;
use InvalidArgumentException;
use Illuminate\Support\Manager;
use Laravel\Socialite\One\TwitterProvider;
use Laravel\Socialite\One\BitbucketProvider;
use League\OAuth1\Client\Server\Twitter as TwitterServer;
use League\OAuth1\Client\Server\Bitbucket as BitbucketServer;
class SocialiteManager extends Manager implements Contracts\Factory
{
@@ -78,6 +76,20 @@ class SocialiteManager extends Manager implements Contracts\Factory
);
}
/**
* Create an instance of the specified driver.
*
* @return \Laravel\Socialite\Two\AbstractProvider
*/
protected function createBitbucketDriver()
{
$config = $this->app['config']['services.bitbucket'];
return $this->buildProvider(
'Laravel\Socialite\Two\BitbucketProvider', $config
);
}
/**
* Build an OAuth 2 provider instance.
*
@@ -107,20 +119,6 @@ class SocialiteManager extends Manager implements Contracts\Factory
);
}
/**
* Create an instance of the specified driver.
*
* @return \Laravel\Socialite\One\AbstractProvider
*/
protected function createBitbucketDriver()
{
$config = $this->app['config']['services.bitbucket'];
return new BitbucketProvider(
$this->app['request'], new BitbucketServer($this->formatConfig($config))
);
}
/**
* Format the server configuration.
*

View File

@@ -2,8 +2,6 @@
namespace Laravel\Socialite\Two;
use GuzzleHttp\Client;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use GuzzleHttp\ClientInterface;
@@ -15,17 +13,10 @@ abstract class AbstractProvider implements ProviderContract
/**
* The HTTP request instance.
*
* @var \Illuminate\Http\Request
* @var Request
*/
protected $request;
/**
* The HTTP Client instance.
*
* @var \GuzzleHttp\Client
*/
protected $httpClient;
/**
* The client ID.
*
@@ -85,7 +76,7 @@ abstract class AbstractProvider implements ProviderContract
/**
* Create a new provider instance.
*
* @param \Illuminate\Http\Request $request
* @param Request $request
* @param string $clientId
* @param string $clientSecret
* @param string $redirectUrl
@@ -126,21 +117,21 @@ abstract class AbstractProvider implements ProviderContract
* Map the raw user array to a Socialite User instance.
*
* @param array $user
* @return \Laravel\Socialite\Two\User
* @return \Laravel\Socialite\User
*/
abstract protected function mapUserToObject(array $user);
/**
* Redirect the user of the application to the provider's authentication screen.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* @return \Illuminate\Http\RedirectResponse
*/
public function redirect()
{
$state = null;
if ($this->usesState()) {
$this->request->session()->set('state', $state = Str::random(40));
$this->request->getSession()->put('state', $state = Str::random(40));
}
return new RedirectResponse($this->getAuthUrl($state));
@@ -200,27 +191,10 @@ abstract class AbstractProvider implements ProviderContract
throw new InvalidStateException;
}
$response = $this->getAccessTokenResponse($this->getCode());
$user = $this->mapUserToObject($this->getUserByToken(
$token = Arr::get($response, 'access_token')
$token = $this->getAccessToken($this->getCode())
));
return $user->setToken($token)
->setRefreshToken(Arr::get($response, 'refresh_token'))
->setExpiresIn(Arr::get($response, 'expires_in'));
}
/**
* Get a Social User instance from a known access token.
*
* @param string $token
* @return \Laravel\Socialite\Two\User
*/
public function userFromToken($token)
{
$user = $this->mapUserToObject($this->getUserByToken($token));
return $user->setToken($token);
}
@@ -234,21 +208,19 @@ abstract class AbstractProvider implements ProviderContract
if ($this->isStateless()) {
return false;
}
//dd($this->request->all());
$state = $this->request->input('state');
\Session::put('state', $state);
//$state = $this->request->session()->pull('state');
$state = $this->request->getSession()->pull('state');
return ! (strlen($state) > 0 && $this->request->input('state') === $state);
}
/**
* Get the access token response for the given code.
* Get the access token for the given code.
*
* @param string $code
* @return array
* @return string
*/
public function getAccessTokenResponse($code)
public function getAccessToken($code)
{
$postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body';
@@ -257,7 +229,7 @@ abstract class AbstractProvider implements ProviderContract
$postKey => $this->getTokenFields($code),
]);
return json_decode($response->getBody(), true);
return $this->parseAccessToken($response->getBody());
}
/**
@@ -274,6 +246,17 @@ abstract class AbstractProvider implements ProviderContract
];
}
/**
* Get the access token from the token response body.
*
* @param string $body
* @return string
*/
protected function parseAccessToken($body)
{
return json_decode($body, true)['access_token'];
}
/**
* Get the code from the request.
*
@@ -292,65 +275,25 @@ abstract class AbstractProvider implements ProviderContract
*/
public function scopes(array $scopes)
{
$this->scopes = array_unique(array_merge($this->scopes, $scopes));
$this->scopes = $scopes;
return $this;
}
/**
* Get the current scopes.
*
* @return array
*/
public function getScopes()
{
return $this->scopes;
}
/**
* Set the redirect URL.
*
* @param string $url
* @return $this
*/
public function redirectUrl($url)
{
$this->redirectUrl = $url;
return $this;
}
/**
* Get a instance of the Guzzle HTTP client.
* Get a fresh instance of the Guzzle HTTP client.
*
* @return \GuzzleHttp\Client
*/
protected function getHttpClient()
{
if (is_null($this->httpClient)) {
$this->httpClient = new Client();
}
return $this->httpClient;
}
/**
* Set the Guzzle HTTP client instance.
*
* @param \GuzzleHttp\Client $client
* @return $this
*/
public function setHttpClient(Client $client)
{
$this->httpClient = $client;
return $this;
return new \GuzzleHttp\Client;
}
/**
* Set the request instance.
*
* @param \Illuminate\Http\Request $request
* @param Request $request
* @return $this
*/
public function setRequest(Request $request)

View File

@@ -0,0 +1,119 @@
<?php
namespace Laravel\Socialite\Two;
use Exception;
use GuzzleHttp\ClientInterface;
class BitbucketProvider extends AbstractProvider implements ProviderInterface
{
/**
* The scopes being requested.
*
* @var array
*/
protected $scopes = ['email'];
/**
* {@inheritdoc}
*/
protected function getAuthUrl($state)
{
return $this->buildAuthUrlFromBase('https://bitbucket.org/site/oauth2/authorize', $state);
}
/**
* {@inheritdoc}
*/
protected function getTokenUrl()
{
return 'https://bitbucket.org/site/oauth2/access_token';
}
/**
* {@inheritdoc}
*/
protected function getUserByToken($token)
{
$userUrl = 'https://api.bitbucket.org/2.0/user?access_token='.$token;
$response = $this->getHttpClient()->get($userUrl);
$user = json_decode($response->getBody(), true);
if (in_array('email', $this->scopes)) {
$user['email'] = $this->getEmailByToken($token);
}
return $user;
}
/**
* Get the email for the given access token.
*
* @param string $token
* @return string|null
*/
protected function getEmailByToken($token)
{
$emailsUrl = 'https://api.bitbucket.org/2.0/user/emails?access_token='.$token;
try {
$response = $this->getHttpClient()->get($emailsUrl);
} catch (Exception $e) {
return;
}
$emails = json_decode($response->getBody(), true);
foreach ($emails['values'] as $email) {
if ($email['type'] == 'email' && $email['is_primary'] && $email['is_confirmed']) {
return $email['email'];
}
}
}
/**
* {@inheritdoc}
*/
protected function mapUserToObject(array $user)
{
return (new User)->setRaw($user)->map([
'id' => $user['uuid'], 'nickname' => $user['username'],
'name' => array_get($user, 'display_name'), 'email' => array_get($user, 'email'),
'avatar' => array_get($user, 'links.avatar.href'),
]);
}
/**
* Get the access token for the given code.
*
* @param string $code
* @return string
*/
public function getAccessToken($code)
{
$postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body';
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
'auth' => [$this->clientId, $this->clientSecret],
'headers' => ['Accept' => 'application/json'],
$postKey => $this->getTokenFields($code),
]);
return $this->parseAccessToken($response->getBody());
}
/**
* Get the POST fields for the token request.
*
* @param string $code
* @return array
*/
protected function getTokenFields($code)
{
return [
'code' => $code, 'redirect_uri' => $this->redirectUrl, 'grant_type' => 'authorization_code',
];
}
}

View File

@@ -2,9 +2,6 @@
namespace Laravel\Socialite\Two;
use Illuminate\Support\Arr;
use GuzzleHttp\ClientInterface;
class FacebookProvider extends AbstractProvider implements ProviderInterface
{
/**
@@ -19,14 +16,14 @@ class FacebookProvider extends AbstractProvider implements ProviderInterface
*
* @var string
*/
protected $version = 'v2.6';
protected $version = 'v2.5';
/**
* The user fields being requested.
*
* @var array
*/
protected $fields = ['name', 'email', 'gender', 'verified'];
protected $fields = ['first_name', 'last_name', 'email', 'gender', 'verified'];
/**
* The scopes being requested.
@@ -42,13 +39,6 @@ class FacebookProvider extends AbstractProvider implements ProviderInterface
*/
protected $popup = false;
/**
* Re-request a declined permission.
*
* @var bool
*/
protected $reRequest = false;
/**
* {@inheritdoc}
*/
@@ -62,23 +52,32 @@ class FacebookProvider extends AbstractProvider implements ProviderInterface
*/
protected function getTokenUrl()
{
return $this->graphUrl.'/'.$this->version.'/oauth/access_token';
return $this->graphUrl.'/oauth/access_token';
}
/**
* Get the access token for the given code.
*
* @param string $code
* @return string
*/
public function getAccessToken($code)
{
$response = $this->getHttpClient()->get($this->getTokenUrl(), [
'query' => $this->getTokenFields($code),
]);
return $this->parseAccessToken($response->getBody());
}
/**
* {@inheritdoc}
*/
public function getAccessTokenResponse($code)
protected function parseAccessToken($body)
{
$postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body';
parse_str($body);
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
$postKey => $this->getTokenFields($code),
]);
$data = json_decode($response->getBody(), true);
return Arr::add($data, 'expires_in', Arr::pull($data, 'expires'));
return $access_token;
}
/**
@@ -86,15 +85,9 @@ class FacebookProvider extends AbstractProvider implements ProviderInterface
*/
protected function getUserByToken($token)
{
$meUrl = $this->graphUrl.'/'.$this->version.'/me?access_token='.$token.'&fields='.implode(',', $this->fields);
$appSecretProof = hash_hmac('sha256', $token, $this->clientSecret);
if (! empty($this->clientSecret)) {
$appSecretProof = hash_hmac('sha256', $token, $this->clientSecret);
$meUrl .= '&appsecret_proof='.$appSecretProof;
}
$response = $this->getHttpClient()->get($meUrl, [
$response = $this->getHttpClient()->get($this->graphUrl.'/'.$this->version.'/me?access_token='.$token.'&appsecret_proof='.$appSecretProof.'&fields='.implode(',', $this->fields), [
'headers' => [
'Accept' => 'application/json',
],
@@ -110,8 +103,12 @@ class FacebookProvider extends AbstractProvider implements ProviderInterface
{
$avatarUrl = $this->graphUrl.'/'.$this->version.'/'.$user['id'].'/picture';
$firstName = isset($user['first_name']) ? $user['first_name'] : null;
$lastName = isset($user['last_name']) ? $user['last_name'] : null;
return (new User)->setRaw($user)->map([
'id' => $user['id'], 'nickname' => null, 'name' => isset($user['name']) ? $user['name'] : null,
'id' => $user['id'], 'nickname' => null, 'name' => $firstName.' '.$lastName,
'email' => isset($user['email']) ? $user['email'] : null, 'avatar' => $avatarUrl.'?type=normal',
'avatar_original' => $avatarUrl.'?width=1920',
]);
@@ -128,10 +125,6 @@ class FacebookProvider extends AbstractProvider implements ProviderInterface
$fields['display'] = 'popup';
}
if ($this->reRequest) {
$fields['auth_type'] = 'rerequest';
}
return $fields;
}
@@ -159,14 +152,4 @@ class FacebookProvider extends AbstractProvider implements ProviderInterface
return $this;
}
/**
* Re-request permissions which were previously declined.
*
* @return $this
*/
public function reRequest()
{
$this->reRequest = true;
}
}

View File

@@ -3,7 +3,6 @@
namespace Laravel\Socialite\Two;
use Exception;
use Illuminate\Support\Arr;
class GithubProvider extends AbstractProvider implements ProviderInterface
{
@@ -81,8 +80,8 @@ class GithubProvider extends AbstractProvider implements ProviderInterface
protected function mapUserToObject(array $user)
{
return (new User)->setRaw($user)->map([
'id' => $user['id'], 'nickname' => $user['login'], 'name' => Arr::get($user, 'name'),
'email' => Arr::get($user, 'email'), 'avatar' => $user['avatar_url'],
'id' => $user['id'], 'nickname' => $user['login'], 'name' => array_get($user, 'name'),
'email' => array_get($user, 'email'), 'avatar' => $user['avatar_url'],
]);
}

View File

@@ -2,7 +2,7 @@
namespace Laravel\Socialite\Two;
use Illuminate\Support\Arr;
use GuzzleHttp\ClientInterface;
class GoogleProvider extends AbstractProvider implements ProviderInterface
{
@@ -19,7 +19,6 @@ class GoogleProvider extends AbstractProvider implements ProviderInterface
* @var array
*/
protected $scopes = [
'openid',
'profile',
'email',
];
@@ -40,6 +39,23 @@ class GoogleProvider extends AbstractProvider implements ProviderInterface
return 'https://accounts.google.com/o/oauth2/token';
}
/**
* Get the access token for the given code.
*
* @param string $code
* @return string
*/
public function getAccessToken($code)
{
$postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body';
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
$postKey => $this->getTokenFields($code),
]);
return $this->parseAccessToken($response->getBody());
}
/**
* Get the POST fields for the token request.
*
@@ -77,8 +93,8 @@ class GoogleProvider extends AbstractProvider implements ProviderInterface
protected function mapUserToObject(array $user)
{
return (new User)->setRaw($user)->map([
'id' => $user['id'], 'nickname' => Arr::get($user, 'nickname'), 'name' => $user['displayName'],
'email' => $user['emails'][0]['value'], 'avatar' => Arr::get($user, 'image')['url'],
'id' => $user['id'], 'nickname' => array_get($user, 'nickname'), 'name' => $user['displayName'],
'email' => $user['emails'][0]['value'], 'avatar' => array_get($user, 'image')['url'],
]);
}
}

View File

@@ -4,5 +4,4 @@ namespace Laravel\Socialite\Two;
class InvalidStateException extends \InvalidArgumentException
{
//
}

View File

@@ -2,8 +2,6 @@
namespace Laravel\Socialite\Two;
use Illuminate\Support\Arr;
class LinkedInProvider extends AbstractProvider implements ProviderInterface
{
/**
@@ -12,13 +10,6 @@ class LinkedInProvider extends AbstractProvider implements ProviderInterface
* @var array
*/
protected $scopes = ['r_basicprofile', 'r_emailaddress'];
/**
* The separating character for the requested scopes.
*
* @var string
*/
protected $scopeSeparator = ' ';
/**
* The fields that are included in the profile.
@@ -36,7 +27,7 @@ class LinkedInProvider extends AbstractProvider implements ProviderInterface
*/
protected function getAuthUrl($state)
{
return $this->buildAuthUrlFromBase('https://www.linkedin.com/oauth/v2/authorization', $state);
return $this->buildAuthUrlFromBase('https://www.linkedin.com/uas/oauth2/authorization', $state);
}
/**
@@ -44,7 +35,7 @@ class LinkedInProvider extends AbstractProvider implements ProviderInterface
*/
protected function getTokenUrl()
{
return 'https://www.linkedin.com/oauth/v2/accessToken';
return 'https://www.linkedin.com/uas/oauth2/accessToken';
}
/**
@@ -83,9 +74,9 @@ class LinkedInProvider extends AbstractProvider implements ProviderInterface
protected function mapUserToObject(array $user)
{
return (new User)->setRaw($user)->map([
'id' => $user['id'], 'nickname' => null, 'name' => Arr::get($user, 'formattedName'),
'email' => Arr::get($user, 'emailAddress'), 'avatar' => Arr::get($user, 'pictureUrl'),
'avatar_original' => Arr::get($user, 'pictureUrls.values.0'),
'id' => $user['id'], 'nickname' => null, 'name' => array_get($user, 'formattedName'),
'email' => array_get($user, 'emailAddress'), 'avatar' => array_get($user, 'pictureUrl'),
'avatar_original' => array_get($user, 'pictureUrls.values.0'),
]);
}

View File

@@ -13,20 +13,6 @@ class User extends AbstractUser
*/
public $token;
/**
* The refresh token that can be exchanged for a new access token.
*
* @var string
*/
public $refreshToken;
/**
* The number of seconds the access token is valid for.
*
* @var int
*/
public $expiresIn;
/**
* Set the token on the user.
*
@@ -39,30 +25,4 @@ class User extends AbstractUser
return $this;
}
/**
* Set the refresh token required to obtain a new access token.
*
* @param string $refreshToken
* @return $this
*/
public function setRefreshToken($refreshToken)
{
$this->refreshToken = $refreshToken;
return $this;
}
/**
* Set the number of seconds the access token is valid for.
*
* @param int $expiresIn
* @return $this
*/
public function setExpiresIn($expiresIn)
{
$this->expiresIn = $expiresIn;
return $this;
}
}

View File

@@ -0,0 +1,70 @@
<?php
use Mockery as m;
use Illuminate\Http\Request;
use Laravel\Socialite\One\AbstractProvider;
class OAuthOneTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
m::close();
}
public function testRedirectGeneratesTheProperSymfonyRedirectResponse()
{
$server = m::mock('League\OAuth1\Client\Server\Twitter');
$server->shouldReceive('getTemporaryCredentials')->once()->andReturn('temp');
$server->shouldReceive('getAuthorizationUrl')->once()->with('temp')->andReturn('http://auth.url');
$request = Request::create('foo');
$request->setLaravelSession($session = m::mock('Illuminate\Contracts\Session\Session'));
$session->shouldReceive('put')->once()->with('oauth.temp', 'temp');
$provider = new OAuthOneTestProviderStub($request, $server);
$response = $provider->redirect();
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
}
public function testUserReturnsAUserInstanceForTheAuthenticatedRequest()
{
$server = m::mock('League\OAuth1\Client\Server\Twitter');
$temp = m::mock('League\OAuth1\Client\Credentials\TemporaryCredentials');
$server->shouldReceive('getTokenCredentials')->once()->with($temp, 'oauth_token', 'oauth_verifier')->andReturn(
$token = m::mock('League\OAuth1\Client\Credentials\TokenCredentials')
);
$server->shouldReceive('getUserDetails')->once()->with($token)->andReturn($user = m::mock('League\OAuth1\Client\Server\User'));
$token->shouldReceive('getIdentifier')->once()->andReturn('identifier');
$token->shouldReceive('getSecret')->once()->andReturn('secret');
$user->uid = 'uid';
$user->email = 'foo@bar.com';
$user->extra = ['extra' => 'extra'];
$request = Request::create('foo', 'GET', ['oauth_token' => 'oauth_token', 'oauth_verifier' => 'oauth_verifier']);
$request->setLaravelSession($session = m::mock('Illuminate\Contracts\Session\Session'));
$session->shouldReceive('get')->once()->with('oauth.temp')->andReturn($temp);
$provider = new OAuthOneTestProviderStub($request, $server);
$user = $provider->user();
$this->assertInstanceOf('Laravel\Socialite\One\User', $user);
$this->assertEquals('uid', $user->id);
$this->assertEquals('foo@bar.com', $user->email);
}
/**
* @expectedException InvalidArgumentException
*/
public function testExceptionIsThrownWhenVerifierIsMissing()
{
$server = m::mock('League\OAuth1\Client\Server\Twitter');
$request = Request::create('foo');
$request->setLaravelSession($session = m::mock('Illuminate\Contracts\Session\Session'));
$provider = new OAuthOneTestProviderStub($request, $server);
$user = $provider->user();
}
}
class OAuthOneTestProviderStub extends AbstractProvider
{
}

View File

@@ -0,0 +1,106 @@
<?php
use Mockery as m;
use Illuminate\Http\Request;
use Laravel\Socialite\Two\User;
use Laravel\Socialite\Two\AbstractProvider;
class OAuthTwoTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
m::close();
}
public function testRedirectGeneratesTheProperSymfonyRedirectResponse()
{
$request = Request::create('foo');
$request->setLaravelSession($session = m::mock('Illuminate\Contracts\Session\Session'));
$session->shouldReceive('put')->once();
$provider = new OAuthTwoTestProviderStub($request, 'client_id', 'client_secret', 'redirect');
$response = $provider->redirect();
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
$this->assertEquals('http://auth.url', $response->getTargetUrl());
}
public function testUserReturnsAUserInstanceForTheAuthenticatedRequest()
{
$request = Request::create('foo', 'GET', ['state' => str_repeat('A', 40), 'code' => 'code']);
$request->setLaravelSession($session = m::mock('Illuminate\Contracts\Session\Session'));
$session->shouldReceive('pull')->once()->with('state')->andReturn(str_repeat('A', 40));
$provider = new OAuthTwoTestProviderStub($request, 'client_id', 'client_secret', 'redirect_uri');
$provider->http = m::mock('StdClass');
$provider->http->shouldReceive('post')->once()->with('http://token.url', [
'headers' => ['Accept' => 'application/json'], 'form_params' => ['client_id' => 'client_id', 'client_secret' => 'client_secret', 'code' => 'code', 'redirect_uri' => 'redirect_uri'],
])->andReturn($response = m::mock('StdClass'));
$response->shouldReceive('getBody')->once()->andReturn('access_token=access_token');
$user = $provider->user();
$this->assertInstanceOf('Laravel\Socialite\Two\User', $user);
$this->assertEquals('foo', $user->id);
}
/**
* @expectedException Laravel\Socialite\Two\InvalidStateException
*/
public function testExceptionIsThrownIfStateIsInvalid()
{
$request = Request::create('foo', 'GET', ['state' => str_repeat('B', 40), 'code' => 'code']);
$request->setLaravelSession($session = m::mock('Illuminate\Contracts\Session\Session'));
$session->shouldReceive('pull')->once()->with('state')->andReturn(str_repeat('A', 40));
$provider = new OAuthTwoTestProviderStub($request, 'client_id', 'client_secret', 'redirect');
$user = $provider->user();
}
/**
* @expectedException Laravel\Socialite\Two\InvalidStateException
*/
public function testExceptionIsThrownIfStateIsNotSet()
{
$request = Request::create('foo', 'GET', ['state' => 'state', 'code' => 'code']);
$request->setLaravelSession($session = m::mock('Illuminate\Contracts\Session\Session'));
$session->shouldReceive('pull')->once()->with('state');
$provider = new OAuthTwoTestProviderStub($request, 'client_id', 'client_secret', 'redirect');
$user = $provider->user();
}
}
class OAuthTwoTestProviderStub extends AbstractProvider
{
public $http;
protected function getAuthUrl($state)
{
return 'http://auth.url';
}
protected function getTokenUrl()
{
return 'http://token.url';
}
protected function getUserByToken($token)
{
return ['id' => 'foo'];
}
protected function mapUserToObject(array $user)
{
return (new User)->map(['id' => $user['id']]);
}
/**
* Get a fresh instance of the Guzzle HTTP client.
*
* @return \GuzzleHttp\Client
*/
protected function getHttpClient()
{
if ($this->http) {
return $this->http;
}
return $this->http = m::mock('StdClass');
}
}