3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\ActivityPub;
24 use Friendica\Content\Text\BBCode;
25 use Friendica\Core\System;
27 use Friendica\Model\User;
28 use Friendica\Module\BaseApi;
29 use Friendica\Protocol\ActivityPub;
32 * "who am i" endpoint for ActivityPub C2S
34 class Whoami extends BaseApi
37 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
39 protected function rawContent(array $request = [])
41 self::checkAllowedScope(self::SCOPE_READ);
42 $uid = self::getCurrentUserID();
44 $owner = User::getOwnerDataById($uid);
46 $data = ['@context' => ActivityPub::CONTEXT];
48 $data['id'] = $owner['url'];
49 $data['url'] = $owner['url'];
50 $data['type'] = ActivityPub::ACCOUNT_TYPES[$owner['account-type']];
51 $data['name'] = $owner['name'];
52 $data['preferredUsername'] = $owner['nick'];
53 $data['alsoKnownAs'] = [];
54 $data['manuallyApprovesFollowers'] = in_array($owner['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP]);
55 $data['discoverable'] = (bool)$owner['net-publish'];
60 'url' => User::getAvatarUrl($owner)
63 if (!empty($owner['about'])) {
64 $data['summary'] = BBCode::convertForUriId($owner['uri-id'] ?? 0, $owner['about'], BBCode::EXTERNAL);
69 foreach (DI::profileField()->selectByContactId(0, $uid) as $profile_field) {
71 'type' => 'PropertyValue',
72 'name' => $profile_field->label,
73 'value' => BBCode::convertForUriId($owner['uri-id'], $profile_field->value)
77 if (!empty($custom_fields)) {
78 $data['attachment'] = $custom_fields;
81 $data['publicKey'] = [
82 'id' => $owner['url'] . '#main-key',
83 'owner' => $owner['url'],
84 'publicKeyPem' => $owner['pubkey']
87 $data['capabilities'] = [];
88 $data['inbox'] = DI::baseUrl() . '/inbox/' . $owner['nick'];
89 $data['outbox'] = DI::baseUrl() . '/outbox/' . $owner['nick'];
90 $data['featured'] = DI::baseUrl() . '/featured/' . $owner['nick'];
91 $data['followers'] = DI::baseUrl() . '/followers/' . $owner['nick'];
92 $data['following'] = DI::baseUrl() . '/following/' . $owner['nick'];
94 $data['endpoints'] = [
95 'oauthAuthorizationEndpoint' => DI::baseUrl() . '/oauth/authorize',
96 'oauthRegistrationEndpoint' => DI::baseUrl() . '/api/v1/apps',
97 'oauthTokenEndpoint' => DI::baseUrl() . '/oauth/token',
98 'sharedInbox' => DI::baseUrl() . '/inbox',
99 // 'uploadMedia' => DI::baseUrl() . '/api/upload_media' // @todo Endpoint does not exist at the moment
102 $data['generator'] = ActivityPub\Transmitter::getService();
103 System::jsonExit($data, 'application/activity+json');