- if (local_user()) {
- $user = $a->user;
-
- // OpenWebAuth
- if ($owa) {
- // 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];
-
- $headers = [];
- $headers['Accept'] = 'application/x-dfrn+json, application/x-zot+json';
- $headers['X-Open-Web-Auth'] = Strings::getRandomHex();
-
- // Create a header that is signed with the local users private key.
- $headers = HTTPSignature::createSig(
- $headers,
- $user['prvkey'],
- 'acct:' . $user['nickname'] . '@' . DI::baseUrl()->getHostname() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : '')
- );
-
- // Try to get an authentication token from the other instance.
- $curlResult = DI::httpRequest()->curl($basepath . '/owa', false, ['headers' => $headers]);
-
- 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;
-
- Logger::info('Redirecting', ['path' => $dest . $args]);
- System::externalRedirect($dest . $args);
+ // OpenWebAuth
+ 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->getHost() . ($this->baseUrl->getPath() ? '/' . $this->baseUrl->getPath() : '')
+ );
+
+ // 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'];