Exemple #1
0
<head>
    <title>SPiD Client user login and authentication example</title>
    <meta charset="utf-8">
</head>
<body>
<h1>SPiD Client user login and authentication example</h1>
<?php 
// May get credential errors
if (isset($_GET['error'])) {
    echo '<h3 id="message" style="color:red">' . $_GET['error'] . '</h3>';
}
$session = isset($_SESSION['sdk']) ? $_SESSION['sdk'] : false;
// If we have session, that means we are logged in.
if ($session) {
    // Authorize the client with the session saved user token
    $client->setAccessToken($session['access_token']);
    // Try since SDK may throw VGS_Client_Exceptions:
    //   For instance if the client is blocked, has exceeded ratelimit or lacks access right
    try {
        // Grab the logged in user's User Object, /me will include the entire User object
        $user = $client->api('/me');
        echo '<h3 id="message">Welcome</h3>
            <h4>Logged in as <span id="name" style="color:blue">' . $user['displayName'] . '</span> <small>id: <span id="userId" style="color:green">' . $user['userId'] . '</span> email: <span id="email" style="color:purple">' . $user['email'] . '</span></h4>';
        if (isset($_GET['order_id'])) {
            echo '<pre>' . print_r($client->api('/order/' . $_GET['order_id']), true) . '</pre>';
        }
    } catch (VGS_Client_Exception $e) {
        if ($e->getCode() == 401) {
            // access denied, in case the access token is expired, try to refresh it
            try {
                // refresh tokens using the session saved refresh token
Exemple #2
0
require_once '../config.php';
$SPID_CREDENTIALS[VGS_Client::REDIRECT_URI] = "http://{$_SERVER['HTTP_HOST']}/examples/api";
$client = new VGS_Client($SPID_CREDENTIALS);
if (isset($_GET['refresh']) || !(isset($_SESSION['sdk']) && isset($_SESSION['sdk']['access_token']))) {
    try {
        $_SESSION['sdk']['access_token'] = $client->auth();
    } catch (VGS_Client_Exception $e) {
        print_r($e);
        exit;
    }
    if (isset($_GET['refresh'])) {
        header("Location: " . $SPID_CREDENTIALS[VGS_Client::REDIRECT_URI]);
        exit;
    }
}
$client->setAccessToken($_SESSION['sdk']['access_token']);
if (empty($_GET['offset'])) {
    $offset = 0;
} else {
    $offset = $_GET['offset'];
}
$limit = 5;
?>
<div id="top">&nbsp;</div>
<?php 
/**
 * /api/users
 * ---------------------------------------------------------------------------------------------------------------------
 */
$users_endpoint = $client->getApiURI('/users', array('since' => 'last year', 'until' => 'today', 'limit' => $limit, 'offset' => $offset, 'filters' => 'updated'));
echo '<br/><br/><strong>/users: </strong> <a href="' . $users_endpoint . '" target="blank">' . $users_endpoint . '</a>';