Last active
December 14, 2016 20:19
-
-
Save ArionHardison/bc86baccaa306c286b28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require('Client.php'); | |
require('IGrantType.php'); | |
require('AuthorizationCode.php'); | |
const CLIENT_ID = 'e8fefc347be6be281bf217d254cbdd5c4ec21f9ea889bfeee3d87bd95222ad9f'; | |
const CLIENT_SECRET = '958abd92ca65034f6966c22a579abf93cba220b36831a04fc73e98ed11d0093a'; | |
const REDIRECT_URI = "http://example.com/"; | |
const AUTHORIZATION_ENDPOINT = "https://arion.nationbuilder.com/oauth/authorize"; | |
const TOKEN_ENDPOINT = "https://arion.nationbuilder.com/oauth/token"; | |
const REQUEST_ENDPOINT = "https://arion.nationbuilder.com/api/v1"; | |
$client = new OAuth2\Client(CLIENT_ID, CLIENT_SECRET); | |
if (!isset($_GET['code'])) { | |
$auth_url = $client->getAuthenticationUrl(AUTHORIZATION_ENDPOINT, REDIRECT_URI); | |
header('Location: ' . $auth_url); | |
die('Redirect'); | |
} | |
$params = array('code' => $_GET['code'], 'redirect_uri' => REDIRECT_URI); | |
$response = $client->getAccessToken(TOKEN_ENDPOINT, 'authorization_code', $params); | |
if (isset($response['result']['error'])) { | |
switch($response['result']['error']) { | |
case 'invalid_grant': | |
header('Location: ' . REDIRECT_URI); | |
$error = "<b>ERROR</b>: Invalid Grant. This code is invalid, expired, or revoked.<br>"; | |
break; | |
default: | |
$error = "<b>Unknown error:</b> " . $response['result']['error'] . " - " . | |
$response['result']['error_description'] . "<br>"; | |
break; | |
} | |
die($error); | |
} | |
$token = $response['result']['access_token']; | |
$client->setAccessTokenType(1); | |
$client->setAccessToken($token); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment