dependencies-upgrade
This commit is contained in:
8
vendor/laravel/socialite/README.md
vendored
8
vendor/laravel/socialite/README.md
vendored
@@ -1,10 +1,10 @@
|
||||
<p align="center"><img src="https://laravel.com/assets/img/components/logo-socialite.svg"></p>
|
||||
<p align="center"><img src="/art/logo.svg" alt="Logo Laravel Socialite"></p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/laravel/socialite/actions"><img src="https://github.com/laravel/socialite/workflows/tests/badge.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>
|
||||
<a href="https://packagist.org/packages/laravel/socialite"><img src="https://img.shields.io/packagist/dt/laravel/socialite" alt="Total Downloads"></a>
|
||||
<a href="https://packagist.org/packages/laravel/socialite"><img src="https://img.shields.io/packagist/v/laravel/socialite" alt="Latest Stable Version"></a>
|
||||
<a href="https://packagist.org/packages/laravel/socialite"><img src="https://img.shields.io/packagist/l/laravel/socialite" alt="License"></a>
|
||||
</p>
|
||||
|
||||
## Introduction
|
||||
|
16
vendor/laravel/socialite/composer.json
vendored
16
vendor/laravel/socialite/composer.json
vendored
@@ -15,18 +15,18 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1.3",
|
||||
"php": "^7.2|^8.0",
|
||||
"ext-json": "*",
|
||||
"guzzlehttp/guzzle": "^6.0|^7.0",
|
||||
"illuminate/http": "~5.7.0|~5.8.0|^6.0|^7.0",
|
||||
"illuminate/support": "~5.7.0|~5.8.0|^6.0|^7.0",
|
||||
"league/oauth1-client": "^1.0"
|
||||
"illuminate/contracts": "^6.0|^7.0|^8.0|^9.0",
|
||||
"illuminate/http": "^6.0|^7.0|^8.0|^9.0",
|
||||
"illuminate/support": "^6.0|^7.0|^8.0|^9.0",
|
||||
"league/oauth1-client": "^1.10.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"illuminate/contracts": "~5.7.0|~5.8.0|^6.0|^7.0",
|
||||
"mockery/mockery": "^1.0",
|
||||
"orchestra/testbench": "^3.7|^3.8|^4.0|^5.0",
|
||||
"phpunit/phpunit": "^7.0|^8.0"
|
||||
"orchestra/testbench": "^4.0|^5.0|^6.0|^7.0",
|
||||
"phpunit/phpunit": "^8.0|^9.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@@ -40,7 +40,7 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.x-dev"
|
||||
"dev-master": "5.x-dev"
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
|
28
vendor/laravel/socialite/src/AbstractUser.php
vendored
28
vendor/laravel/socialite/src/AbstractUser.php
vendored
@@ -49,6 +49,13 @@ abstract class AbstractUser implements ArrayAccess, User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* The user's other attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $attributes = [];
|
||||
|
||||
/**
|
||||
* Get the unique identifier for the user.
|
||||
*
|
||||
@@ -130,8 +137,12 @@ abstract class AbstractUser implements ArrayAccess, User
|
||||
*/
|
||||
public function map(array $attributes)
|
||||
{
|
||||
$this->attributes = $attributes;
|
||||
|
||||
foreach ($attributes as $key => $value) {
|
||||
$this->{$key} = $value;
|
||||
if (property_exists($this, $key)) {
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -143,6 +154,7 @@ abstract class AbstractUser implements ArrayAccess, User
|
||||
* @param string $offset
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return array_key_exists($offset, $this->user);
|
||||
@@ -154,6 +166,7 @@ abstract class AbstractUser implements ArrayAccess, User
|
||||
* @param string $offset
|
||||
* @return mixed
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->user[$offset];
|
||||
@@ -166,6 +179,7 @@ abstract class AbstractUser implements ArrayAccess, User
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->user[$offset] = $value;
|
||||
@@ -177,8 +191,20 @@ abstract class AbstractUser implements ArrayAccess, User
|
||||
* @param string $offset
|
||||
* @return void
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->user[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user attribute value dynamically.
|
||||
*
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
return $this->attributes[$key] ?? null;
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ interface Provider
|
||||
/**
|
||||
* Redirect the user to the authentication page for the provider.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function redirect();
|
||||
|
||||
|
@@ -7,6 +7,7 @@ use Laravel\Socialite\Contracts\Factory;
|
||||
|
||||
/**
|
||||
* @method static \Laravel\Socialite\Contracts\Provider driver(string $driver = null)
|
||||
*
|
||||
* @see \Laravel\Socialite\SocialiteManager
|
||||
*/
|
||||
class Socialite extends Facade
|
||||
|
@@ -4,7 +4,6 @@ namespace Laravel\Socialite\One;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use InvalidArgumentException;
|
||||
use Laravel\Socialite\Contracts\Provider as ProviderContract;
|
||||
use League\OAuth1\Client\Credentials\TokenCredentials;
|
||||
use League\OAuth1\Client\Server\Server;
|
||||
@@ -64,12 +63,12 @@ abstract class AbstractProvider implements ProviderContract
|
||||
*
|
||||
* @return \Laravel\Socialite\One\User
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \Laravel\Socialite\One\MissingVerifierException
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
if (! $this->hasNecessaryVerifier()) {
|
||||
throw new InvalidArgumentException('Invalid request. Missing OAuth verifier.');
|
||||
throw new MissingVerifierException('Invalid request. Missing OAuth verifier.');
|
||||
}
|
||||
|
||||
$token = $this->getToken();
|
||||
@@ -129,6 +128,10 @@ abstract class AbstractProvider implements ProviderContract
|
||||
{
|
||||
$temp = $this->request->session()->get('oauth.temp');
|
||||
|
||||
if (! $temp) {
|
||||
throw new MissingTemporaryCredentialsException('Missing temporary OAuth credentials.');
|
||||
}
|
||||
|
||||
return $this->server->getTokenCredentials(
|
||||
$temp, $this->request->get('oauth_token'), $this->request->get('oauth_verifier')
|
||||
);
|
||||
@@ -141,7 +144,7 @@ abstract class AbstractProvider implements ProviderContract
|
||||
*/
|
||||
protected function hasNecessaryVerifier()
|
||||
{
|
||||
return $this->request->has('oauth_token') && $this->request->has('oauth_verifier');
|
||||
return $this->request->has(['oauth_token', 'oauth_verifier']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
10
vendor/laravel/socialite/src/One/MissingTemporaryCredentialsException.php
vendored
Normal file
10
vendor/laravel/socialite/src/One/MissingTemporaryCredentialsException.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\One;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class MissingTemporaryCredentialsException extends InvalidArgumentException
|
||||
{
|
||||
//
|
||||
}
|
10
vendor/laravel/socialite/src/One/MissingVerifierException.php
vendored
Normal file
10
vendor/laravel/socialite/src/One/MissingVerifierException.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\One;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class MissingVerifierException extends InvalidArgumentException
|
||||
{
|
||||
//
|
||||
}
|
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Laravel\Socialite\One;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class TwitterProvider extends AbstractProvider
|
||||
{
|
||||
/**
|
||||
@@ -12,7 +10,7 @@ class TwitterProvider extends AbstractProvider
|
||||
public function user()
|
||||
{
|
||||
if (! $this->hasNecessaryVerifier()) {
|
||||
throw new InvalidArgumentException('Invalid request. Missing OAuth verifier.');
|
||||
throw new MissingVerifierException('Invalid request. Missing OAuth verifier.');
|
||||
}
|
||||
|
||||
$user = $this->server->getUserDetails($token = $this->getToken(), $this->shouldBypassCache($token->getIdentifier(), $token->getSecret()));
|
||||
@@ -34,4 +32,15 @@ class TwitterProvider extends AbstractProvider
|
||||
'avatar_original' => str_replace('_normal', '', $user->imageUrl),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the access level the application should request to the user account.
|
||||
*
|
||||
* @param string $scope
|
||||
* @return void
|
||||
*/
|
||||
public function scope(string $scope)
|
||||
{
|
||||
$this->server->setApplicationScope($scope);
|
||||
}
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ use Laravel\Socialite\Two\GithubProvider;
|
||||
use Laravel\Socialite\Two\GitlabProvider;
|
||||
use Laravel\Socialite\Two\GoogleProvider;
|
||||
use Laravel\Socialite\Two\LinkedInProvider;
|
||||
use Laravel\Socialite\Two\TwitterProvider as TwitterOAuth2Provider;
|
||||
use League\OAuth1\Client\Server\Twitter as TwitterServer;
|
||||
|
||||
class SocialiteManager extends Manager implements Contracts\Factory
|
||||
@@ -35,7 +36,7 @@ class SocialiteManager extends Manager implements Contracts\Factory
|
||||
*/
|
||||
protected function createGithubDriver()
|
||||
{
|
||||
$config = $this->app->make('config')['services.github'];
|
||||
$config = $this->config->get('services.github');
|
||||
|
||||
return $this->buildProvider(
|
||||
GithubProvider::class, $config
|
||||
@@ -49,7 +50,7 @@ class SocialiteManager extends Manager implements Contracts\Factory
|
||||
*/
|
||||
protected function createFacebookDriver()
|
||||
{
|
||||
$config = $this->app->make('config')['services.facebook'];
|
||||
$config = $this->config->get('services.facebook');
|
||||
|
||||
return $this->buildProvider(
|
||||
FacebookProvider::class, $config
|
||||
@@ -63,7 +64,7 @@ class SocialiteManager extends Manager implements Contracts\Factory
|
||||
*/
|
||||
protected function createGoogleDriver()
|
||||
{
|
||||
$config = $this->app->make('config')['services.google'];
|
||||
$config = $this->config->get('services.google');
|
||||
|
||||
return $this->buildProvider(
|
||||
GoogleProvider::class, $config
|
||||
@@ -77,7 +78,7 @@ class SocialiteManager extends Manager implements Contracts\Factory
|
||||
*/
|
||||
protected function createLinkedinDriver()
|
||||
{
|
||||
$config = $this->app->make('config')['services.linkedin'];
|
||||
$config = $this->config->get('services.linkedin');
|
||||
|
||||
return $this->buildProvider(
|
||||
LinkedInProvider::class, $config
|
||||
@@ -91,7 +92,7 @@ class SocialiteManager extends Manager implements Contracts\Factory
|
||||
*/
|
||||
protected function createBitbucketDriver()
|
||||
{
|
||||
$config = $this->app->make('config')['services.bitbucket'];
|
||||
$config = $this->config->get('services.bitbucket');
|
||||
|
||||
return $this->buildProvider(
|
||||
BitbucketProvider::class, $config
|
||||
@@ -105,10 +106,42 @@ class SocialiteManager extends Manager implements Contracts\Factory
|
||||
*/
|
||||
protected function createGitlabDriver()
|
||||
{
|
||||
$config = $this->app->make('config')['services.gitlab'];
|
||||
$config = $this->config->get('services.gitlab');
|
||||
|
||||
return $this->buildProvider(
|
||||
GitlabProvider::class, $config
|
||||
)->setHost($config['host'] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the specified driver.
|
||||
*
|
||||
* @return \Laravel\Socialite\One\AbstractProvider|\Laravel\Socialite\Two\AbstractProvider
|
||||
*/
|
||||
protected function createTwitterDriver()
|
||||
{
|
||||
$config = $this->config->get('services.twitter');
|
||||
|
||||
if (($config['oauth'] ?? null) === 2) {
|
||||
return $this->createTwitterOAuth2Driver();
|
||||
}
|
||||
|
||||
return new TwitterProvider(
|
||||
$this->container->make('request'), new TwitterServer($this->formatConfig($config))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the specified driver.
|
||||
*
|
||||
* @return \Laravel\Socialite\Two\AbstractProvider
|
||||
*/
|
||||
protected function createTwitterOAuth2Driver()
|
||||
{
|
||||
$config = $this->config->get('services.twitter') ?? $this->config->get('services.twitter-oauth-2');
|
||||
|
||||
return $this->buildProvider(
|
||||
TwitterOAuth2Provider::class, $config
|
||||
);
|
||||
}
|
||||
|
||||
@@ -122,26 +155,12 @@ class SocialiteManager extends Manager implements Contracts\Factory
|
||||
public function buildProvider($provider, $config)
|
||||
{
|
||||
return new $provider(
|
||||
$this->app->make('request'), $config['client_id'],
|
||||
$this->container->make('request'), $config['client_id'],
|
||||
$config['client_secret'], $this->formatRedirectUrl($config),
|
||||
Arr::get($config, 'guzzle', [])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the specified driver.
|
||||
*
|
||||
* @return \Laravel\Socialite\One\AbstractProvider
|
||||
*/
|
||||
protected function createTwitterDriver()
|
||||
{
|
||||
$config = $this->app->make('config')['services.twitter'];
|
||||
|
||||
return new TwitterProvider(
|
||||
$this->app->make('request'), new TwitterServer($this->formatConfig($config))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the server configuration.
|
||||
*
|
||||
@@ -167,11 +186,37 @@ class SocialiteManager extends Manager implements Contracts\Factory
|
||||
{
|
||||
$redirect = value($config['redirect']);
|
||||
|
||||
return Str::startsWith($redirect, '/')
|
||||
? $this->app->make('url')->to($redirect)
|
||||
return Str::startsWith($redirect ?? '', '/')
|
||||
? $this->container->make('url')->to($redirect)
|
||||
: $redirect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget all of the resolved driver instances.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function forgetDrivers()
|
||||
{
|
||||
$this->drivers = [];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the container instance used by the manager.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return $this
|
||||
*/
|
||||
public function setContainer($container)
|
||||
{
|
||||
$this->app = $container;
|
||||
$this->container = $container;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default driver name.
|
||||
*
|
||||
|
@@ -2,10 +2,11 @@
|
||||
|
||||
namespace Laravel\Socialite;
|
||||
|
||||
use Illuminate\Contracts\Support\DeferrableProvider;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Laravel\Socialite\Contracts\Factory;
|
||||
|
||||
class SocialiteServiceProvider extends ServiceProvider
|
||||
class SocialiteServiceProvider extends ServiceProvider implements DeferrableProvider
|
||||
{
|
||||
/**
|
||||
* Register the service provider.
|
||||
@@ -28,14 +29,4 @@ class SocialiteServiceProvider extends ServiceProvider
|
||||
{
|
||||
return [Factory::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the provider is deferred.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDeferred()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
@@ -81,6 +82,13 @@ abstract class AbstractProvider implements ProviderContract
|
||||
*/
|
||||
protected $stateless = false;
|
||||
|
||||
/**
|
||||
* Indicates if PKCE should be used.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $usesPKCE = false;
|
||||
|
||||
/**
|
||||
* The custom Guzzle configuration options.
|
||||
*
|
||||
@@ -88,6 +96,13 @@ abstract class AbstractProvider implements ProviderContract
|
||||
*/
|
||||
protected $guzzle = [];
|
||||
|
||||
/**
|
||||
* The cached user instance.
|
||||
*
|
||||
* @var \Laravel\Socialite\Two\User|null
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Create a new provider instance.
|
||||
*
|
||||
@@ -151,6 +166,10 @@ abstract class AbstractProvider implements ProviderContract
|
||||
$this->request->session()->put('state', $state = $this->getState());
|
||||
}
|
||||
|
||||
if ($this->usesPKCE()) {
|
||||
$this->request->session()->put('code_verifier', $this->getCodeVerifier());
|
||||
}
|
||||
|
||||
return new RedirectResponse($this->getAuthUrl($state));
|
||||
}
|
||||
|
||||
@@ -185,6 +204,11 @@ abstract class AbstractProvider implements ProviderContract
|
||||
$fields['state'] = $state;
|
||||
}
|
||||
|
||||
if ($this->usesPKCE()) {
|
||||
$fields['code_challenge'] = $this->getCodeChallenge();
|
||||
$fields['code_challenge_method'] = $this->getCodeChallengeMethod();
|
||||
}
|
||||
|
||||
return array_merge($fields, $this->parameters);
|
||||
}
|
||||
|
||||
@@ -205,19 +229,24 @@ abstract class AbstractProvider implements ProviderContract
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
if ($this->user) {
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
if ($this->hasInvalidState()) {
|
||||
throw new InvalidStateException;
|
||||
}
|
||||
|
||||
$response = $this->getAccessTokenResponse($this->getCode());
|
||||
|
||||
$user = $this->mapUserToObject($this->getUserByToken(
|
||||
$this->user = $this->mapUserToObject($this->getUserByToken(
|
||||
$token = Arr::get($response, 'access_token')
|
||||
));
|
||||
|
||||
return $user->setToken($token)
|
||||
return $this->user->setToken($token)
|
||||
->setRefreshToken(Arr::get($response, 'refresh_token'))
|
||||
->setExpiresIn(Arr::get($response, 'expires_in'));
|
||||
->setExpiresIn(Arr::get($response, 'expires_in'))
|
||||
->setApprovedScopes(explode($this->scopeSeparator, Arr::get($response, 'scope', '')));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,7 +275,7 @@ abstract class AbstractProvider implements ProviderContract
|
||||
|
||||
$state = $this->request->session()->pull('state');
|
||||
|
||||
return ! (strlen($state) > 0 && $this->request->input('state') === $state);
|
||||
return empty($state) || $this->request->input('state') !== $state;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,13 +287,24 @@ abstract class AbstractProvider implements ProviderContract
|
||||
public function getAccessTokenResponse($code)
|
||||
{
|
||||
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
|
||||
'headers' => ['Accept' => 'application/json'],
|
||||
'form_params' => $this->getTokenFields($code),
|
||||
RequestOptions::HEADERS => $this->getTokenHeaders($code),
|
||||
RequestOptions::FORM_PARAMS => $this->getTokenFields($code),
|
||||
]);
|
||||
|
||||
return json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the headers for the access token request.
|
||||
*
|
||||
* @param string $code
|
||||
* @return array
|
||||
*/
|
||||
protected function getTokenHeaders($code)
|
||||
{
|
||||
return ['Accept' => 'application/json'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the POST fields for the token request.
|
||||
*
|
||||
@@ -273,12 +313,19 @@ abstract class AbstractProvider implements ProviderContract
|
||||
*/
|
||||
protected function getTokenFields($code)
|
||||
{
|
||||
return [
|
||||
$fields = [
|
||||
'grant_type' => 'authorization_code',
|
||||
'client_id' => $this->clientId,
|
||||
'client_secret' => $this->clientSecret,
|
||||
'code' => $code,
|
||||
'redirect_uri' => $this->redirectUrl,
|
||||
];
|
||||
|
||||
if ($this->usesPKCE()) {
|
||||
$fields['code_verifier'] = $this->request->session()->pull('code_verifier');
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -422,6 +469,60 @@ abstract class AbstractProvider implements ProviderContract
|
||||
return Str::random(40);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the provider uses PKCE.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function usesPKCE()
|
||||
{
|
||||
return $this->usesPKCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables PKCE for the provider.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function enablePKCE()
|
||||
{
|
||||
$this->usesPKCE = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random string of the right length for the PKCE code verifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCodeVerifier()
|
||||
{
|
||||
return Str::random(96);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the PKCE code challenge based on the PKCE code verifier in the session.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCodeChallenge()
|
||||
{
|
||||
$hashed = hash('sha256', $this->request->session()->get('code_verifier'), true);
|
||||
|
||||
return rtrim(strtr(base64_encode($hashed), '+/', '-_'), '=');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hash method used to calculate the PKCE code challenge.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCodeChallengeMethod()
|
||||
{
|
||||
return 'S256';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the custom parameters of the request.
|
||||
*
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
use Exception;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class BitbucketProvider extends AbstractProvider implements ProviderInterface
|
||||
@@ -42,13 +43,13 @@ class BitbucketProvider extends AbstractProvider implements ProviderInterface
|
||||
*/
|
||||
protected function getUserByToken($token)
|
||||
{
|
||||
$userUrl = 'https://api.bitbucket.org/2.0/user?access_token='.$token;
|
||||
|
||||
$response = $this->getHttpClient()->get($userUrl);
|
||||
$response = $this->getHttpClient()->get('https://api.bitbucket.org/2.0/user', [
|
||||
RequestOptions::QUERY => ['access_token' => $token],
|
||||
]);
|
||||
|
||||
$user = json_decode($response->getBody(), true);
|
||||
|
||||
if (in_array('email', $this->scopes)) {
|
||||
if (in_array('email', $this->scopes, true)) {
|
||||
$user['email'] = $this->getEmailByToken($token);
|
||||
}
|
||||
|
||||
@@ -74,7 +75,7 @@ class BitbucketProvider extends AbstractProvider implements ProviderInterface
|
||||
$emails = json_decode($response->getBody(), true);
|
||||
|
||||
foreach ($emails['values'] as $email) {
|
||||
if ($email['type'] == 'email' && $email['is_primary'] && $email['is_confirmed']) {
|
||||
if ($email['type'] === 'email' && $email['is_primary'] && $email['is_confirmed']) {
|
||||
return $email['email'];
|
||||
}
|
||||
}
|
||||
@@ -103,22 +104,11 @@ class BitbucketProvider extends AbstractProvider implements ProviderInterface
|
||||
public function getAccessToken($code)
|
||||
{
|
||||
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
|
||||
'auth' => [$this->clientId, $this->clientSecret],
|
||||
'headers' => ['Accept' => 'application/json'],
|
||||
'form_params' => $this->getTokenFields($code),
|
||||
RequestOptions::AUTH => [$this->clientId, $this->clientSecret],
|
||||
RequestOptions::HEADERS => ['Accept' => 'application/json'],
|
||||
RequestOptions::FORM_PARAMS => $this->getTokenFields($code),
|
||||
]);
|
||||
|
||||
return json_decode($response->getBody(), true)['access_token'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the POST fields for the token request.
|
||||
*
|
||||
* @param string $code
|
||||
* @return array
|
||||
*/
|
||||
protected function getTokenFields($code)
|
||||
{
|
||||
return parent::getTokenFields($code) + ['grant_type' => 'authorization_code'];
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class FacebookProvider extends AbstractProvider implements ProviderInterface
|
||||
@@ -48,6 +49,13 @@ class FacebookProvider extends AbstractProvider implements ProviderInterface
|
||||
*/
|
||||
protected $reRequest = false;
|
||||
|
||||
/**
|
||||
* The access token that was last used to retrieve a user.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $lastToken;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -70,7 +78,7 @@ class FacebookProvider extends AbstractProvider implements ProviderInterface
|
||||
public function getAccessTokenResponse($code)
|
||||
{
|
||||
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
|
||||
'form_params' => $this->getTokenFields($code),
|
||||
RequestOptions::FORM_PARAMS => $this->getTokenFields($code),
|
||||
]);
|
||||
|
||||
$data = json_decode($response->getBody(), true);
|
||||
@@ -83,18 +91,22 @@ class FacebookProvider extends AbstractProvider implements ProviderInterface
|
||||
*/
|
||||
protected function getUserByToken($token)
|
||||
{
|
||||
$meUrl = $this->graphUrl.'/'.$this->version.'/me?access_token='.$token.'&fields='.implode(',', $this->fields);
|
||||
$this->lastToken = $token;
|
||||
|
||||
$params = [
|
||||
'access_token' => $token,
|
||||
'fields' => implode(',', $this->fields),
|
||||
];
|
||||
|
||||
if (! empty($this->clientSecret)) {
|
||||
$appSecretProof = hash_hmac('sha256', $token, $this->clientSecret);
|
||||
|
||||
$meUrl .= '&appsecret_proof='.$appSecretProof;
|
||||
$params['appsecret_proof'] = hash_hmac('sha256', $token, $this->clientSecret);
|
||||
}
|
||||
|
||||
$response = $this->getHttpClient()->get($meUrl, [
|
||||
'headers' => [
|
||||
$response = $this->getHttpClient()->get($this->graphUrl.'/'.$this->version.'/me', [
|
||||
RequestOptions::HEADERS => [
|
||||
'Accept' => 'application/json',
|
||||
],
|
||||
RequestOptions::QUERY => $params,
|
||||
]);
|
||||
|
||||
return json_decode($response->getBody(), true);
|
||||
@@ -173,6 +185,16 @@ class FacebookProvider extends AbstractProvider implements ProviderInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last access token used.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function lastToken()
|
||||
{
|
||||
return $this->lastToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify which graph version should be used.
|
||||
*
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
use Exception;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class GithubProvider extends AbstractProvider implements ProviderInterface
|
||||
@@ -43,7 +44,7 @@ class GithubProvider extends AbstractProvider implements ProviderInterface
|
||||
|
||||
$user = json_decode($response->getBody(), true);
|
||||
|
||||
if (in_array('user:email', $this->scopes)) {
|
||||
if (in_array('user:email', $this->scopes, true)) {
|
||||
$user['email'] = $this->getEmailByToken($token);
|
||||
}
|
||||
|
||||
@@ -92,13 +93,13 @@ class GithubProvider extends AbstractProvider implements ProviderInterface
|
||||
/**
|
||||
* Get the default options for an HTTP request.
|
||||
*
|
||||
* @param string $token
|
||||
* @param string $token
|
||||
* @return array
|
||||
*/
|
||||
protected function getRequestOptions($token)
|
||||
{
|
||||
return [
|
||||
'headers' => [
|
||||
RequestOptions::HEADERS => [
|
||||
'Accept' => 'application/vnd.github.v3+json',
|
||||
'Authorization' => 'token '.$token,
|
||||
],
|
||||
|
@@ -2,14 +2,52 @@
|
||||
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
use GuzzleHttp\RequestOptions;
|
||||
|
||||
class GitlabProvider extends AbstractProvider implements ProviderInterface
|
||||
{
|
||||
/**
|
||||
* The scopes being requested.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $scopes = ['read_user'];
|
||||
|
||||
/**
|
||||
* The separating character for the requested scopes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scopeSeparator = ' ';
|
||||
|
||||
/**
|
||||
* The Gitlab instance host.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $host = 'https://gitlab.com';
|
||||
|
||||
/**
|
||||
* Set the Gitlab instance host.
|
||||
*
|
||||
* @param string|null $host
|
||||
* @return $this
|
||||
*/
|
||||
public function setHost($host)
|
||||
{
|
||||
if (! empty($host)) {
|
||||
$this->host = rtrim($host, '/');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAuthUrl($state)
|
||||
{
|
||||
return $this->buildAuthUrlFromBase('https://gitlab.com/oauth/authorize', $state);
|
||||
return $this->buildAuthUrlFromBase($this->host.'/oauth/authorize', $state);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -17,7 +55,7 @@ class GitlabProvider extends AbstractProvider implements ProviderInterface
|
||||
*/
|
||||
protected function getTokenUrl()
|
||||
{
|
||||
return 'https://gitlab.com/oauth/token';
|
||||
return $this->host.'/oauth/token';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,13 +63,11 @@ class GitlabProvider extends AbstractProvider implements ProviderInterface
|
||||
*/
|
||||
protected function getUserByToken($token)
|
||||
{
|
||||
$userUrl = 'https://gitlab.com/api/v3/user?access_token='.$token;
|
||||
$response = $this->getHttpClient()->get($this->host.'/api/v3/user', [
|
||||
RequestOptions::QUERY => ['access_token' => $token],
|
||||
]);
|
||||
|
||||
$response = $this->getHttpClient()->get($userUrl);
|
||||
|
||||
$user = json_decode($response->getBody(), true);
|
||||
|
||||
return $user;
|
||||
return json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,12 +83,4 @@ class GitlabProvider extends AbstractProvider implements ProviderInterface
|
||||
'avatar' => $user['avatar_url'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTokenFields($code)
|
||||
{
|
||||
return parent::getTokenFields($code) + ['grant_type' => 'authorization_code'];
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class GoogleProvider extends AbstractProvider implements ProviderInterface
|
||||
@@ -40,29 +41,16 @@ class GoogleProvider extends AbstractProvider implements ProviderInterface
|
||||
return 'https://www.googleapis.com/oauth2/v4/token';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the POST fields for the token request.
|
||||
*
|
||||
* @param string $code
|
||||
* @return array
|
||||
*/
|
||||
protected function getTokenFields($code)
|
||||
{
|
||||
return Arr::add(
|
||||
parent::getTokenFields($code), 'grant_type', 'authorization_code'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getUserByToken($token)
|
||||
{
|
||||
$response = $this->getHttpClient()->get('https://www.googleapis.com/oauth2/v3/userinfo', [
|
||||
'query' => [
|
||||
RequestOptions::QUERY => [
|
||||
'prettyPrint' => 'false',
|
||||
],
|
||||
'headers' => [
|
||||
RequestOptions::HEADERS => [
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
],
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class LinkedInProvider extends AbstractProvider implements ProviderInterface
|
||||
@@ -36,17 +37,6 @@ class LinkedInProvider extends AbstractProvider implements ProviderInterface
|
||||
return 'https://www.linkedin.com/oauth/v2/accessToken';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the POST fields for the token request.
|
||||
*
|
||||
* @param string $code
|
||||
* @return array
|
||||
*/
|
||||
protected function getTokenFields($code)
|
||||
{
|
||||
return parent::getTokenFields($code) + ['grant_type' => 'authorization_code'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -66,13 +56,14 @@ class LinkedInProvider extends AbstractProvider implements ProviderInterface
|
||||
*/
|
||||
protected function getBasicProfile($token)
|
||||
{
|
||||
$url = 'https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))';
|
||||
|
||||
$response = $this->getHttpClient()->get($url, [
|
||||
'headers' => [
|
||||
$response = $this->getHttpClient()->get('https://api.linkedin.com/v2/me', [
|
||||
RequestOptions::HEADERS => [
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
'X-RestLi-Protocol-Version' => '2.0.0',
|
||||
],
|
||||
RequestOptions::QUERY => [
|
||||
'projection' => '(id,firstName,lastName,profilePicture(displayImage~:playableStreams))',
|
||||
],
|
||||
]);
|
||||
|
||||
return (array) json_decode($response->getBody(), true);
|
||||
@@ -86,13 +77,15 @@ class LinkedInProvider extends AbstractProvider implements ProviderInterface
|
||||
*/
|
||||
protected function getEmailAddress($token)
|
||||
{
|
||||
$url = 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))';
|
||||
|
||||
$response = $this->getHttpClient()->get($url, [
|
||||
'headers' => [
|
||||
$response = $this->getHttpClient()->get('https://api.linkedin.com/v2/emailAddress', [
|
||||
RequestOptions::HEADERS => [
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
'X-RestLi-Protocol-Version' => '2.0.0',
|
||||
],
|
||||
RequestOptions::QUERY => [
|
||||
'q' => 'members',
|
||||
'projection' => '(elements*(handle~))',
|
||||
],
|
||||
]);
|
||||
|
||||
return (array) Arr::get((array) json_decode($response->getBody(), true), 'elements.0.handle~');
|
||||
|
107
vendor/laravel/socialite/src/Two/TwitterProvider.php
vendored
Normal file
107
vendor/laravel/socialite/src/Two/TwitterProvider.php
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class TwitterProvider extends AbstractProvider
|
||||
{
|
||||
/**
|
||||
* The scopes being requested.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $scopes = ['users.read', 'tweet.read'];
|
||||
|
||||
/**
|
||||
* Indicates if PKCE should be used.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $usesPKCE = true;
|
||||
|
||||
/**
|
||||
* The separating character for the requested scopes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scopeSeparator = ' ';
|
||||
|
||||
/**
|
||||
* The query encoding format.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $encodingType = PHP_QUERY_RFC3986;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAuthUrl($state)
|
||||
{
|
||||
return $this->buildAuthUrlFromBase('https://twitter.com/i/oauth2/authorize', $state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTokenUrl()
|
||||
{
|
||||
return 'https://api.twitter.com/2/oauth2/token';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getUserByToken($token)
|
||||
{
|
||||
$response = $this->getHttpClient()->get('https://api.twitter.com/2/users/me', [
|
||||
RequestOptions::HEADERS => ['Authorization' => 'Bearer '.$token],
|
||||
RequestOptions::QUERY => ['user.fields' => 'profile_image_url'],
|
||||
]);
|
||||
|
||||
return Arr::get(json_decode($response->getBody(), true), 'data');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function mapUserToObject(array $user)
|
||||
{
|
||||
return (new User)->setRaw($user)->map([
|
||||
'id' => $user['id'],
|
||||
'nickname' => $user['username'],
|
||||
'name' => $user['name'],
|
||||
'avatar' => $user['profile_image_url'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAccessTokenResponse($code)
|
||||
{
|
||||
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
|
||||
RequestOptions::HEADERS => ['Accept' => 'application/json'],
|
||||
RequestOptions::AUTH => [$this->clientId, $this->clientSecret],
|
||||
RequestOptions::FORM_PARAMS => $this->getTokenFields($code),
|
||||
]);
|
||||
|
||||
return json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getCodeFields($state = null)
|
||||
{
|
||||
$fields = parent::getCodeFields($state);
|
||||
|
||||
if ($this->isStateless()) {
|
||||
$fields['state'] = 'state';
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
}
|
20
vendor/laravel/socialite/src/Two/User.php
vendored
20
vendor/laravel/socialite/src/Two/User.php
vendored
@@ -27,6 +27,13 @@ class User extends AbstractUser
|
||||
*/
|
||||
public $expiresIn;
|
||||
|
||||
/**
|
||||
* The scopes the user authorized. The approved scopes may be a subset of the requested scopes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $approvedScopes;
|
||||
|
||||
/**
|
||||
* Set the token on the user.
|
||||
*
|
||||
@@ -65,4 +72,17 @@ class User extends AbstractUser
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the scopes that were approved by the user during authentication.
|
||||
*
|
||||
* @param array $approvedScopes
|
||||
* @return $this
|
||||
*/
|
||||
public function setApprovedScopes($approvedScopes)
|
||||
{
|
||||
$this->approvedScopes = $approvedScopes;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user