update 1.0.8.0
Commits for version update
This commit is contained in:
21
vendor/laravel/socialite/LICENSE.txt
vendored
Normal file
21
vendor/laravel/socialite/LICENSE.txt
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
39
vendor/laravel/socialite/composer.json
vendored
Normal file
39
vendor/laravel/socialite/composer.json
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "laravel/socialite",
|
||||
"description": "Laravel wrapper around OAuth 1 & OAuth 2 libraries.",
|
||||
"keywords": ["oauth", "laravel"],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylorotwell@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"guzzlehttp/guzzle": "~5.0|~6.0",
|
||||
"illuminate/contracts": "~5.0",
|
||||
"illuminate/http": "~5.0",
|
||||
"illuminate/support": "~5.0",
|
||||
"league/oauth1-client": "~1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "~0.9",
|
||||
"phpunit/phpunit": "~4.0|~5.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Laravel\\Socialite\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
136
vendor/laravel/socialite/readme.md
vendored
Normal file
136
vendor/laravel/socialite/readme.md
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
# Laravel Socialite
|
||||
|
||||
[](https://travis-ci.org/laravel/socialite)
|
||||
[](https://packagist.org/packages/laravel/socialite)
|
||||
[](https://packagist.org/packages/laravel/socialite)
|
||||
[](https://packagist.org/packages/laravel/socialite)
|
||||
[](https://packagist.org/packages/laravel/socialite)
|
||||
[](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.
|
||||
|
||||
To get started with Socialite, add to your `composer.json` file as a dependency:
|
||||
|
||||
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();
|
||||
```
|
183
vendor/laravel/socialite/src/AbstractUser.php
vendored
Normal file
183
vendor/laravel/socialite/src/AbstractUser.php
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite;
|
||||
|
||||
use ArrayAccess;
|
||||
|
||||
abstract class AbstractUser implements ArrayAccess, Contracts\User
|
||||
{
|
||||
/**
|
||||
* The unique identifier for the user.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The user's nickname / username.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $nickname;
|
||||
|
||||
/**
|
||||
* The user's full name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* The user's e-mail address.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $email;
|
||||
|
||||
/**
|
||||
* The user's avatar image URL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $avatar;
|
||||
|
||||
/**
|
||||
* The user's raw attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Get the unique identifier for the user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the nickname / username for the user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNickname()
|
||||
{
|
||||
return $this->nickname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full name of the user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the e-mail address of the user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the avatar / image URL for the user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param array $user
|
||||
* @return $this
|
||||
*/
|
||||
public function setRaw(array $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the given array onto the user's properties.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return $this
|
||||
*/
|
||||
public function map(array $attributes)
|
||||
{
|
||||
foreach ($attributes as $key => $value) {
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given raw user attribute exists.
|
||||
*
|
||||
* @param string $offset
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return array_key_exists($offset, $this->user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the given key from the raw user.
|
||||
*
|
||||
* @param string $offset
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->user[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given attribute on the raw user array.
|
||||
*
|
||||
* @param string $offset
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->user[$offset] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset the given value from the raw user array.
|
||||
*
|
||||
* @param string $offset
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->user[$offset]);
|
||||
}
|
||||
}
|
14
vendor/laravel/socialite/src/Contracts/Factory.php
vendored
Normal file
14
vendor/laravel/socialite/src/Contracts/Factory.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\Contracts;
|
||||
|
||||
interface Factory
|
||||
{
|
||||
/**
|
||||
* Get an OAuth provider implementation.
|
||||
*
|
||||
* @param string $driver
|
||||
* @return \Laravel\Socialite\Contracts\Provider
|
||||
*/
|
||||
public function driver($driver = null);
|
||||
}
|
20
vendor/laravel/socialite/src/Contracts/Provider.php
vendored
Normal file
20
vendor/laravel/socialite/src/Contracts/Provider.php
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\Contracts;
|
||||
|
||||
interface Provider
|
||||
{
|
||||
/**
|
||||
* Redirect the user to the authentication page for the provider.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
public function redirect();
|
||||
|
||||
/**
|
||||
* Get the User instance for the authenticated user.
|
||||
*
|
||||
* @return \Laravel\Socialite\Contracts\User
|
||||
*/
|
||||
public function user();
|
||||
}
|
41
vendor/laravel/socialite/src/Contracts/User.php
vendored
Normal file
41
vendor/laravel/socialite/src/Contracts/User.php
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\Contracts;
|
||||
|
||||
interface User
|
||||
{
|
||||
/**
|
||||
* Get the unique identifier for the user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId();
|
||||
|
||||
/**
|
||||
* Get the nickname / username for the user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNickname();
|
||||
|
||||
/**
|
||||
* Get the full name of the user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Get the e-mail address of the user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail();
|
||||
|
||||
/**
|
||||
* Get the avatar / image URL for the user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAvatar();
|
||||
}
|
21
vendor/laravel/socialite/src/Facades/Socialite.php
vendored
Normal file
21
vendor/laravel/socialite/src/Facades/Socialite.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @see \Laravel\Socialite\SocialiteManager
|
||||
*/
|
||||
class Socialite extends Facade
|
||||
{
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'Laravel\Socialite\Contracts\Factory';
|
||||
}
|
||||
}
|
113
vendor/laravel/socialite/src/One/AbstractProvider.php
vendored
Normal file
113
vendor/laravel/socialite/src/One/AbstractProvider.php
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\One;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use InvalidArgumentException;
|
||||
use League\OAuth1\Client\Server\Server;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Laravel\Socialite\Contracts\Provider as ProviderContract;
|
||||
|
||||
abstract class AbstractProvider implements ProviderContract
|
||||
{
|
||||
/**
|
||||
* The HTTP request instance.
|
||||
*
|
||||
* @var \Illuminate\Http\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* The OAuth server implementation.
|
||||
*
|
||||
* @var \League\OAuth1\Client\Server\Server
|
||||
*/
|
||||
protected $server;
|
||||
|
||||
/**
|
||||
* Create a new provider instance.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \League\OAuth1\Client\Server\Server $server
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Request $request, Server $server)
|
||||
{
|
||||
$this->server = $server;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect the user to the authentication page for the provider.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
public function redirect()
|
||||
{
|
||||
$this->request->session()->set(
|
||||
'oauth.temp', $temp = $this->server->getTemporaryCredentials()
|
||||
);
|
||||
|
||||
return new RedirectResponse($this->server->getAuthorizationUrl($temp));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the User instance for the authenticated user.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return \Laravel\Socialite\One\User
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
if (! $this->hasNecessaryVerifier()) {
|
||||
throw new InvalidArgumentException('Invalid request. Missing OAuth verifier.');
|
||||
}
|
||||
|
||||
$user = $this->server->getUserDetails($token = $this->getToken());
|
||||
|
||||
$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,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the token credentials for the request.
|
||||
*
|
||||
* @return \League\OAuth1\Client\Credentials\TokenCredentials
|
||||
*/
|
||||
protected function getToken()
|
||||
{
|
||||
$temp = $this->request->session()->get('oauth.temp');
|
||||
|
||||
return $this->server->getTokenCredentials(
|
||||
$temp, $this->request->get('oauth_token'), $this->request->get('oauth_verifier')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the request has the necessary OAuth verifier.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasNecessaryVerifier()
|
||||
{
|
||||
return $this->request->has('oauth_token') && $this->request->has('oauth_verifier');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the request instance.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return $this
|
||||
*/
|
||||
public function setRequest(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
8
vendor/laravel/socialite/src/One/BitbucketProvider.php
vendored
Normal file
8
vendor/laravel/socialite/src/One/BitbucketProvider.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\One;
|
||||
|
||||
class BitbucketProvider extends AbstractProvider
|
||||
{
|
||||
//
|
||||
}
|
34
vendor/laravel/socialite/src/One/TwitterProvider.php
vendored
Normal file
34
vendor/laravel/socialite/src/One/TwitterProvider.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\One;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class TwitterProvider extends AbstractProvider
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
if (! $this->hasNecessaryVerifier()) {
|
||||
throw new InvalidArgumentException('Invalid request. Missing OAuth verifier.');
|
||||
}
|
||||
|
||||
$user = $this->server->getUserDetails($token = $this->getToken());
|
||||
|
||||
$extraDetails = [
|
||||
'location' => $user->location,
|
||||
'description' => $user->description,
|
||||
];
|
||||
|
||||
$instance = (new User)->setRaw(array_merge($user->extra, $user->urls, $extraDetails))
|
||||
->setToken($token->getIdentifier(), $token->getSecret());
|
||||
|
||||
return $instance->map([
|
||||
'id' => $user->uid, 'nickname' => $user->nickname,
|
||||
'name' => $user->name, 'email' => $user->email, 'avatar' => $user->imageUrl,
|
||||
'avatar_original' => str_replace('_normal', '', $user->imageUrl),
|
||||
]);
|
||||
}
|
||||
}
|
37
vendor/laravel/socialite/src/One/User.php
vendored
Normal file
37
vendor/laravel/socialite/src/One/User.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\One;
|
||||
|
||||
use Laravel\Socialite\AbstractUser;
|
||||
|
||||
class User extends AbstractUser
|
||||
{
|
||||
/**
|
||||
* The user's access token.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $token;
|
||||
|
||||
/**
|
||||
* The user's access token secret.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $tokenSecret;
|
||||
|
||||
/**
|
||||
* Set the token on the user.
|
||||
*
|
||||
* @param string $token
|
||||
* @param string $tokenSecret
|
||||
* @return $this
|
||||
*/
|
||||
public function setToken($token, $tokenSecret)
|
||||
{
|
||||
$this->token = $token;
|
||||
$this->tokenSecret = $tokenSecret;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
150
vendor/laravel/socialite/src/SocialiteManager.php
vendored
Normal file
150
vendor/laravel/socialite/src/SocialiteManager.php
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
/**
|
||||
* Get a driver instance.
|
||||
*
|
||||
* @param string $driver
|
||||
* @return mixed
|
||||
*/
|
||||
public function with($driver)
|
||||
{
|
||||
return $this->driver($driver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the specified driver.
|
||||
*
|
||||
* @return \Laravel\Socialite\Two\AbstractProvider
|
||||
*/
|
||||
protected function createGithubDriver()
|
||||
{
|
||||
$config = $this->app['config']['services.github'];
|
||||
|
||||
return $this->buildProvider(
|
||||
'Laravel\Socialite\Two\GithubProvider', $config
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the specified driver.
|
||||
*
|
||||
* @return \Laravel\Socialite\Two\AbstractProvider
|
||||
*/
|
||||
protected function createFacebookDriver()
|
||||
{
|
||||
$config = $this->app['config']['services.facebook'];
|
||||
|
||||
return $this->buildProvider(
|
||||
'Laravel\Socialite\Two\FacebookProvider', $config
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the specified driver.
|
||||
*
|
||||
* @return \Laravel\Socialite\Two\AbstractProvider
|
||||
*/
|
||||
protected function createGoogleDriver()
|
||||
{
|
||||
$config = $this->app['config']['services.google'];
|
||||
|
||||
return $this->buildProvider(
|
||||
'Laravel\Socialite\Two\GoogleProvider', $config
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the specified driver.
|
||||
*
|
||||
* @return \Laravel\Socialite\Two\AbstractProvider
|
||||
*/
|
||||
protected function createLinkedinDriver()
|
||||
{
|
||||
$config = $this->app['config']['services.linkedin'];
|
||||
|
||||
return $this->buildProvider(
|
||||
'Laravel\Socialite\Two\LinkedInProvider', $config
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an OAuth 2 provider instance.
|
||||
*
|
||||
* @param string $provider
|
||||
* @param array $config
|
||||
* @return \Laravel\Socialite\Two\AbstractProvider
|
||||
*/
|
||||
public function buildProvider($provider, $config)
|
||||
{
|
||||
return new $provider(
|
||||
$this->app['request'], $config['client_id'],
|
||||
$config['client_secret'], $config['redirect']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the specified driver.
|
||||
*
|
||||
* @return \Laravel\Socialite\One\AbstractProvider
|
||||
*/
|
||||
protected function createTwitterDriver()
|
||||
{
|
||||
$config = $this->app['config']['services.twitter'];
|
||||
|
||||
return new TwitterProvider(
|
||||
$this->app['request'], new TwitterServer($this->formatConfig($config))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
public function formatConfig(array $config)
|
||||
{
|
||||
return array_merge([
|
||||
'identifier' => $config['client_id'],
|
||||
'secret' => $config['client_secret'],
|
||||
'callback_uri' => $config['redirect'],
|
||||
], $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default driver name.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultDriver()
|
||||
{
|
||||
throw new InvalidArgumentException('No Socialite driver was specified.');
|
||||
}
|
||||
}
|
37
vendor/laravel/socialite/src/SocialiteServiceProvider.php
vendored
Normal file
37
vendor/laravel/socialite/src/SocialiteServiceProvider.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class SocialiteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = true;
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('Laravel\Socialite\Contracts\Factory', function ($app) {
|
||||
return new SocialiteManager($app);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return ['Laravel\Socialite\Contracts\Factory'];
|
||||
}
|
||||
}
|
407
vendor/laravel/socialite/src/Two/AbstractProvider.php
vendored
Normal file
407
vendor/laravel/socialite/src/Two/AbstractProvider.php
vendored
Normal file
@@ -0,0 +1,407 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Request;
|
||||
use GuzzleHttp\ClientInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Laravel\Socialite\Contracts\Provider as ProviderContract;
|
||||
|
||||
abstract class AbstractProvider implements ProviderContract
|
||||
{
|
||||
/**
|
||||
* The HTTP request instance.
|
||||
*
|
||||
* @var \Illuminate\Http\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* The HTTP Client instance.
|
||||
*
|
||||
* @var \GuzzleHttp\Client
|
||||
*/
|
||||
protected $httpClient;
|
||||
|
||||
/**
|
||||
* The client ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $clientId;
|
||||
|
||||
/**
|
||||
* The client secret.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $clientSecret;
|
||||
|
||||
/**
|
||||
* The redirect URL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectUrl;
|
||||
|
||||
/**
|
||||
* The custom parameters to be sent with the request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $parameters = [];
|
||||
|
||||
/**
|
||||
* The scopes being requested.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $scopes = [];
|
||||
|
||||
/**
|
||||
* The separating character for the requested scopes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scopeSeparator = ',';
|
||||
|
||||
/**
|
||||
* The type of the encoding in the query.
|
||||
*
|
||||
* @var int Can be either PHP_QUERY_RFC3986 or PHP_QUERY_RFC1738.
|
||||
*/
|
||||
protected $encodingType = PHP_QUERY_RFC1738;
|
||||
|
||||
/**
|
||||
* Indicates if the session state should be utilized.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $stateless = false;
|
||||
|
||||
/**
|
||||
* Create a new provider instance.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $clientId
|
||||
* @param string $clientSecret
|
||||
* @param string $redirectUrl
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Request $request, $clientId, $clientSecret, $redirectUrl)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->clientId = $clientId;
|
||||
$this->redirectUrl = $redirectUrl;
|
||||
$this->clientSecret = $clientSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authentication URL for the provider.
|
||||
*
|
||||
* @param string $state
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getAuthUrl($state);
|
||||
|
||||
/**
|
||||
* Get the token URL for the provider.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getTokenUrl();
|
||||
|
||||
/**
|
||||
* Get the raw user for the given access token.
|
||||
*
|
||||
* @param string $token
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getUserByToken($token);
|
||||
|
||||
/**
|
||||
* Map the raw user array to a Socialite User instance.
|
||||
*
|
||||
* @param array $user
|
||||
* @return \Laravel\Socialite\Two\User
|
||||
*/
|
||||
abstract protected function mapUserToObject(array $user);
|
||||
|
||||
/**
|
||||
* Redirect the user of the application to the provider's authentication screen.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
public function redirect()
|
||||
{
|
||||
$state = null;
|
||||
|
||||
if ($this->usesState()) {
|
||||
$this->request->session()->set('state', $state = Str::random(40));
|
||||
}
|
||||
|
||||
return new RedirectResponse($this->getAuthUrl($state));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authentication URL for the provider.
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $state
|
||||
* @return string
|
||||
*/
|
||||
protected function buildAuthUrlFromBase($url, $state)
|
||||
{
|
||||
return $url.'?'.http_build_query($this->getCodeFields($state), '', '&', $this->encodingType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the GET parameters for the code request.
|
||||
*
|
||||
* @param string|null $state
|
||||
* @return array
|
||||
*/
|
||||
protected function getCodeFields($state = null)
|
||||
{
|
||||
$fields = [
|
||||
'client_id' => $this->clientId, 'redirect_uri' => $this->redirectUrl,
|
||||
'scope' => $this->formatScopes($this->scopes, $this->scopeSeparator),
|
||||
'response_type' => 'code',
|
||||
];
|
||||
|
||||
if ($this->usesState()) {
|
||||
$fields['state'] = $state;
|
||||
}
|
||||
|
||||
return array_merge($fields, $this->parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given scopes.
|
||||
*
|
||||
* @param array $scopes
|
||||
* @param string $scopeSeparator
|
||||
* @return string
|
||||
*/
|
||||
protected function formatScopes(array $scopes, $scopeSeparator)
|
||||
{
|
||||
return implode($scopeSeparator, $scopes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
if ($this->hasInvalidState()) {
|
||||
throw new InvalidStateException;
|
||||
}
|
||||
|
||||
$response = $this->getAccessTokenResponse($this->getCode());
|
||||
|
||||
$user = $this->mapUserToObject($this->getUserByToken(
|
||||
$token = Arr::get($response, 'access_token')
|
||||
));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the current request / session has a mismatching "state".
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasInvalidState()
|
||||
{
|
||||
if ($this->isStateless()) {
|
||||
return false;
|
||||
}
|
||||
//dd($this->request->all());
|
||||
$state = $this->request->input('state');
|
||||
\Session::put('state', $state);
|
||||
//$state = $this->request->session()->pull('state');
|
||||
|
||||
return ! (strlen($state) > 0 && $this->request->input('state') === $state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the access token response for the given code.
|
||||
*
|
||||
* @param string $code
|
||||
* @return array
|
||||
*/
|
||||
public function getAccessTokenResponse($code)
|
||||
{
|
||||
$postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body';
|
||||
|
||||
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
|
||||
'headers' => ['Accept' => 'application/json'],
|
||||
$postKey => $this->getTokenFields($code),
|
||||
]);
|
||||
|
||||
return json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the POST fields for the token request.
|
||||
*
|
||||
* @param string $code
|
||||
* @return array
|
||||
*/
|
||||
protected function getTokenFields($code)
|
||||
{
|
||||
return [
|
||||
'client_id' => $this->clientId, 'client_secret' => $this->clientSecret,
|
||||
'code' => $code, 'redirect_uri' => $this->redirectUrl,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the code from the request.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCode()
|
||||
{
|
||||
return $this->request->input('code');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the scopes of the requested access.
|
||||
*
|
||||
* @param array $scopes
|
||||
* @return $this
|
||||
*/
|
||||
public function scopes(array $scopes)
|
||||
{
|
||||
$this->scopes = array_unique(array_merge($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.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the request instance.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return $this
|
||||
*/
|
||||
public function setRequest(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the provider is operating with state.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function usesState()
|
||||
{
|
||||
return ! $this->stateless;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the provider is operating as stateless.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isStateless()
|
||||
{
|
||||
return $this->stateless;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates that the provider should operate as stateless.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function stateless()
|
||||
{
|
||||
$this->stateless = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the custom parameters of the request.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @return $this
|
||||
*/
|
||||
public function with(array $parameters)
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
174
vendor/laravel/socialite/src/Two/FacebookProvider.php
vendored
Normal file
174
vendor/laravel/socialite/src/Two/FacebookProvider.php
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use GuzzleHttp\ClientInterface;
|
||||
|
||||
class FacebookProvider extends AbstractProvider implements ProviderInterface
|
||||
{
|
||||
/**
|
||||
* The base Facebook Graph URL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $graphUrl = 'https://graph.facebook.com';
|
||||
|
||||
/**
|
||||
* The Graph API version for the request.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $version = 'v2.6';
|
||||
|
||||
/**
|
||||
* The user fields being requested.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fields = ['name', 'email', 'gender', 'verified'];
|
||||
|
||||
/**
|
||||
* The scopes being requested.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $scopes = ['email'];
|
||||
|
||||
/**
|
||||
* Display the dialog in a popup view.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $popup = false;
|
||||
|
||||
/**
|
||||
* Re-request a declined permission.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $reRequest = false;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAuthUrl($state)
|
||||
{
|
||||
return $this->buildAuthUrlFromBase('https://www.facebook.com/'.$this->version.'/dialog/oauth', $state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTokenUrl()
|
||||
{
|
||||
return $this->graphUrl.'/oauth/access_token';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAccessTokenResponse($code)
|
||||
{
|
||||
$postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body';
|
||||
|
||||
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
|
||||
$postKey => $this->getTokenFields($code),
|
||||
]);
|
||||
|
||||
$data = [];
|
||||
|
||||
parse_str($response->getBody(), $data);
|
||||
|
||||
return Arr::add($data, 'expires_in', Arr::pull($data, 'expires'));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getUserByToken($token)
|
||||
{
|
||||
$meUrl = $this->graphUrl.'/'.$this->version.'/me?access_token='.$token.'&fields='.implode(',', $this->fields);
|
||||
|
||||
if (! empty($this->clientSecret)) {
|
||||
$appSecretProof = hash_hmac('sha256', $token, $this->clientSecret);
|
||||
|
||||
$meUrl .= '&appsecret_proof='.$appSecretProof;
|
||||
}
|
||||
|
||||
$response = $this->getHttpClient()->get($meUrl, [
|
||||
'headers' => [
|
||||
'Accept' => 'application/json',
|
||||
],
|
||||
]);
|
||||
|
||||
return json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function mapUserToObject(array $user)
|
||||
{
|
||||
$avatarUrl = $this->graphUrl.'/'.$this->version.'/'.$user['id'].'/picture';
|
||||
|
||||
return (new User)->setRaw($user)->map([
|
||||
'id' => $user['id'], 'nickname' => null, 'name' => isset($user['name']) ? $user['name'] : null,
|
||||
'email' => isset($user['email']) ? $user['email'] : null, 'avatar' => $avatarUrl.'?type=normal',
|
||||
'avatar_original' => $avatarUrl.'?width=1920',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getCodeFields($state = null)
|
||||
{
|
||||
$fields = parent::getCodeFields($state);
|
||||
|
||||
if ($this->popup) {
|
||||
$fields['display'] = 'popup';
|
||||
}
|
||||
|
||||
if ($this->reRequest) {
|
||||
$fields['auth_type'] = 'rerequest';
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user fields to request from Facebook.
|
||||
*
|
||||
* @param array $fields
|
||||
* @return $this
|
||||
*/
|
||||
public function fields(array $fields)
|
||||
{
|
||||
$this->fields = $fields;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dialog to be displayed as a popup.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function asPopup()
|
||||
{
|
||||
$this->popup = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-request permissions which were previously declined.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function reRequest()
|
||||
{
|
||||
$this->reRequest = true;
|
||||
}
|
||||
}
|
102
vendor/laravel/socialite/src/Two/GithubProvider.php
vendored
Normal file
102
vendor/laravel/socialite/src/Two/GithubProvider.php
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class GithubProvider extends AbstractProvider implements ProviderInterface
|
||||
{
|
||||
/**
|
||||
* The scopes being requested.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $scopes = ['user:email'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAuthUrl($state)
|
||||
{
|
||||
return $this->buildAuthUrlFromBase('https://github.com/login/oauth/authorize', $state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTokenUrl()
|
||||
{
|
||||
return 'https://github.com/login/oauth/access_token';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getUserByToken($token)
|
||||
{
|
||||
$userUrl = 'https://api.github.com/user?access_token='.$token;
|
||||
|
||||
$response = $this->getHttpClient()->get(
|
||||
$userUrl, $this->getRequestOptions()
|
||||
);
|
||||
|
||||
$user = json_decode($response->getBody(), true);
|
||||
|
||||
if (in_array('user: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.github.com/user/emails?access_token='.$token;
|
||||
|
||||
try {
|
||||
$response = $this->getHttpClient()->get(
|
||||
$emailsUrl, $this->getRequestOptions()
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (json_decode($response->getBody(), true) as $email) {
|
||||
if ($email['primary'] && $email['verified']) {
|
||||
return $email['email'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default options for an HTTP request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getRequestOptions()
|
||||
{
|
||||
return [
|
||||
'headers' => [
|
||||
'Accept' => 'application/vnd.github.v3+json',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
84
vendor/laravel/socialite/src/Two/GoogleProvider.php
vendored
Normal file
84
vendor/laravel/socialite/src/Two/GoogleProvider.php
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class GoogleProvider extends AbstractProvider implements ProviderInterface
|
||||
{
|
||||
/**
|
||||
* The separating character for the requested scopes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scopeSeparator = ' ';
|
||||
|
||||
/**
|
||||
* The scopes being requested.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $scopes = [
|
||||
'openid',
|
||||
'profile',
|
||||
'email',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAuthUrl($state)
|
||||
{
|
||||
return $this->buildAuthUrlFromBase('https://accounts.google.com/o/oauth2/auth', $state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTokenUrl()
|
||||
{
|
||||
return 'https://accounts.google.com/o/oauth2/token';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the POST fields for the token request.
|
||||
*
|
||||
* @param string $code
|
||||
* @return array
|
||||
*/
|
||||
protected function getTokenFields($code)
|
||||
{
|
||||
return array_add(
|
||||
parent::getTokenFields($code), 'grant_type', 'authorization_code'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getUserByToken($token)
|
||||
{
|
||||
$response = $this->getHttpClient()->get('https://www.googleapis.com/plus/v1/people/me?', [
|
||||
'query' => [
|
||||
'prettyPrint' => 'false',
|
||||
],
|
||||
'headers' => [
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
],
|
||||
]);
|
||||
|
||||
return json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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'],
|
||||
]);
|
||||
}
|
||||
}
|
8
vendor/laravel/socialite/src/Two/InvalidStateException.php
vendored
Normal file
8
vendor/laravel/socialite/src/Two/InvalidStateException.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
class InvalidStateException extends \InvalidArgumentException
|
||||
{
|
||||
//
|
||||
}
|
104
vendor/laravel/socialite/src/Two/LinkedInProvider.php
vendored
Normal file
104
vendor/laravel/socialite/src/Two/LinkedInProvider.php
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class LinkedInProvider extends AbstractProvider implements ProviderInterface
|
||||
{
|
||||
/**
|
||||
* The scopes being requested.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fields = [
|
||||
'id', 'first-name', 'last-name', 'formatted-name',
|
||||
'email-address', 'headline', 'location', 'industry',
|
||||
'public-profile-url', 'picture-url', 'picture-urls::(original)',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAuthUrl($state)
|
||||
{
|
||||
return $this->buildAuthUrlFromBase('https://www.linkedin.com/oauth/v2/authorization', $state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTokenUrl()
|
||||
{
|
||||
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}
|
||||
*/
|
||||
protected function getUserByToken($token)
|
||||
{
|
||||
$fields = implode(',', $this->fields);
|
||||
|
||||
$url = 'https://api.linkedin.com/v1/people/~:('.$fields.')';
|
||||
|
||||
$response = $this->getHttpClient()->get($url, [
|
||||
'headers' => [
|
||||
'x-li-format' => 'json',
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
],
|
||||
]);
|
||||
|
||||
return json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user fields to request from LinkedIn.
|
||||
*
|
||||
* @param array $fields
|
||||
* @return $this
|
||||
*/
|
||||
public function fields(array $fields)
|
||||
{
|
||||
$this->fields = $fields;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
20
vendor/laravel/socialite/src/Two/ProviderInterface.php
vendored
Normal file
20
vendor/laravel/socialite/src/Two/ProviderInterface.php
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
interface ProviderInterface
|
||||
{
|
||||
/**
|
||||
* Redirect the user to the authentication page for the provider.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
public function redirect();
|
||||
|
||||
/**
|
||||
* Get the User instance for the authenticated user.
|
||||
*
|
||||
* @return \Laravel\Socialite\Two\User
|
||||
*/
|
||||
public function user();
|
||||
}
|
68
vendor/laravel/socialite/src/Two/User.php
vendored
Normal file
68
vendor/laravel/socialite/src/Two/User.php
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Socialite\Two;
|
||||
|
||||
use Laravel\Socialite\AbstractUser;
|
||||
|
||||
class User extends AbstractUser
|
||||
{
|
||||
/**
|
||||
* The user's access token.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param string $token
|
||||
* @return $this
|
||||
*/
|
||||
public function setToken($token)
|
||||
{
|
||||
$this->token = $token;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user