irongate/integrationchief

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

为构建Chief Tools所使用的基功能和辅助工具。

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

README

Total Downloads Monthly Downloads Latest Stable Version License

为构建Chief Tools所使用的基功能和辅助工具。

配置

  • (Socialite) 通过Account Chief进行身份验证
  • 使用Laravel Passport进行API访问
  • 使用Sentry客户端
  • 基于基础模式和标量的Lighthouse GraphQL
    • 受保护会话端点 /api/graphql/web
    • 受保护(GraphiQL)沙盒 /api/playground
    • OAuth(Passport)受保护端点 /api/graphql
  • 账户页面以显示个人资料信息和偏好设置
  • 基本API文档和Passport个人访问令牌管理
  • /contact/privacy/terms重定向到Chief Tools主页
  • 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
    添加一组默认的安全头,可以通过在app配置中设置chief.response.securityheaders(数组)进行配置
  • IronGate\Chief\Middleware\TrustProxiesOnVapor
    配置fideloper/proxy以在Laravel 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")
}