foxdeveloper/oauth2-gitea
Composer 安装命令:
composer require foxdeveloper/oauth2-gitea
包简介
Gitea OAuth 2.0 Client provider for the PHP League OAuth2-Client
README 文档
README
This package provides Gitea OAuth 2.0 support for the PHP League's OAuth 2.0 Client.
Installation
To install, use composer:
composer require foxdeveloper/oauth2-gitea
Usage
Usage is the same as The League's OAuth client, using \FoxDeveloper\OAuth2\Client\Provider\Gitea as the provider.
use FoxDeveloper\OAuth2\Client\Provider\Gitea; use FoxDeveloper\OAuth2\Client\Provider\GiteaResourceOwner; $provider = new Gitea([ 'clientId' => '{GITEA_CLIENT_ID}', 'clientSecret' => '{GITEA_CLIENT_SECRET}', 'redirectUri' => 'https://example.com/callback-url', 'baseUrl' => '{GITEA_BASE_URL}', ]); if (!isset($_GET['code'])) { $authUrl = $provider->getAuthorizationUrl(); $_SESSION['oauth2state'] = $provider->getState(); header('Location: '.$authUrl); exit(); } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) { unset($_SESSION['oauth2state']); exit('Invalid state'); } else { $token = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'], ]); try { /** @var GiteaResourceOwner */ $user = $provider->getResourceOwner($token); printf('Hello %s!', $user->getLogin()); } catch (\Exception $e) { exit('Oh dear...'); } echo $token->getToken(); }
Testing
./vendor/bin/phpunit
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 1.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-07