PHP code example of schibsted / account-sdk-php

1. Go to this page and download the library: Download schibsted/account-sdk-php 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/ */

    

schibsted / account-sdk-php example snippets


$provider = new Schibsted\OAuth2\Client\Provider\Schibsted([
    'domain'       => '{domain}',
    'clientId'     => '{schibsted-client-id}',
    'clientSecret' => '{schibsted-client-secret}',
    'redirectUri'  => 'https://example.com/callback-url'
]);

// Fetch a client token
$token = $provider->getAccessToken('client_credentials');

// Fetch a user token from authorization code
$token = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'] ]);

// Fetch Resource owner from user token
$user = $provider->getResourceOwner($token);

// Make an API request to Schibsted account
$req = $provider->getAuthenticatedRequest('GET', 'user/1', $token);
$res = $provider->getParsedResponse($req);

// or to your own service, using the Schibsted account token that you can introspect locally
$req = $provider->getAuthenticatedRequest('GET', 'https://myapi.com/resource/1', $token);
$res = $provider->getParsedResponse($req);

// Refreshing a token
if ($token->hasExpired()) {
    $token = $provider->getAccessToken('refresh_token', [
        'refresh_token' => $token->getRefreshToken()
    ]);
}

composer