PHP code example of romitou / oauth2-invision
1. Go to this page and download the library: Download romitou/oauth2-invision 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/ */
romitou / oauth2-invision example snippets
n_start();
$invisionProvider = new Romitou\OAuth2\Client\InvisionProvider([
'baseUrl' => '', // The base URL of your Invision Community
'clientId' => '', // The client ID of your application
'clientSecret' => '', // The client secret of your application
'redirectUri' => '' // The callback URI where the user will be redirected
]);
if (isset($_GET['code'])) {
if ($_SESSION['oauth2_state'] !== $_GET['state'])
exit('The returned state doesn\'t match with your local state.');
$invisionToken = $invisionProvider->getAccessToken('authorization_code', ['code' => $_GET['code']]);
$invisionUser = $invisionProvider->getResourceOwner($invisionToken);
echo 'Your primary group name is: ' . $invisionUser->getPrimaryGroup()->getName();
echo 'Your email is: ' . $invisionUser->getEmail();
} else {
$oauthUrl = $invisionProvider->getAuthorizationUrl();
$_SESSION['oauth2_state'] = $invisionProvider->getState();
header('Location: ' . $oauthUrl);
}