Skip to content
Snippets Groups Projects
Unverified Commit 82ef51cd authored by Thijs Kinkhorst's avatar Thijs Kinkhorst Committed by GitHub
Browse files

Merge pull request #743 from tvdijen/patch-oauth

oauth: Cleanup unused demo + templates
parents 7051ecc2 71c22ec0
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env php
<?php
function _readline($prompt = '') {
echo $prompt;
return rtrim( fgets( STDIN ), "\n" );
}
try {
// This is the base directory of the SimpleSAMLphp installation
$baseDir = dirname(dirname(dirname(dirname(__FILE__))));
// Add library autoloader.
require_once($baseDir . '/lib/_autoload.php');
require_once(dirname(dirname(__FILE__)) . '/libextinc/OAuth.php');
// Needed in order to make session_start to be called before output is printed.
$session = SimpleSAML_Session::getSessionFromRequest();
$baseurl = (isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'http://mars.foodle.local/simplesaml');
$key = (isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : 'key');
$secret = (isset($_SERVER['argv'][3]) ? $_SERVER['argv'][3] : 'secret');
echo 'Welcome to the OAuth CLI client' . "\n";
$consumer = new sspmod_oauth_Consumer($key, $secret);
// Get the request token
$requestToken = $consumer->getRequestToken($baseurl . '/module.php/oauth/requestToken.php');
echo "Got a request token from the OAuth service provider [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]\n";
// Authorize the request token
$url = $consumer->getAuthorizeRequest($baseurl . '/module.php/oauth/authorize.php', $requestToken, FALSE);
echo('Go to this URL to authenticate/authorize the request: ' . $url . "\n");
system('open ' . $url);
_readline('Click enter when you have completed the authorization step using your web browser...');
// Replace the request token with an access token
$accessToken = $consumer->getAccessToken( $baseurl . '/module.php/oauth/accessToken.php', $requestToken);
echo "Got an access token from the OAuth service provider [" . $accessToken->key . "] with the secret [" . $accessToken->secret . "]\n";
$userdata = $consumer->getUserInfo($baseurl . '/module.php/oauth/getUserInfo.php', $accessToken);
echo 'You are successfully authenticated to this Command Line CLI. ' . "\n";
echo 'Got data [' . join(', ', array_keys($userdata)) . ']' . "\n";
echo 'Your user ID is : ' . $userdata['eduPersonPrincipalName'][0] . "\n";
} catch(Exception $e) {
echo 'Error occurred: ' . $e->getMessage() . "\n\n";
}
<?php
$this->data['header'] = 'OAuth Authorization';
$this->includeAtTemplateBase('includes/header.php');
?>
<p style="margin-top: 2em">
You are now successfully authenticated, and you may click <em>Continue</em> in the application where you initiated authentication.
</p>
<?php if (!empty($this->data['oauth_verifier'])) {?>
<p>
When asked, the verifier code to finish the procedure, is: <b><?php echo htmlspecialchars($this->data['oauth_verifier']);?></b>.
</p>
<?php } ?>
<?php
$this->includeAtTemplateBase('includes/footer.php');
<?php
$this->data['header'] = 'OAuth Authorization';
$this->includeAtTemplateBase('includes/header.php');
?>
<p style="margin-top: 2em">
Do you agree to let the application at <b><?php echo htmlspecialchars($this->data['consumer']['name'])?></b> use Foodle on your behalf?
</p>
<p>
<a href="<?php echo htmlspecialchars($this->data['urlAgree']); ?>">Yes I agree</a> |
<a href="javascript:alert('Please close this browser.');">No, cancel the request.</a>
</p>
<?php
$this->includeAtTemplateBase('includes/footer.php');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment