PageRenderTime 52ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/virtualorgclient/www/index.php

http://simplesamlphp-labs.googlecode.com/
PHP | 99 lines | 52 code | 36 blank | 11 comment | 10 complexity | aff5cb5ac608b96b49ca14fa396e22b7 MD5 | raw file
  1. <?php
  2. /* Load simpleSAMLphp, configuration and metadata */
  3. $config = SimpleSAML_Configuration::getInstance();
  4. $oauthconfig = SimpleSAML_Configuration::getConfig('module_oauth.php');
  5. require_once($config->resolvePath('modules/oauth/libextinc/OAuth.php'));
  6. $session = SimpleSAML_Session::getInstance();
  7. $userid = NULL;
  8. $voreceived = FALSE;
  9. $vomemberships = NULL;
  10. $accessTokenKey = NULL;
  11. if (isset($_REQUEST['login'])) {
  12. $authsource = 'default-sp';
  13. $useridattr = 'eduPersonPrincipalName';
  14. if ($session->isValid($authsource)) {
  15. $attributes = $session->getAttributes();
  16. // Check if userid exists
  17. if (!isset($attributes[$useridattr]))
  18. throw new Exception('User ID is missing');
  19. $userid = $attributes[$useridattr][0];
  20. } else {
  21. SimpleSAML_Auth_Default::initLogin($authsource, SimpleSAML_Utilities::selfURL());
  22. }
  23. }
  24. # module.php/virtualorg/data_oauth_json.php
  25. $baseurl = 'http://vo.rnd.feide.no/simplesaml/';
  26. $key = 'key';
  27. $secret = 'secret';
  28. $consumer = new sspmod_oauth_Consumer($key, $secret);
  29. if (isset($_REQUEST['step']) && $_REQUEST['step'] == '1') {
  30. $oauthsess = SimpleSAML_Utilities::generateID();
  31. // Get the request token
  32. $requestToken = $consumer->getRequestToken($baseurl . '/module.php/oauth/requestToken.php');
  33. #print_r($requestToken); exit;
  34. $session->setData('oauthSess', $oauthsess, serialize($requestToken));
  35. # echo "Got a request token from the OAuth service provider [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]\n";
  36. $callback = SimpleSAML_Utilities::addURLparameter(SimpleSAML_Utilities::selfURLNoQuery(), array(
  37. 'step' => '2',
  38. 'oauthsess' => $oauthsess,
  39. ));
  40. // Authorize the request token
  41. $url = $consumer->getAuthorizeRequest($baseurl . '/module.php/oauth/authorize.php', $requestToken, TRUE, $callback);
  42. # echo('Go to this URL to authenticate/authorize the request: ' . $url . "\n");
  43. } elseif (isset($_REQUEST['step']) && $_REQUEST['step'] == '2') {
  44. $requestToken = unserialize($session->getData('oauthSess', $_REQUEST['oauthsess']));
  45. # print_r($requestToken); exit;
  46. // Replace the request token with an access token
  47. $accessToken = $consumer->getAccessToken( $baseurl . '/module.php/oauth/accessToken.php', $requestToken);
  48. $session->setData('accessToken', 'accesstoken', serialize($accessToken));
  49. SimpleSAML_Utilities::redirect('index.php?step=3'); exit;
  50. }
  51. if ($adata = $session->getData('accessToken', 'accesstoken')) {
  52. $accessToken = unserialize($adata);
  53. $vomemberships = $consumer->getUserInfo($baseurl . '/module.php/virtualorg/data_oauth_json.php?method=memberOf', $accessToken);
  54. $voreceived = TRUE;
  55. $accessTokenKey = $accessToken->key;
  56. # echo('<pre>'); print_r($vomemberships); exit;
  57. }
  58. $template = new SimpleSAML_XHTML_Template($config, 'virtualorgclient:client.tpl.php');
  59. $template->data['vomemberships'] = $vomemberships;
  60. $template->data['voreceived'] = $voreceived;
  61. $template->data['accessToken'] = $accessTokenKey;
  62. $template->data['userid'] = $userid;
  63. $template->show();