foxdeveloper / oauth2-gitea
Gitea OAuth 2.0 Client provider for the PHP League OAuth2-Client
Installs: 1 271
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.2
- league/oauth2-client: ^2.0
Requires (Dev)
- mockery/mockery: ^1.4
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.5
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.