etsvthor/laravel-bifrost-bridge

Connect a laravel application with the Bifrost oauth2 server
3,674
Install
composer require etsvthor/laravel-bifrost-bridge
Latest Version:2.0.0
PHP:~8.3.0 | ~8.4.0 | ~8.5.0
License:MIT
Last Updated:Aug 28, 2026
Links: GitHub  ·  Packagist
Maintainer: dododedodonl

laravel-bifrost-bridge

Latest Version on Packagist

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 model implements EtsvThor\BifrostBridge\Contracts\BifrostUser
  • Ensure the users has a oauth_user_id and email_verified_at column.
  • In the User model, cast email_verified_at to datetime and add the HasRoles trait.

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
})

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

631,580,251 9,707
laravel/framework

The Laravel Framework.

580,311,802 34,925
laravel/tinker

Powerful REPL for the Laravel framework.

489,754,436 7,444
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

404,034,618 608
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

384,821,166 4,658