Skip to content

Commit 2c28c3c

Browse files
committed
fixes
Signed-off-by: Anupam Kumar <[email protected]>
1 parent 6c6b1a3 commit 2c28c3c

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

appinfo/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
// HaRP actions
6363
['name' => 'Harp#getExAppMetadata', 'url' => '/harp/exapp-meta', 'verb' => 'GET'],
64-
['name' => 'Harp#getUserInfo', 'url' => '/harp/user-info', 'verb' => 'POST'],
64+
['name' => 'Harp#getUserInfo', 'url' => '/harp/user-info', 'verb' => 'GET'],
6565
],
6666
'ocs' => [
6767
// Logging

lib/Controller/HarpController.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public function getExAppMetadata(string $appId): DataResponse {
6969
return new DataResponse(['message' => 'ExApp not found'], Http::STATUS_NOT_FOUND);
7070
}
7171

72-
// todo
73-
$val = [
72+
return new DataResponse([
7473
'exapp_token' => $exApp->getSecret(),
7574
'exapp_version' => $exApp->getVersion(),
7675
'port' => $exApp->getPort(),
@@ -85,10 +84,7 @@ public function getExAppMetadata(string $appId): DataResponse {
8584
'bruteforce_protection' => $bruteforceList,
8685
];
8786
}, $exApp->getRoutes()),
88-
];
89-
// todo
90-
$this->logger->error('ExApp metadata', $val);
91-
return new DataResponse($val);
87+
]);
9288
}
9389

9490
protected function isUserEnabled(string $userId): bool {
@@ -114,38 +110,44 @@ protected function isUserEnabled(string $userId): bool {
114110
* @return DataResponse { user_id: string|null, access_level: int }
115111
*/
116112
#[PublicPage]
117-
// #[NoCSRFRequired]
118-
public function getUserInfo(string $tokenId): DataResponse {
119-
if (!$this->validateHarpSharedKey(['tokenId' => $tokenId])) {
113+
#[NoCSRFRequired]
114+
public function getUserInfo(): DataResponse {
115+
if (!$this->validateHarpSharedKey()) {
120116
return new DataResponse(['message' => 'Invalid token'], Http::STATUS_UNAUTHORIZED);
121117
}
122118

123119
if ($this->userId === null) {
124120
$this->logger->debug('No user found in the harp request');
125121
return new DataResponse([
126122
'user_id' => null,
127-
'access_level' => 0, // PUBLIC
123+
'access_level' => ExAppRouteAccessLevel::PUBLIC->value,
128124
]);
129125
}
130126

131127
if (!$this->isUserEnabled($this->userId)) {
132128
$this->logger->debug('User is not enabled in the harp request', ['userId' => $this->userId]);
133129
return new DataResponse([
134130
'user_id' => $this->userId,
135-
'access_level' => 0, // PUBLIC
131+
'access_level' => ExAppRouteAccessLevel::PUBLIC->value,
136132
]);
137133
}
138134

139135
if ($this->groupManager->isAdmin($this->userId)) {
140136
return new DataResponse([
141137
'user_id' => $this->userId,
142-
'access_level' => 2, // ADMIN
138+
'access_level' => ExAppRouteAccessLevel::ADMIN->value,
143139
]);
144140
}
145141

146142
return new DataResponse([
147143
'user_id' => $this->userId,
148-
'access_level' => 1, // USER
144+
'access_level' => ExAppRouteAccessLevel::USER->value,
149145
]);
150146
}
151147
}
148+
149+
enum ExAppRouteAccessLevel: int {
150+
case PUBLIC = 0;
151+
case USER = 1;
152+
case ADMIN = 2;
153+
}

0 commit comments

Comments
 (0)