1: <?php
2:
3: require_once('OpenID_common.php');
4: require_once(dirname(__FILE__) . '/Auth/OpenID/AX.php');
5: if (!defined('OFFSET_PATH'))
6: define('OFFSET_PATH', 4);
7: require_once(dirname(dirname(dirname(__FILE__))) . '/admin-functions.php');
8: session_start();
9:
10: function escape($thing) {
11: return htmlentities($thing);
12: }
13:
14: function run() {
15:
16: $consumer = getConsumer();
17:
18:
19:
20: $return_to = getReturnTo();
21: $response = $consumer->complete($return_to);
22:
23:
24: if ($response->status == Auth_OpenID_CANCEL) {
25:
26: $msg = gettext('Verification cancelled.');
27: } else if ($response->status == Auth_OpenID_FAILURE) {
28:
29: $msg = sprintf(gettext("OpenID authentication failed: %s"), $response->message);
30: } else if ($response->status == Auth_OpenID_SUCCESS) {
31:
32:
33:
34: $openid = $response->getDisplayIdentifier();
35: $esc_identity = escape($openid);
36:
37: $success = sprintf(gettext('You have successfully verified <a href="%s">%s</a> as your identity.'), $esc_identity, $esc_identity);
38:
39: if ($response->endpoint->canonicalID) {
40: $escaped_canonicalID = escape($response->endpoint->canonicalID);
41: $success .= ' (XRI CanonicalID: ' . $escaped_canonicalID . ') ';
42: }
43:
44: $email = $name = NULL;
45: $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
46: $sreg = $sreg_resp->contents();
47: if ($sreg) {
48: if (@$sreg['email']) {
49: $email = trim($sreg['email']);
50: }
51: if (@$sreg['nickname']) {
52: $name = $sreg['nickname'];
53: }
54: if (@$sreg['fullname']) {
55: $name = $sreg['fullname'];
56: }
57: }
58: $ax_resp = Auth_OpenID_AX_FetchResponse::fromSuccessResponse($response);
59: if ($ax_resp) {
60: $arr_ax_resp = get_object_vars($ax_resp);
61: $arr_ax_data = $arr_ax_resp['data'];
62: if (empty($email) && isset($arr_ax_data["http://axschema.org/contact/email"]) && count($arr_ax_data["http://axschema.org/contact/email"]) > 0) {
63: $email = $arr_ax_data["http://axschema.org/contact/email"][0];
64: }
65: if (empty($name) && isset($arr_ax_data["http://axschema.org/namePerson"]) && count($arr_ax_data["http://axschema.org/namePerson"]) > 0) {
66: $name = $arr_ax_data["http://axschema.org/namePerson"][0];
67: }
68: if (empty($name)) {
69: $name_first = '';
70: $name_middle = '';
71: $name_last = '';
72: if (isset($arr_ax_data["http://axschema.org/namePerson/first"]) && count($arr_ax_data["http://axschema.org/namePerson/first"]) > 0) {
73: $name_first = $arr_ax_data["http://axschema.org/namePerson/first"][0];
74: }
75: if (isset($arr_ax_data["http://axschema.org/namePerson/middle"]) && count($arr_ax_data["http://axschema.org/namePerson/middle"]) > 0) {
76: $name_middle = $arr_ax_data["http://axschema.org/namePerson/middle"][0];
77: }
78: if (isset($arr_ax_data["http://axschema.org/namePerson/last"]) && count($arr_ax_data["http://axschema.org/namePerson/last"]) > 0) {
79: $name_last = $arr_ax_data["http://axschema.org/namePerson/last"][0];
80: }
81: $fullname = trim(trim(trim($name_first) . ' ' . $name_middle) . ' ' . $name_last);
82: if (!empty($fullname)) {
83: $name = $fullname;
84: }
85: }
86: if (empty($name) && isset($arr_ax_data["http://axschema.org/namePerson/friendly"]) && count($arr_ax_data["http://axschema.org/namePerson/friendly"]) > 0) {
87: $name = $arr_ax_data["http://axschema.org/namePerson/friendly"][0];
88: }
89: }
90: $userid = trim(str_replace(array('http://', 'https://'), '', $openid), '/');
91: $pattern = @$_SESSION['OpenID_cleaner_pattern'];
92: if ($pattern) {
93: if (preg_match($pattern, $userid, $matches)) {
94: $userid = $matches[1];
95: }
96: }
97: $provider = @$_SESSION['provider'];
98: if (strlen($userid) + strlen($provider) > 63) {
99: $userid = sha1($userid);
100: }
101: if ($provider) {
102: $userid = $provider . ':' . $userid;
103: }
104: $redirect = @$_SESSION['OpenID_redirect'];
105: $success .= federated_logon::credentials($userid, $email, $name, $redirect);
106: }
107: return $success;
108: }
109:
110: $error = run();
111: if ($error) {
112: header('Location: ' . FULLWEBPATH . '/' . ZENFOLDER . '/admin.php?_zp_login_error=' . sprintf(gettext('Federated logon error:<br />%s'), $error));
113: exitZP();
114: }
115: ?>