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

This package is auto-updated.

Last update: 2024-04-04 01:37:10 UTC


README

GitHub Source GitHub Release GitHub License GitHub Actions Workflow Status Packagist Downloads

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.