friendsofcat / github-team-auth
GitHub 登录工具
Requires
- php: >=5.5.9
- graham-campbell/github: ^8.6
- illuminate/support: 6.*
- knplabs/github-api: ^2.9
- laravel/socialite: ^4.0
- php-http/guzzle6-adapter: ^1.1
Requires (Dev)
- fzaninotto/faker: ~1.4
- mockery/mockery: ~1.0
- nunomaduro/collision: ~1.1
- orchestra/testbench-browser-kit: ~3.4
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ~8.0
- squizlabs/php_codesniffer: ^3.3
This package is auto-updated.
Last update: 2024-09-17 22:14:28 UTC
README
概述
GitHubLogin 是一个 Laravel 扩展包,它使用 socialite(https://github.com/laravel/socialite) 通过获取 GitHub 用户账户和权限来登录用户。它基本上获取一个 GitHub 账户并验证用户是否属于预期的组织和团队,并发送一个包含用户数据的事件。预期的组织和团队必须在数据库中填写,这可以通过界面完成(更多详细信息请参阅界面部分)。
要求
"require": {
"php": ">=5.5.9",
"illuminate/support": "5.*",
"laravel/socialite": "^3.0@dev",
"knplabs/github-api": "^2.9",
"php-http/guzzle6-adapter": "^1.1",
"graham-campbell/github": "^7.4"
}
安装
Composer 安装
composer require friendsofcat/github-team-auth
发布配置文件
php artisan vendor:publish
发布配置文件
php artisan vendor:publish --provider="Friendsofcat\GitHubTeamAuth\GitHubTeamAuthProvider" --tag='github_team_auth:config'
配置文件只有一个参数,team_table_name,它定义了数据库中用于 GitHub 团队名称的表名,默认值为 'teams'
配置文件只有一个参数,custom_redirect,它定义了我们应该重定向的位置。
发布迁移
php artisan vendor:publish --provider="Friendsofcat\GitHubTeamAuth\GitHubTeamAuthProvider" --tag='github_team_auth:migrations'
发布视图
php artisan vendor:publish --provider="Friendsofcat\GitHubTeamAuth\GitHubTeamAuthProvider" --tag='github_team_auth:views'
编辑 app/config/service.php 添加以下代码
'github' => [
'client_id' => env('GITHUB_CLIENT_ID'),
'client_secret' => env('GITHUB_CLIENT_SECRET'),
'redirect' => 'https://cat-quality-service.test/auth/github/callback',
],
服务.php 配置的 env 文件是必需的,用于通知
- GITHUB_CLIENT_ID
- GITHUB_CLIENT_SECRET
- 重定向(必须是 https://{{APP_NAME}}/auth/github/callback)。
注册 GitHub 回调功能后,您可以获取所有这些参数。
管理组织和 org 的视图
https://{domain}/admin/github-team-auth
这是仪表板页面,列出了所有团队和组织。从该页面您可以选择删除组织或团队。还可以导航到创建团队或创建组织的屏幕。
https://{domain}/admin/github-team-auth/add/team
此页面设计用于添加新团队,显示用户登录时存储在缓存中的 GitHub 令牌所表示的团队可能性。还允许用户通过 'acl' 字段添加标签以标记团队访问级别。
https://{domain}/admin/github-team-auth/add/org
此页面设计用于添加新组织,显示用户登录时存储在缓存中的 GitHub 令牌所表示的组织可能性。
事件
在处理结束时,用户将登录并将触发一个事件。此事件具有以下公共参数
-
user_github_object ( \Laravel\Socialite\Two\User )
Which contain all the user information.
-
user_team_array ( 数组 )
An array with all the teams which this user is part of.
HTML
您必须在登录页面中添加 GitHub 登录按钮,如下例所示
<a class="btn mb-2 btn-secondary" href="{{ route('git_auth') }}">
<i class="fa fa-github"></i> GitHub
</a>
@if ($errors->has('github'))
<span class="help-block alert alert-dark">
<strong>{{ $errors->first('github') }}</strong>
</span>
@endif
鸡生蛋难题
为了添加新的组织/团队,用户需要登录系统,但为了登录,系统中必须有一些有效的组织和团队在数据库中。为了解决这个问题,创建一个迁移并插入基本组织和团队。