承接 codebarista/laravel-workos 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

codebarista/laravel-workos

最新稳定版本:1.2.4

Composer 安装命令:

composer require codebarista/laravel-workos

包简介

Authorize Laravel users with WorkOS.

README 文档

README

User Roles, Permissions and Stripe Entitlements

Authorize users with WorkOS roles and permissions, as well as subscribed Stripe entitlements. The roles and permissions implementation is heavily inspired by Spatie Laravel Permission. The additional Stripe entitlements are applied in the same way as permissions.

1. Installation

 composer require codebarista/laravel-workos

2. Configuration

WorkOS

These variables should match the values provided to you in the WorkOS dashboard for your application:

WORKOS_REDIRECT_URL="${APP_URL}/authenticate"
WORKOS_CLIENT_ID=your-client-id
WORKOS_API_KEY=your-api-key

Routes

LARAVEL_WORKOS_ROUTES_AUTHENTICATE=authenticate
LARAVEL_WORKOS_REDIRECT_TO_ROUTE_NAME=dashboard
LARAVEL_WORKOS_ROUTES_LOGOUT=logout
LARAVEL_WORKOS_ROUTES_LOGIN=login

Publish config (optional)

php artisan vendor:publish --tag="config" --provider="Codebarista\LaravelWorkos\LaravelWorkosServiceProvider"

3. Implementation

Add the HasRoles, HasPermissions and HasEntitlements traits as needed to the User class, or any other that uses authentication.

namespace App\Models;

use Codebarista\LaravelWorkos\Traits\HasEntitlements;
use Codebarista\LaravelWorkos\Traits\HasPermissions;
use Codebarista\LaravelWorkos\Traits\HasRoles;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasEntitlements, HasPermissions, HasRoles;

    // ...
}

4. Usage

WorkOS Role & Permissions

// e.g. use in Laravel policies
class EntryPolicy
{
    public function viewAny(User $user): bool
    {
        return $user->hasPermissionTo('entries:view') // custom WorkOS permission
            || $user->hasRole('org-editor'); // custom WorkOS organization role
    }
    
    // ...
}

Stripe Product Entitlements

Register Stripe customer for entitlements

php artisan codebarista:register-stripe-customer

Authorize with Stripe product entitlements

// e.g. use in Laravel gates
protected function gate(): void
{
    Gate::define('viewNova', static function (User $user) {
        return $user->hasEntitlementTo('access-dashboard'); // custom Stripe entitlement
    });
}

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固