PHP code example of gap / open-server
1. Go to this page and download the library: Download gap/open-server 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/ */
gap / open-server example snippets
$cnn = new Cnn($pdo, $serverId);
$openServer = new OpenServer(['cnn' => $cnn]);
$authCodeGrant = $openServer->authCodeGrant();
$appId = 'fake-app-id';
$userId = 'fake-user-id';
$redirectUrl = 'fake-redirect-url';
$scope = '';
$authCode = $authCodeGrant->authCode(
$appId,
$userId,
$redirectUrl,
$scope
);
$accessToken = $authCodeGrant->accessToken(
$appId,
$authCode->code
);
if (is_null($accessToken)) {
return;
}
$clientCdGrant = $openServer->clientCdGrant();
$appId = 'fake-app-id';
$appSecret = 'fake-app-secret';
$accessToken = $clientCdGrant->accessToken(
$appId,
$appSecret
);
$publicKey =
'-----BEGIN PUBLIC KEY-----' . "\n"
. 'xxx'
. 'xxx' . "\n"
. '-----END PUBLIC KEY-----';
$privateKey =
'------BEGIN RSA PRIVATE KEY----' . "\n"
. 'xxxx'
. 'xxx' . "\n"
. '------END RSA PRIVATE KEY----';
$openServer = new OpenServer([
'cnn' => $cnn,
'cache' => $cache,
'publicKey' => $publicKey,
'privateKey' => $privateKey
]);
$openIdGrant = $openServer->openIdGrant();
$idToken = $openIdGrant->idToken($userId);
$tokenStr = (string) $idToken;
$accessToken = $openIdGrant->accessToken($appId, $tokenStr);
$token = 'Bearer xxxxx';
$openServer->accessTokenService()
->bearerAuthorize($token)