- if ($this->userSession->getLocalUserId() && $owa) {
- $user = User::getById($this->userSession->getLocalUserId());
-
- // Extract the basepath
- // NOTE: we need another solution because this does only work
- // for friendica contacts :-/ . We should have the basepath
- // of a contact also in the contact table.
- $exp = explode('/profile/', $contact['url']);
- $basepath = $exp[0];
-
- $header = [
- 'Accept' => ['application/x-dfrn+json', 'application/x-zot+json'],
- 'X-Open-Web-Auth' => [Strings::getRandomHex()],
- ];
-
- // Create a header that is signed with the local users private key.
- $header = HTTPSignature::createSig(
- $header,
- $user['prvkey'],
- 'acct:' . $user['nickname'] . '@' . $this->baseUrl->getHostname() . ($this->baseUrl->getUrlPath() ? '/' . $this->baseUrl->getUrlPath() : '')
- );
-
- // Try to get an authentication token from the other instance.
- $curlResult = $this->httpClient->get($basepath . '/owa', HttpClientAccept::DEFAULT, [HttpClientOptions::HEADERS => $header]);
-
- if ($curlResult->isSuccess()) {
- $j = json_decode($curlResult->getBody(), true);
-
- if ($j['success']) {
- $token = '';
- if ($j['encrypted_token']) {
- // The token is encrypted. If the local user is really the one the other instance
- // thinks he/she is, the token can be decrypted with the local users public key.
- openssl_private_decrypt(Strings::base64UrlDecode($j['encrypted_token']), $token, $user['prvkey']);
- } else {
- $token = $j['token'];
- }
- $args = (strpbrk($dest, '?&') ? '&' : '?') . 'owt=' . $token;
-
- $this->logger->info('Redirecting', ['path' => $dest . $args]);
- System::externalRedirect($dest . $args);
- }
+ $owner = User::getOwnerDataById($this->userSession->getLocalUserId());
+
+ if (!empty($contact['gsid'])) {
+ $gserver = $this->dba->selectFirst('gserver', ['url'], ['id' => $contact['gsid']]);
+ if (empty($gserver)) {
+ $this->logger->notice('Server not found, redirecting to destination.', ['gsid' => $contact['gsid'], 'dest' => $dest]);
+ System::externalRedirect($dest);