定制 etsvthor/laravel-bifrost-bridge 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

etsvthor/laravel-bifrost-bridge

最新稳定版本:1.4.0

Composer 安装命令:

composer require etsvthor/laravel-bifrost-bridge

包简介

Connect a laravel application with the Bifrost oauth2 server

README 文档

README

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 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.
  • (only laravel <11) Please add 'webhooks/bifrost' to the CSRF exceptions in App\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 (laravel <11 only)

Don't forget to add 'webhooks/bifrost' to the $except array in App\Http\Middleware\VerifyCsrfToken.php.

统计信息

  • 总下载量: 3.25k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-19