killmails / oauth2-eve
EVE Online OAuth 2.0 Client Provider for The PHP League OAuth2-Client
v2.0.2
2024-03-04 01:32 UTC
Requires
- php: ^8.2
- firebase/php-jwt: ^6.9
- league/oauth2-client: ^2.4
Requires (Dev)
- pestphp/pest: ^2.33
- strobotti/php-jwk: ^1.4
README
This package provides EVE Online OAuth 2.0 support for the PHP League's OAuth 2.0 Client.
Installation
To install, use composer:
composer require killmails/oauth2-eve:^2.0
Usage
Usage is the same as The League's OAuth client, using \Killmails\OAuth2\Client\Provider\EveOnline
as the provider.
Authorization Code Flow
use Killmails\OAuth2\Client\Provider\EveOnline; $sso = new EveOnline([ 'clientId' => '{eveonline-client-id}', 'clientSecret' => '{eveonline-client-secret}', 'redirectUri' => 'https://example.com/callback-url', ]); if (empty($_GET['code'])) { $url = $sso->getAuthorizationUrl(); $_SESSION['state'] = $sso->getState(); header('Location: '.$authUrl); } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['state'])) { unset($_SESSION['state']); } else { $token = $sso->getAccessToken('authorization_code', [ 'code' => $_GET['code'] ]); $user = $sso->getResourceOwner($token); printf('Hello, %s (%d)', $user->getName(), $user->getId()); }
Managing Scopes
When creating your EVE Online authorization URL, you can specify the state and scopes your application may authorize.
$options = [ 'scope' => ['esi-killmails.read_killmails.v1'] ]; $url = $sso->getAuthorizationUrl($options); // ...
If neither are defined, the provider will utilize internal defaults.
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.