4 use Friendica\Core\Config;
5 use Friendica\Core\System;
6 use Friendica\Database\DBM;
8 require_once('library/openid.php');
10 function openid_content(App $a) {
12 $noid = Config::get('system','no_openid');
14 goaway(System::baseUrl());
16 logger('mod_openid ' . print_r($_REQUEST,true), LOGGER_DATA);
18 if((x($_GET,'openid_mode')) && (x($_SESSION,'openid'))) {
20 $openid = new LightOpenID;
22 if($openid->validate()) {
24 $authid = $_REQUEST['openid_identity'];
26 if(! strlen($authid)) {
27 logger( t('OpenID protocol error. No ID returned.') . EOL);
28 goaway(System::baseUrl());
31 // NOTE: we search both for normalised and non-normalised form of $authid
32 // because the normalization step was removed from setting
33 // mod/settings.php in 8367cad so it might have left mixed
34 // records in the user table
38 WHERE ( `openid` = '%s' OR `openid` = '%s' )
39 AND `blocked` = 0 AND `account_expired` = 0
40 AND `account_removed` = 0 AND `verified` = 1
42 dbesc($authid), dbesc(normalise_openid($authid))
45 if (DBM::is_result($r)) {
47 // successful OpenID login
49 unset($_SESSION['openid']);
51 require_once('include/security.php');
52 authenticate_success($r[0],true,true);
54 // just in case there was no return url set
55 // and we fell through
57 goaway(System::baseUrl());
60 // Successful OpenID login - but we can't match it to an existing account.
63 if ($a->config['register_policy'] == REGISTER_CLOSED) {
64 notice( t('Account not found and OpenID registration is not permitted on this site.') . EOL);
65 goaway(System::baseUrl());
68 unset($_SESSION['register']);
70 $attr = $openid->getAttributes();
71 if (is_array($attr) && count($attr)) {
72 foreach ($attr as $k => $v) {
73 if ($k === 'namePerson/friendly') {
74 $nick = notags(trim($v));
76 if($k === 'namePerson/first') {
77 $first = notags(trim($v));
79 if($k === 'namePerson') {
80 $args .= '&username=' . urlencode(notags(trim($v)));
82 if ($k === 'contact/email') {
83 $args .= '&email=' . urlencode(notags(trim($v)));
85 if ($k === 'media/image/aspect11') {
86 $photosq = bin2hex(trim($v));
88 if ($k === 'media/image/default') {
89 $photo = bin2hex(trim($v));
94 $args .= '&nickname=' . urlencode($nick);
97 $args .= '&nickname=' . urlencode($first);
101 $args .= '&photo=' . urlencode($photosq);
104 $args .= '&photo=' . urlencode($photo);
107 $args .= '&openid_url=' . urlencode(notags(trim($authid)));
109 goaway(System::baseUrl() . '/register?' . $args);
114 notice( t('Login failed.') . EOL);
115 goaway(System::baseUrl());