ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
demo.php
Go to the documentation of this file.
1 #!/usr/bin/env php
2 <?php
3 
4 
5 function _readline($prompt = '') {
6  echo $prompt;
7  return rtrim( fgets( STDIN ), "\n" );
8 }
9 
10 try {
11 
12 
13  // This is the base directory of the SimpleSAMLphp installation
14  $baseDir = dirname(dirname(dirname(dirname(__FILE__))));
15 
16  // Add library autoloader.
17  require_once($baseDir . '/lib/_autoload.php');
18 
19 
20  require_once(dirname(dirname(__FILE__)) . '/libextinc/OAuth.php');
21 
22  // Needed in order to make session_start to be called before output is printed.
24 
25  $baseurl = (isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'http://mars.foodle.local/simplesaml');
26  $key = (isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : 'key');
27  $secret = (isset($_SERVER['argv'][3]) ? $_SERVER['argv'][3] : 'secret');
28 
29  echo 'Welcome to the OAuth CLI client' . "\n";
31 
32  // Get the request token
33  $requestToken = $consumer->getRequestToken($baseurl . '/module.php/oauth/requestToken.php');
34  echo "Got a request token from the OAuth service provider [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]\n";
35 
36  // Authorize the request token
37  $url = $consumer->getAuthorizeRequest($baseurl . '/module.php/oauth/authorize.php', $requestToken, FALSE);
38 
39  echo('Go to this URL to authenticate/authorize the request: ' . $url . "\n");
40  system('open ' . $url);
41 
42  _readline('Click enter when you have completed the authorization step using your web browser...');
43 
44  // Replace the request token with an access token
45  $accessToken = $consumer->getAccessToken( $baseurl . '/module.php/oauth/accessToken.php', $requestToken);
46  echo "Got an access token from the OAuth service provider [" . $accessToken->key . "] with the secret [" . $accessToken->secret . "]\n";
47 
48  $userdata = $consumer->getUserInfo($baseurl . '/module.php/oauth/getUserInfo.php', $accessToken);
49 
50 
51  echo 'You are successfully authenticated to this Command Line CLI. ' . "\n";
52  echo 'Got data [' . join(', ', array_keys($userdata)) . ']' . "\n";
53  echo 'Your user ID is : ' . $userdata['eduPersonPrincipalName'][0] . "\n";
54 
55 } catch(Exception $e) {
56  echo 'Error occurred: ' . $e->getMessage() . "\n\n";
57 }
58 
59 
60 
61 
62 
63 
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$session
Definition: demo.php:23
$secret
Definition: demo.php:27
$baseurl
Definition: demo.php:25
$userdata
Definition: demo.php:48
$requestToken
Definition: demo.php:33
$key
Definition: demo.php:26
$consumer
Definition: demo.php:30
$url
Definition: demo.php:37
$accessToken
Definition: demo.php:45
_readline($prompt='')
Definition: demo.php:5
static getSessionFromRequest()
Retrieves the current session.
Definition: Session.php:243