1. Go to this page and download the library: Download chillerlan/php-oauth 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/ */
chillerlan / php-oauth example snippets
$options = new OAuthOptions;
// set the credentials for your OAuth application
// https://github.com/settings/applications/
$options->key = '[client_id]';
$options->secret = '[secret]';
$options->callbackURL = 'https://example.com/callback/';
// starts the session for the session storage
$options->sessionStart = true;
// a session (or other permanet) storage is
// display a link to the log-in redirect
echo '<a href="?route=oauth-login">connect with GitHub!</a>';
if($route === 'oauth2-callback' && isset($_GET['code'])){
$state = null;
// not all providers support "state"
if($provider instanceof CSRFToken && isset($_GET['state'])){
$state = $_GET['state'];
}
$token = $provider->getAccessToken($_GET['code'], $state);
// some providers may send additional data with the callback query parameters,
// that you may want to save here along with the token
// when everything is done here, you should redirect the user to wherever they were headed,
// but also to clear the URL query parameters
header('Location: ...');
}