PHP code example of tkhamez / eve-sso

1. Go to this page and download the library: Download tkhamez/eve-sso library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tkhamez / eve-sso example snippets


// Initiate the provider object.
$provider = new Eve\Sso\AuthenticationProvider(
    [
        // Required.
        'clientId'       => 'your-EVE-app-client-ID',
        'clientSecret'   => 'your-EVE-app-secret-key',
        'redirectUri'    => 'https://your-callback.url',

        // Optional. If you do not provide all URLs, a request will be made
        // to the metadata URL to get them.
        'urlAuthorize'   => 'https://login.eveonline.com/v2/oauth/authorize',
        'urlAccessToken' => 'https://login.eveonline.com/v2/oauth/token',
        'urlRevoke'      => 'https://login.eveonline.com/v2/oauth/revoke',
        'urlKeySet'      => 'https://login.eveonline.com/oauth/jwks',
        'issuer'         => 'https://login.eveonline.com',
        'urlMetadata' => 'https://login.eveonline.com/.well-known/oauth-authorization-server',
    ],

    // Optionally, add all 

// Login URL
session_start();
$_SESSION['state'] = $provider->generateState();
$loginUrl = $provider->buildLoginUrl($_SESSION['state']);
header("Location: $loginUrl");

// Callback URL
session_start();
$eveAuthentication = $provider->validateAuthenticationV2(
    $_GET['state'] ?? '', 
    $_SESSION['state'] ?? '', 
    $_GET['code'] ?? '',
);
unset($_SESSION['state']);

$characterId = $eveAuthentication->getCharacterId();
$refreshToken = $eveAuthentication->getToken()->getRefreshToken();
$accessToken = $eveAuthentication->getToken()->getToken();
$expires = $eveAuthentication->getToken()->getExpires();
// ... store the token data somewhere together with the character ID.

// Refreshes access token, if necessary.
$existingToken = new League\OAuth2\Client\Token\AccessToken([
    'refresh_token' => $refreshToken,
    'access_token' => $accessToken,
    'expires' => $expires,
]);
$validToken = $provider->refreshAccessToken($existingToken);