Updates for OAuth2 support

This commit is contained in:
Erik Amaru Ortiz
2013-10-22 11:17:48 -04:00
parent 54696c03ae
commit 3bbb57709c
7 changed files with 80 additions and 102 deletions

View File

@@ -4,6 +4,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
$G_PUBLISH = new Publisher();
$G_PUBLISH->AddContent( 'view', 'oauth2/authorize' );
$erik = 'neyek';
G::RenderPage('publish', 'minimal');
break;
@@ -24,11 +25,11 @@ switch ($_SERVER['REQUEST_METHOD']) {
$response = $oauthServer->postAuthorize($authorize, $userid, true);
$code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40);
//$code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40);
echo 'session_id ' . session_id() . '<br>';
exit("SUCCESS! ==> Authorization Code: $code");
//echo 'session_id ' . session_id() . '<br>';
//exit("SUCCESS! ==> Authorization Code: $code");
//die($response->send());
die($response->send());
break;
}

View File

@@ -0,0 +1,35 @@
<?php
G::pr($_GET);
if (! empty($_GET['error'])) {
G::pr($_GET);
die();
}
$http = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
$host = $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != '80' ? ':' . $_SERVER['SERVER_PORT'] : '');
$endpoint = sprintf('%s://%s/api/1.0/%s/token', $http, $host, SYS_SYS);
$code = empty($_GET['code']) ? 'NN' : $_GET['code'];
$clientId = 'x-pm-local-client';
$secret = '179ad45c6ce2cb97cf1029e212046e81';
$data = array(
'grant_type' => 'authorization_code',
'code' => $code
);
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERPWD, "$clientId:$secret");
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = @json_decode(curl_exec($ch));
curl_close($ch);
G::pr((array) $data);