]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Profile.php
Merge pull request #6989 from nupplaphil/task/basePath_baseUrl_fix
[friendica.git] / src / Model / Profile.php
index b10e9848f5893d269fe79dcb1214ceb8beff159b..79971cd9998e24045181d4249418220e00e11e68 100644 (file)
@@ -1083,34 +1083,20 @@ class Profile
        }
 
        /**
-        * OpenWebAuth authentication.
-        *
-        * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/include/zid.php
+        * Set the visitor cookies (see remote_user()) for the given handle
         *
-        * @param string $token
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
-        * @throws \ImagickException
+        * @param string $handle Visitor handle
+        * @return array Visitor contact array
         */
-       public static function openWebAuthInit($token)
+       public static function addVisitorCookieForHandle($handle)
        {
                $a = \get_app();
 
-               // Clean old OpenWebAuthToken entries.
-               OpenWebAuthToken::purge('owt', '3 MINUTE');
-
-               // Check if the token we got is the same one
-               // we have stored in the database.
-               $visitor_handle = OpenWebAuthToken::getMeta('owt', 0, $token);
-
-               if($visitor_handle === false) {
-                       return;
-               }
-
                // Try to find the public contact entry of the visitor.
-               $cid = Contact::getIdForURL($visitor_handle);
-               if(!$cid) {
-                       Logger::log('owt: unable to finger ' . $visitor_handle, Logger::DEBUG);
-                       return;
+               $cid = Contact::getIdForURL($handle);
+               if (!$cid) {
+                       Logger::log('unable to finger ' . $handle, Logger::DEBUG);
+                       return [];
                }
 
                $visitor = DBA::selectFirst('contact', [], ['id' => $cid]);
@@ -1133,6 +1119,43 @@ class Profile
 
                        $_SESSION['remote'][] = ['cid' => $contact['id'], 'uid' => $contact['uid'], 'url' => $visitor['url']];
                }
+
+               $a->contact = $visitor;
+
+               Logger::info('Authenticated visitor', ['url' => $visitor['url']]);
+
+               return $visitor;
+       }
+
+       /**
+        * OpenWebAuth authentication.
+        *
+        * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/include/zid.php
+        *
+        * @param string $token
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public static function openWebAuthInit($token)
+       {
+               $a = \get_app();
+
+               // Clean old OpenWebAuthToken entries.
+               OpenWebAuthToken::purge('owt', '3 MINUTE');
+
+               // Check if the token we got is the same one
+               // we have stored in the database.
+               $visitor_handle = OpenWebAuthToken::getMeta('owt', 0, $token);
+
+               if ($visitor_handle === false) {
+                       return;
+               }
+
+               $visitor = self::addVisitorCookieForHandle($visitor_handle);
+               if (empty($visitor)) {
+                       return;
+               }
+
                $arr = [
                        'visitor' => $visitor,
                        'url' => $a->query_string