ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAuthOpenId.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 class ilAuthOpenId extends Auth
12 {
13  private $settings = null;
14 
21  public function __construct($a_container,$a_addition_options = array())
22  {
24  $a_container,
25  $a_addition_options,
26  array($this,'callProvider'),
27  true);
28  $this->setSessionName("_authhttp".md5(CLIENT_ID));
29 
30  $this->initAuth();
31  $this->initSettings();
32 
33  if(isset($_GET['oid_check_status']))
34  {
35  $_POST['username'] = 'dummy';
36  $_POST['password'] = 'dummy';
37  }
38 
39  }
40 
49  public function supportsRedirects()
50  {
51  return true;
52  }
53 
63  {
64  global $ilCtrl;
65 
66  $username = $_POST['oid_username'];
67 
68  if(!$this->parseUsername($username,$auth))
69  {
70  return false;
71  }
72 
73  $consumer = $this->settings->getConsumer();
74  $oid_auth = $consumer->begin($username);
75 
76  if (!$oid_auth)
77  {
78  $auth->status = AUTH_WRONG_LOGIN;
79  return false;
80  }
81 
82  include_once 'Auth/OpenID/SReg.php';
84  // Required
85  array('nickname'),
86  // Optional
87  array(
88  'fullname',
89  'dob',
90  'email',
91  'gender',
92  'postcode',
93  'language',
94  'timezone'
95  )
96  );
97 
98  if ($sreg_req)
99  {
100  $oid_auth->addExtension($sreg_req);
101  }
102 
103  // TODO: Switch openid v. 1,2
104  $url = $oid_auth->redirectURL(ILIAS_HTTP_PATH,$this->settings->getReturnLocation());
105  ilUtil::redirect($url);
106  }
107 
112  protected function initSettings()
113  {
114  include_once './Services/OpenId/classes/class.ilOpenIdSettings.php';
115  $this->settings = ilOpenIdSettings::getInstance();
116  $this->settings->initConsumer();
117  }
118 
123  protected function parseUsername(&$username,$auth)
124  {
125  if($_POST['oid_provider'])
126  {
127  include_once './Services/OpenId/classes/class.ilOpenIdProviders.php';
128  try
129  {
130  $url = ilOpenIdProviders::getInstance()->getProviderById($_POST['oid_provider'])->getURL();
131  $username = sprintf($url,(string) $username);
132  $GLOBALS['ilLog']->write(__METHOD__.': Using '.$username.' for authentication');
133  return true;
134  }
135  catch(UnexpectedValueException $e)
136  {
137  $GLOBALS['ilLog']->write(__METHOD__.': Unknown provider id given: '.$username);
138  $auth->status = AUTH_WRONG_LOGIN;
139  return false;
140  }
141  }
142  if($this->settings->forcedProviderSelection())
143  {
144  $auth->status = AUTH_WRONG_LOGIN;
145  return false;
146  }
147  $GLOBALS['ilLog']->write(__METHOD__.': Trying openid url: '.$username);
148  return true;
149  }
150 }
151 ?>