1. Go to this page and download the library: Download eureka2/oauth-client 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/ */
eureka2 / oauth-client example snippets
use eureka2\OAuth\Client\OAuthClient;
try {
$client = OAuthClient::create('Google');
$client->setClientId('<YOUR CLIENT ID>');
$client->setClientSecret('<YOUR CLIENT SECRET>');
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']);
$user = (object) [];
if ($client->initialize([
'strategy' => [
'offline_access' => true
]
])) {
if ($client->authenticate()) {
if (!empty($client->getAccessToken())) {
$user = $client->getResourceOwner();
}
}
$client->finalize();
}
if ($client->shouldExit()) {
exit;
}
....
// Do something with $user
} catch (\Exception $e) {
// Do something with $e
}
use eureka2\OAuth\Client\OAuthClient;
try {
$client = OAuthClient::create('Google');
$options = [ // See the full list of options below
'provider' => [
'registration' => [
'keys' => [
'client_id' => '<YOUR CLIENT ID>',
'client_secret' => '<YOUR CLIENT SECRET>',
'redirect_uri' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']
]
]
],
'strategy' => [
'offline_access' => true
]
];
$user = $client->fetchResourceOwner($options);
....
// Do something with $user
} catch (\Exception $e) {
// Do something with $e
}