fix: fix psalm

Signed-off-by: Jana Peper <jana.peper@nextcloud.com>
pull/55790/head
Jana Peper 2025-11-12 14:36:24 +07:00 committed by janepie
parent 134943e109
commit eafb602b4e
3 changed files with 21 additions and 4 deletions

@ -187,7 +187,6 @@ class WebhooksController extends OCSController {
* @param "none"|"header"|null $authMethod Authentication method to use
* @param ?array<string,mixed> $authData Array of data for authentication
* @param ?array<string,mixed> $tokenNeeded List of user ids for which to include auth tokens in the event.
* @param ?array<string,mixed> $tokenNeeded List of user ids for which to include auth tokens in the event.
* Has two fields: "user_ids" list of user uids for which tokens are needed, "user_roles" list of roles (users not defined by their ID but by the role they have in the webhook event) for which tokens can be included.
* Possible roles: "owner" for the user creating the webhook, "trigger" for the user triggering the webhook call.
* Requested auth tokens are valid for 1 hour after receiving them in the event call request.

@ -54,7 +54,7 @@ class TemporaryTokenMapper extends QBMapper {
/**
* @throws Exception
* @return WebhookListener[]
* @return TemporaryToken[]
*/
public function getAll(): array {
$qb = $this->db->getQueryBuilder();

@ -8,6 +8,7 @@
namespace OCA\WebhookListeners\Service;
use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\PublicKeyToken;
use OCA\WebhookListeners\Db\TemporaryTokenMapper;
use OCA\WebhookListeners\Db\WebhookListener;
use OCP\AppFramework\Utility\ITimeFactory;
@ -80,8 +81,25 @@ class TokenService {
$token = $this->generateRandomDeviceToken();
$name = 'Ephemeral webhook authentication';
$password = null;
$deviceToken = $this->tokenProvider->generateToken($token, $userId, $userId, $password, $name, IToken::PERMANENT_TOKEN);
$this->tokenMapper->addTemporaryToken($deviceToken->getId(), $deviceToken->getToken(), $userId, $this->time->getTime());
$deviceToken = $this->tokenProvider->generateToken(
$token,
$userId,
$userId,
$password,
$name,
IToken::PERMANENT_TOKEN);
// We need the getToken() method to be able to send the token out.
// That method is only available in PublicKeyToken which is returned by generateToken
// but not declared as such, so we have to check the type here
if (!($deviceToken instanceof PublicKeyToken)) { // type needed for the getToken() function
throw new \Exception('Unexpected token type');
}
$this->tokenMapper->addTemporaryToken(
$deviceToken->getId(),
$deviceToken->getToken(),
$userId,
$this->time->getTime());
return $token;
}