etsvthor / laravel-bifrost-bridge
Connect a laravel application with the Bifrost oauth2 server
Installs: 2 419
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ~8.1.0 | ~8.2.0 | ~8.3.0
- laravel/framework: ^10.0 | ^11.0
- laravel/socialite: ^5.1
- spatie/laravel-data: ^4.0
- spatie/laravel-permission: ^4.0 | ^5.0 | ^6.0
Suggests
- filament/notifications: Show filament notifications on login and logout
- laracasts/flash: Show flash messages on login and logout
- dev-master
- 1.1.0
- 1.0.1
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.7
- 0.5.6
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-support-filament-notifications
- dev-support-laravel-11
- dev-docs/spatie-permissions-separate
- dev-update/php8.2
- dev-feature/bifrost-login-event
- dev-composer-php8.x
- dev-changelog
This package is auto-updated.
Last update: 2024-11-08 05:44:38 UTC
README
Connect a laravel application with the Bifrost
Installation
First, install spatie/laravel-permission, follow their installation guide
You can then install the package via composer:
composer require etsvthor/laravel-bifrost-bridge
You can publish the config file of bifrost and the underlying spatie permissions config+migrations with:
php artisan vendor:publish --provider="EtsvThor\\BifrostBridge\\BifrostBridgeServiceProvider" --tag="bifrost-config"
- Ensure the
users
has aoauth_user_id
andemail_verified_at
column. - In the
User
model, castemail_verified_at
todatetime
and add theHasRoles
trait. - Please add
'webhooks/bifrost'
to the CSRF exceptions inApp\Http\Middleware\VerifyCsrfToken
class
Environment
Add the following to your .env
file and fill them in:
# Required configuration BIFROST_ENABLED=true BIFROST_CLIENT_ID= BIFROST_CLIENT_SECRET= BIFROST_AUTH_PUSH_KEY= # Optional configuration with its defaults BIFROST_REDIRECT_URL="/login/callback" BIFROST_HOST="https://bifrost.thor.edu" BIFROST_ROUTE_PREFIX=
Configuration
In the configuration file, one can specify some thing about the user model, but have some sensible defaults
See config/bifrost.php for all options.
Make sure to seed all required roles, otherwise they will not sync
Resolvers
The User
and Role
model can be resolved using a custom resolver
use Spatie\Permission\Models\Role; use Illuminate\Database\Eloquent\Model as EloquentModel; // Default behaviour BifrostBridge::resolveUserClassUsing(function(/* auto injection works here */): EloquentModel { return app(config('bifrost.user.model', 'App\\Models\\User')); }); // Default behaviour BifrostBridge::resolveRoleClassUsing(function(/* auto injection works here */): Role { return app(PermissionRegistrar::class)->getRoleClass(); }); // Disabled role sync BifrostBridge::resolveRoleClassUsing(fn() => null); // Override the way a user is resolved BifrostBridge::resolveAndUpdateUserUsing(function(/* auto injection works here */, BifrostUserData $data): ?EloquentModel { // Model should implement \Illuminate\Contracts\Auth\Authenticatable return null; // when null is returned, the user is not logged in })
CSRF
Don't forget to add 'webhooks/bifrost'
to the $except
array in App\Http\Middleware\VerifyCsrfToken.php
.