Laravel OAuth2 client package for single sign-on (SSO) authentication with Fortify/Jetstream integration
larawizards/lara-oauth2-client is a Laravel package for laravel oauth2 client package for single sign-on (sso) authentication with fortify/jetstream integration.
It currently has 0 GitHub stars and 1 downloads on Packagist (latest version 1.0.0).
Install it with composer require larawizards/lara-oauth2-client.
Discover more Laravel packages by larawizards
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel package for OAuth2 client authentication with single sign-on (SSO) support, compatible with Laravel 10, 11, and 12. Includes seamless integration with Laravel Fortify and Jetstream.
You can install the package via Composer:
composer require larawizards/lara-oauth2-client
Install the package:
composer require larawizards/lara-oauth2-client
Publish configuration:
php artisan lara-oauth2-client:install
Configure your .env file:
OAUTH2_CLIENT_ID=your-client-id
OAUTH2_CLIENT_SECRET=your-client-secret
OAUTH2_REDIRECT_URI=http://your-app.com/oauth2/callback
OAUTH2_AUTHORIZATION_URL=https://your-provider.com/oauth/authorize
OAUTH2_TOKEN_URL=https://your-provider.com/oauth/token
OAUTH2_USER_INFO_URL=https://your-provider.com/oauth/userinfo
OAUTH2_SCOPES=openid profile email
Run migrations:
php artisan migrate
For complete configuration instructions, including:
See CONFIGURATION.md for detailed instructions.
The package automatically registers routes for OAuth2 authentication:
GET /oauth2/redirect - Redirects to OAuth2 providerGET /oauth2/callback - Handles OAuth2 callbackPOST /oauth2/logout - Logout and optionally revoke tokensGET /login/sso - SSO login page (if enabled)Simply redirect users to the SSO login route:
return redirect()->route('login.sso');
Or use the OAuth2 redirect directly:
return redirect()->route('oauth2.redirect');
Use the oauth2.auth middleware to protect routes:
Route::middleware(['oauth2.auth'])->group(function () {
Route::get('/dashboard', function () {
return view('dashboard');
});
});
The package automatically maps OAuth2 user attributes to your user model. You can customize the mapping in config/lara-oauth2-client.php:
'user_mapping' => [
'id' => 'oauth2_id',
'email' => 'email',
'name' => 'name',
'first_name' => 'first_name',
'last_name' => 'last_name',
'avatar' => 'avatar',
],
Make sure your user model has the necessary columns. You may need to create a migration:
Schema::table('users', function (Blueprint $table) {
$table->string('oauth2_id')->nullable()->unique();
$table->string('avatar')->nullable();
});
.env:OAUTH2_FORTIFY_ENABLED=true
.env:OAUTH2_JETSTREAM_ENABLED=true
php artisan jetstream:install livewire
# or
php artisan jetstream:install inertia
Publish the views to customize them:
php artisan vendor:publish --tag=lara-oauth2-client-views
Views will be published to resources/views/vendor/lara-oauth2-client/.
You can also use the OAuth2 client directly:
use Larawizards\LaraOAuth2Client\OAuth2Client;
$client = app(OAuth2Client::class);
// Get authorization URL
$authUrl = $client->getAuthorizationUrl();
// Get access token (after receiving authorization code)
$tokenData = $client->getAccessToken($code, $state);
// Get user info
$userInfo = $client->getUserInfo($tokenData['access_token']);
// Refresh token
$newTokenData = $client->refreshAccessToken($refreshToken);
All configuration options are available in config/lara-oauth2-client.php:
| Option | Description | Default |
|--------|-------------|---------|
| client_id | OAuth2 client ID | - |
| client_secret | OAuth2 client secret | - |
| redirect_uri | OAuth2 redirect URI | /oauth2/callback |
| authorization_url | OAuth2 authorization endpoint | - |
| token_url | OAuth2 token endpoint | - |
| user_info_url | OAuth2 user info endpoint | - |
| scopes | OAuth2 scopes | ['openid', 'profile', 'email'] |
| route_prefix | Route prefix for OAuth2 routes | oauth2 |
| auto_create_users | Automatically create users if they don't exist | true |
| fortify_enabled | Enable Fortify integration | false |
| jetstream_enabled | Enable Jetstream integration | false |
| sso_login_enabled | Enable SSO login page | true |
Run the test suite:
composer test
Or with PHPUnit:
vendor/bin/phpunit
For detailed testing instructions, see TESTING.md.
Please see CHANGELOG for more information on what has changed recently.
Contributions are welcome! Please feel free to submit a Pull Request.
The MIT License (MIT). Please see License File for more information.
For support, please open an issue on GitHub or contact [email protected].