matt-allan / passport-socialite
A socialite driver for Passport
Installs: 4 452
Dependents: 0
Suggesters: 0
Security: 0
Stars: 38
Watchers: 1
Forks: 5
Open Issues: 0
Requires
- php: >=7.3
- illuminate/support: ^6.0|^7.0|^8.0
- laravel/socialite: ^5.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15.6
- matt-allan/laravel-code-style: ^0.6.0
- orchestra/testbench: ^3.8|^4.0
- phpunit/phpunit: ^8.0
README
A Laravel Socialite driver for authenticating with Laravel Passport OAuth servers.
Installation
This package can be installed using Composer. The Socialite package will also be installed if it is not already installed.
composer require matt-allan/passport-socialite
Configuration
Before using this driver, you will need to add credentials for the Passport server. These credentials should be placed in your config/services.php
configuration file, and should use the key passport
. For example:
'passport' => [ 'client_id' => env('PASSPORT_CLIENT_ID'), 'client_secret' => env('PASSPORT_CLIENT_SECRET'), 'url' => env('PASSPORT_URL'), 'redirect' => env('PASSPORT_REDIRECT'), ],
Usage
The Passport driver works identically to the other Socialite drivers. All of the methods mentioned in the official documentation are available.
You can access the passport driver using the Socialite
facade:
<?php namespace App\Http\Controllers\Auth; use Socialite; class LoginController extends Controller { /** * Redirect the user to the Passport server's authentication page. * * @return \Illuminate\Http\Response */ public function redirectToProvider() { return Socialite::driver('passport')->redirect(); } /** * Obtain the user information from the Passport server. * * @return \Illuminate\Http\Response */ public function handleProviderCallback() { $user = Socialite::driver('passport')->user(); // $user->token; } }
The current user's details will be retrieved from the default api/user
route.
In addition to the standard Socialite methods a refresh
method is available to easily refresh expired tokens. The refresh
method accepts a refresh token and returns an updated User
with new access and refresh tokens if the token is refreshed successfully.
$user = Socialite::driver('passport')->refresh($refreshToken);
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.