File: demo.php

package info (click to toggle)
simplesamlphp 1.13.1-2%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 11,304 kB
  • sloc: php: 65,124; xml: 629; python: 376; sh: 193; perl: 185; makefile: 43
file content (64 lines) | stat: -rwxr-xr-x 2,323 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/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] : 'https://foodle.feide.no/simplesaml');
	$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";
}