PHP code example of qbnk / guzzle5-oauth2-subscriber
1. Go to this page and download the library: Download qbnk/guzzle5-oauth2-subscriber 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/ */
qbnk / guzzle5-oauth2-subscriber example snippets
use kamermans\GuzzleOAuth2\OAuth2Subscriber;
// Setup OAuth
$oauth = new OAuth2Subscriber();
// Manually specify access_token. When it expires, you will get an exception
$oauth->getTokenData()->accessToken = 'somelongtoken';
$client = new GuzzleHttp\Client();
// Attach OAuth subscriber to the Guzzle client and all URLs will be authenticated
$client->getEmitter()->attach($oauth);
$response = $client->get('http://somehost/some_secure_url');
echo "Status: ".$response->getStatusCode()."\n";
use kamermans\GuzzleOAuth2\GrantType\ClientCredentials;
use kamermans\GuzzleOAuth2\OAuth2Subscriber;
// Authorization client - this is used to request OAuth access tokens
$reauth_client = new GuzzleHttp\Client([
// URL for access_token request
'base_url' => 'http://some_host/access_token_request_url',
]);
$reauth_config = [
"client_id" => "your client id",
"client_secret" => "your client secret",
"scope" => "your scope(s)", // optional
"state" => time(), // optional
];
$grant_type = new ClientCredentials($reauth_client, $reauth_config);
$oauth = new OAuth2Subscriber($grant_type);
// This is the normal Guzzle client that you use in your application
$client = new GuzzleHttp\Client();
$client->getEmitter()->attach($oauth);
$response = $client->get('http://somehost/some_secure_url');
echo "Status: ".$response->getStatusCode()."\n";
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.