PHP code example of ekoapp / eko-oauth-sdk

1. Go to this page and download the library: Download ekoapp/eko-oauth-sdk 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/ */

    

ekoapp / eko-oauth-sdk example snippets


use EkoApp\OAuth\EkoOAuthClient;

$client = new EkoOAuthClient();
$client->setClientId(CLIENT_ID);
$client->setClientSecret(CLIENT_SECRET);
$client->setRedirectUri(REDIRECT_URI);
$client->setEkoUri(EKO_URI);

$_SESSION['state'] = $client->createState();
// DO NOT forget to store this state into the session to validate it when Eko redirect back to your endpoint

$authEndpointUrl = $client->createAuthenticateUrl($_SESSION['state']);

$client->validateState($_SESSION['state'], $state);

$token = $client->requestToken($code);

// Retreiving values from access token
$accessToken = $token->getAccessToken();
$refreshToken = $token->getRefreshToken();
$tokenType = $token->getTokenType();
$expiresIn = $token->getExpiresIn();
$scopes = $token->getScopes();
$rawIdToken = $token->getRawIdToken();
$idToken = $token->getIdToken();

$idToken = $token->getIdToken();

// Retreiving values from id token
$firstName = $idToken->firstname;
$lastName = $idToken->lastname;
$email = $idToken->email;

$userInfo = $client->requestUserInfo($token->getAccessToken());

// Retreiving values from user info
$userId = $userInfo->_id;
$firstName = $userInfo->firstname;
$lastName = $userInfo->lastname;
$email = $userInfo->email;
$networkId = $userInfo->networkId;

$userInfo = $client->requestUserInfoByCode($code);