1: <?php
2:
3: require_once("OpenID_common.php");
4: require_once(dirname(__FILE__).'/Auth/OpenID/AX.php');
5: if (!defined('OFFSET_PATH')) define('OFFSET_PATH',4);
6: require_once(dirname(dirname(dirname(__FILE__))).'/admin-functions.php');
7: if (session_id() == '') session_start();
8:
9: function getOpenIDURL() {
10:
11:
12: if (empty($_GET['openid_identifier'])) {
13: return false;
14: }
15:
16: return $_GET['openid_identifier'];
17: }
18:
19: function run() {
20: if (!($openid = getOpenIDURL())) {
21: return gettext('Not a valid OpenID URL');
22: }
23:
24: $consumer = getConsumer();
25:
26:
27: $auth_request = $consumer->begin($openid);
28:
29:
30: if (!$auth_request) {
31: return gettext("Authentication error; not a valid OpenID.");
32: }
33: $sreg_attribute = array();
34:
35:
36:
37: $attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/contact/email',2,1, 'email');
38: $sreg_attribute[] = 'email';
39:
40: $attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/namePerson',1,1, 'name');
41: $ax_attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/namePerson/first',1,1,'firstname');
42: $ax_attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/namePerson/middle',1,1,'middlename');
43: $ax_attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/namePerson/last',1,1,'lastname');
44: $sreg_attribute[] = 'fullname';
45:
46: $attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/namePerson/friendly',1,1, 'nicknamename');
47: $sreg_attribute[] = 'nickname';
48:
49:
50: $sreg_request = Auth_OpenID_SRegRequest::build($sreg_attribute);
51: if ($sreg_request) {
52: $auth_request->addExtension($sreg_request);
53: }
54: $ax = new Auth_OpenID_AX_FetchRequest;
55:
56: foreach($attribute as $attr){
57: $ax->add($attr);
58: }
59:
60: $auth_request->addExtension($ax);
61:
62:
63:
64:
65:
66:
67:
68: if ($auth_request->shouldSendRedirect()) {
69: $redirect_url = $auth_request->redirectURL(getTrustRoot(), getReturnTo());
70:
71:
72: if (Auth_OpenID::isFailure($redirect_url)) {
73: return sprintf(gettext("Could not redirect to server: %s"), $redirect_url->message);
74: } else {
75:
76: header("Location: ".$redirect_url);
77: }
78: } else {
79:
80: $form_id = 'openid_message';
81: $form_html = $auth_request->htmlMarkup(getTrustRoot(), getReturnTo(),
82: false, array('id' => $form_id));
83:
84:
85:
86: if (Auth_OpenID::isFailure($form_html)) {
87: return sprintf(gettext("Could not redirect to server: %s"), $form_html->message);
88: } else {
89: print $form_html;
90: }
91: }
92: return false;
93: }
94:
95: $error = run();
96: if ($error) {
97: header('Location: '.FULLWEBPATH.'/'.ZENFOLDER.'/admin.php?_zp_login_error='.sprintf(gettext('Federated logon error:<br />%s'), $error));
98: exitZP();
99: }
100:
101: ?>