irongate/chief-base

此包已被弃用,不再维护。作者建议使用 irongate/chief 包。

用于构建Chief Tools的基础功能和辅助工具。

v0.34.1 2022-07-25 19:14 UTC

README

Total Downloads Monthly Downloads Latest Stable Version License

用于构建Chief Tools的基础功能和辅助工具。

配置

  • 通过 Account Chief(Socialite)进行认证
  • 使用 Laravel Passport 进行API访问
  • 使用 Sentry 客户端
  • 使用基于基本模式和标量的 Lighthouse GraphQL
    • 受会话保护的端点 /api/graphql/web
    • 受会话保护的(GraphiQL)游乐场 /api/playground
    • OAuth(Passport)受保护的端点 /api/graphql
  • 账户页面以显示个人资料信息和偏好设置
  • 基本API文档和Passport个人访问令牌管理
  • 重定向到Chief Tools主页的 /contact/privacy/terms
  • Chief Tools webhook处理器,当用户账户关闭或更新时进行通知
  • 健康检查队列任务每分钟ping QUEUE_MONITOR_URL,使用默认队列(当QUEUE_MONITOR_URL为空或未设置时禁用)
  • 登录事件监听器用于更新users表上的last_login

提供

中间件

  • IronGate\Chief\Middleware\AuthenticateChief
    验证请求是否来自 Chief Tools
    需要将services.chief.webhook_secret配置设置为随机字符串
  • IronGate\Chief\Middleware\AutoAuthenticate
    使用apiweb守卫,并设置第一个认证的守卫
  • IronGate\Chief\Middleware\ForceSecure
    确保请求是通过https://进行的
  • IronGate\Chief\Middleware\MoveAccessTokenFromURLToHeader
    将访问令牌从access_token GET参数移动到Authorization头中
  • IronGate\Chief\Middleware\SecurityHeaders
    添加一组默认的安全头,可以通过在应用配置中设置chief.response.securityheaders(数组)进行配置
  • IronGate\Chief\Middleware\TrustProxiesOnVapor
    配置fideloper/proxyLaravel Vapor 上使用

验证规则

  • IronGate\Chief\Rules\UUID
    验证输入值是否为UUIDv4

辅助工具

  • active($whitelist = null, $blacklist = null, $active = 'active', $inactive = '')
    基于白名单获取活动状态。用于指示活动菜单
  • timezones(): array
    返回所有时区的键值列表
  • validate($fields, $rules): bool
    根据规则验证字段。例如 validate($id, new \IronGate\Chief\Rules\UUID)
  • latest_ca_bundle_file_path(): string
    获取最新CA包文件的路径,使用Certainty作为底层

安装

首先引入包

composer require irongate/chief

发布配置文件和可选迁移

php artisan vendor:publish --tag=chief-config

# php artisan vendor:publish --tag=chief-migrations

运行应用程序迁移以创建用户表

php artisan migrate

将首席服务添加到 config/services.php

<?php

return [
    'chief' => [
        'client_id'      => env('CHIEF_CLIENT_ID'),
        'client_secret'  => env('CHIEF_CLIENT_SECRET'),
        'webhook_secret' => env('CHIEF_SECRET'),
        'base_url'       => env('CHIEF_BASE_URL', 'https://account.chief.app'),
        'verify'         => env('CHIEF_VERIFY', true),
        'redirect'       => '/login/callback',
    ],
];

这就完成了,你应该能够对Account Chief进行身份验证。

GraphQL API

您需要在您的项目中创建一个包含以下内容的 routes/graphql/schema.graphql

#import ../../vendor/irongate/chief/routes/graphql/schema.graphql

您可以在之后向模式中添加任何内容,例如

#import ../../vendor/irongate/chief/routes/graphql/schema.graphql

#import ./types/*.graphql
#import ./queries/*.graphql

请注意,User 类型已经提供,因此如果您想添加字段,则需要扩展它。

type OfType implements Entity {
    id: ID!
}

extend type User {
    relation: [OfType!]! @hasMany(type: "paginator")
}