valdask/gitlab-auth
Composer 安装命令:
composer require valdask/gitlab-auth
包简介
Simple Gitlab Oauth wrapper for PHP
README 文档
README
Simple Gitlab Oauth wrapper to receive user information, such as email.
The main purpose of this package is to retrieve user info from Gitlab, simplifying user login and registration proccess.
Quick use
On your login page:
$lib = new \GitlabAuth\Auth(new GuzzleHttp\Client(), "http://mygitlab.com", "app id", "app secret", "http://myapp.com/do-login"); header('Location: ' . $lib->getLoginRedirectUrl()); exit;
on "http://myapp.com/do-login" page:
$lib = new \GitlabAuth\Auth(new GuzzleHttp\Client(), "http://mygitlab.com", "app id", "app secret", "http://myapp.com/do-login"); var_dump($lib->getUserByCode($_GET['code'])); exit;
Full how-to guide
1. Initializing
To initialize this library, create new instance of GitlabAuth\Auth.
Guide how to create application ID and secret can be found here: http://doc.gitlab.com/ce/integration/oauth_provider.html
$lib = new \GitlabAuth\Auth(new GuzzleHttp\Client(), "http://mygitlab.com", "app id", "app secret", "http://myapp.com/do-login");
2. Retrieving authorization URL
First step in login proccess is to redirect user to Gitlab authorization page, where he or she accepts of denies access using their Gitlab account. This library provides simple method to create proper redirect URL.
$authorizationUrl = $lib->getLoginRedirectUrl();
You can use this URL in link and present it to user or just use proper redirect header to skip user input.
3. Retrieving user data
When user visits authorization page, he can choose whether to accept or deny authorization. After action is chosen, he is redirected back to redirect url (set in library initialization step), with GET parameter named "code". This is used to retrieve auth token from Gitlab server, and then using that auth token user details are retrievied from Gitlab API.
Tip: do not forget to check if $_GET['error'] exists, and if it does that means user declined the request and should not be authorized.
$userDetais = $lib->getUserByCode($_GET['code']);
User details is an array, which contain email, name, surname, and other user details. Full documentation of Gitlab user API can be found here: http://doc.gitlab.com/ce/api/users.html#for-admin
4. (optional) Retrieving Gitlab Auth token
If you need extra Gitlab API features, which require auth token, after calling getUserByCode function, method getTokenContainer can be used which contains retrieved auth token.
$authToken = $lib->getTokenContainer();
valdask/gitlab-auth 适用场景与选型建议
valdask/gitlab-auth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 06 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 valdask/gitlab-auth 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 valdask/gitlab-auth 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-12