Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,18 @@

public function __construct(
IRequest $request,
private IRootFolder $root,
private UserMapper $userMapper,
private IUserManager $userManager,
private readonly IRootFolder $root,

Check failure on line 26 in lib/Controller/ApiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

ParseError

lib/Controller/ApiController.php:26:20: ParseError: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 26 (see https://psalm.dev/173)

Check failure on line 26 in lib/Controller/ApiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

InvalidDocblock

lib/Controller/ApiController.php:26:3: InvalidDocblock: Param2 of OCA\UserOIDC\Controller\ApiController::__construct has invalid syntax (see https://psalm.dev/008)
private readonly UserMapper $userMapper,
private readonly IUserManager $userManager,
) {
parent::__construct(Application::APP_ID, $request);
}

/**
* @param int $providerId
* @param string $userId
* @param string|null $displayName
* @param string|null $email
* @param string|null $quota
* @return DataResponse
*/
#[NoCSRFRequired]
public function createUser(int $providerId, string $userId, ?string $displayName = null,
?string $email = null, ?string $quota = null): DataResponse {
$backendUser = $this->userMapper->getOrCreate($providerId, $userId);

Check failure on line 36 in lib/Controller/ApiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyFetch

lib/Controller/ApiController.php:36:18: UndefinedThisPropertyFetch: Instance property OCA\UserOIDC\Controller\ApiController::$userMapper is not defined (see https://psalm.dev/041)
$user = $this->userManager->get($backendUser->getUserId());

Check failure on line 37 in lib/Controller/ApiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyFetch

lib/Controller/ApiController.php:37:11: UndefinedThisPropertyFetch: Instance property OCA\UserOIDC\Controller\ApiController::$userManager is not defined (see https://psalm.dev/041)

if ($displayName) {
if ($displayName !== $backendUser->getDisplayName()) {
Expand All @@ -59,24 +51,21 @@
$user->setQuota($quota);
}

$userFolder = $this->root->getUserFolder($user->getUID());
$userId = $user->getUID();
$userFolder = $this->root->getUserFolder($userId);

Check failure on line 55 in lib/Controller/ApiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyFetch

lib/Controller/ApiController.php:55:17: UndefinedThisPropertyFetch: Instance property OCA\UserOIDC\Controller\ApiController::$root is not defined (see https://psalm.dev/041)
try {
// copy skeleton
\OC_Util::copySkeleton($user->getUID(), $userFolder);
\OC_Util::copySkeleton($userId, $userFolder);
} catch (NotPermittedException $ex) {
// read only uses
}

return new DataResponse(['user_id' => $user->getUID()]);
return new DataResponse(['user_id' => $userId]);
}

/**
* @param string $userId
* @return DataResponse
*/
#[NoCSRFRequired]
public function deleteUser(string $userId): DataResponse {
$user = $this->userManager->get($userId);

Check failure on line 68 in lib/Controller/ApiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyFetch

lib/Controller/ApiController.php:68:11: UndefinedThisPropertyFetch: Instance property OCA\UserOIDC\Controller\ApiController::$userManager is not defined (see https://psalm.dev/041)
if (is_null($user) || $user->getBackendClassName() !== Application::APP_ID) {
return new DataResponse(['message' => 'User not found'], Http::STATUS_NOT_FOUND);
}
Expand Down
69 changes: 15 additions & 54 deletions lib/Controller/BaseOidcController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

public function __construct(
IRequest $request,
private IConfig $config,
private IL10N $l,
private readonly IConfig $config,

Check failure on line 23 in lib/Controller/BaseOidcController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

ParseError

lib/Controller/BaseOidcController.php:23:20: ParseError: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 23 (see https://psalm.dev/173)

Check failure on line 23 in lib/Controller/BaseOidcController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

InvalidDocblock

lib/Controller/BaseOidcController.php:23:3: InvalidDocblock: Param2 of OCA\UserOIDC\Controller\BaseOidcController::__construct has invalid syntax (see https://psalm.dev/008)
private readonly IL10N $l,
) {
parent::__construct(Application::APP_ID, $request);
}
Expand All @@ -30,56 +30,38 @@
* @return bool
*/
protected function isDebugModeEnabled(): bool {
return $this->config->getSystemValueBool('debug', false);

Check failure on line 33 in lib/Controller/BaseOidcController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyFetch

lib/Controller/BaseOidcController.php:33:10: UndefinedThisPropertyFetch: Instance property OCA\UserOIDC\Controller\BaseOidcController::$config is not defined (see https://psalm.dev/041)
}

/**
* @param string $message
* @param int $statusCode
* @param array $throttleMetadata
* @param bool|null $throttle
* @return TemplateResponse
*/
protected function buildErrorTemplateResponse(string $message, int $statusCode, array $throttleMetadata = [], ?bool $throttle = null): TemplateResponse {
protected function buildErrorTemplateResponse(
string $message, int $statusCode, array $throttleMetadata = [], ?bool $throttle = null
): TemplateResponse {
$params = [
'message' => $message,
'title' => $this->l->t('Error'),

Check failure on line 41 in lib/Controller/BaseOidcController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyFetch

lib/Controller/BaseOidcController.php:41:15: UndefinedThisPropertyFetch: Instance property OCA\UserOIDC\Controller\BaseOidcController::$l is not defined (see https://psalm.dev/041)
];
return $this->buildFailureTemplateResponse($params, $statusCode, $throttleMetadata, $throttle);
}

/**
* @param string $message
* @param int $statusCode
* @param array $throttleMetadata
* @param bool|null $throttle
* @return TemplateResponse
*/
protected function build403TemplateResponse(string $message, int $statusCode, array $throttleMetadata = [], ?bool $throttle = null): TemplateResponse {
protected function build403TemplateResponse(string $message, int $statusCode, array $throttleMetadata = [],
?bool $throttle = null): TemplateResponse {
$params = [
'message' => $message,
'title' => $this->l->t('Access forbidden'),
];
return $this->buildFailureTemplateResponse($params, $statusCode, $throttleMetadata, $throttle);
}

/**
* @param array $params
* @param int $statusCode
* @param array $throttleMetadata
* @param bool|null $throttle
* @return TemplateResponse
*/
protected function buildFailureTemplateResponse(
array $params, int $statusCode, array $throttleMetadata = [], ?bool $throttle = null,
): TemplateResponse {
protected function buildFailureTemplateResponse(array $params, int $statusCode, array $throttleMetadata = [],
?bool $throttle = null): TemplateResponse {
$response = new TemplateResponse(
Application::APP_ID,
'error',
$params,
TemplateResponse::RENDER_AS_ERROR
);
$response->setStatus($statusCode);

// if not specified, throttle if debug mode is off
if (($throttle === null && !$this->isDebugModeEnabled()) || $throttle) {
$response->throttle($throttleMetadata);
Expand All @@ -89,15 +71,8 @@

// TODO: use the following methods only when 32 is the min supported version
// as it includes the "back to NC" button

/**
* @param string $message
* @param int $statusCode
* @param array $throttleMetadata
* @param bool|null $throttle
* @return TemplateResponse
*/
protected function buildCoreErrorTemplateResponse(string $message, int $statusCode, array $throttleMetadata = [], ?bool $throttle = null): TemplateResponse {
protected function buildCoreErrorTemplateResponse(string $message, int $statusCode, array $throttleMetadata = [],
?bool $throttle = null): TemplateResponse {
$params = [
'errors' => [
['error' => $message],
Expand All @@ -106,27 +81,12 @@
return $this->buildCoreFailureTemplateResponse('', 'error', $params, $statusCode, $throttleMetadata, $throttle);
}

/**
* @param string $message
* @param int $statusCode
* @param array $throttleMetadata
* @param bool|null $throttle
* @return TemplateResponse
*/
protected function buildCore403TemplateResponse(string $message, int $statusCode, array $throttleMetadata = [], ?bool $throttle = null): TemplateResponse {
protected function buildCore403TemplateResponse(string $message, int $statusCode, array $throttleMetadata = [],
?bool $throttle = null): TemplateResponse {
$params = ['message' => $message];
return $this->buildCoreFailureTemplateResponse('core', '403', $params, $statusCode, $throttleMetadata, $throttle);
}

/**
* @param string $appName
* @param string $templateName
* @param array $params
* @param int $statusCode
* @param array $throttleMetadata
* @param bool|null $throttle
* @return TemplateResponse
*/
protected function buildCoreFailureTemplateResponse(string $appName, string $templateName, array $params, int $statusCode,
array $throttleMetadata = [], ?bool $throttle = null): TemplateResponse {
$response = new TemplateResponse(
Expand All @@ -136,6 +96,7 @@
TemplateResponse::RENDER_AS_ERROR
);
$response->setStatus($statusCode);

// if not specified, throttle if debug mode is off
if (($throttle === null && !$this->isDebugModeEnabled()) || $throttle) {
$response->throttle($throttleMetadata);
Expand Down
32 changes: 14 additions & 18 deletions lib/Controller/Id4meController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ class Id4meController extends BaseOidcController {

public function __construct(
IRequest $request,
private ISecureRandom $random,
private ISession $session,
private readonly ISecureRandom $random,
private readonly ISession $session,
IConfig $config,
private IL10N $l10n,
private ITimeFactory $timeFactory,
private IClientService $clientService,
private IURLGenerator $urlGenerator,
private UserMapper $userMapper,
private IUserSession $userSession,
private IUserManager $userManager,
private readonly IL10N $l10n,
private readonly ITimeFactory $timeFactory,
private readonly IClientService $clientService,
private readonly IURLGenerator $urlGenerator,
private readonly UserMapper $userMapper,
private readonly IUserSession $userSession,
private readonly IUserManager $userManager,
HttpClientHelper $clientHelper,
private Id4MeMapper $id4MeMapper,
private ID4MeService $id4MeService,
private LoggerInterface $logger,
private ICrypto $crypto,
private readonly Id4MeMapper $id4MeMapper,
private readonly ID4MeService $id4MeService,
private readonly LoggerInterface $logger,
private readonly ICrypto $crypto,
) {
parent::__construct($request, $config, $l10n);

Expand Down Expand Up @@ -96,7 +96,6 @@ public function showLogin() {
}

/**
* @param string $domain
* @return RedirectResponse|TemplateResponse
*/
#[PublicPage]
Expand Down Expand Up @@ -165,9 +164,6 @@ private function registerClient(string $authorityName, OpenIdConfig $openIdConfi
}

/**
* @param string $state
* @param string $code
* @param string $scope
* @return JSONResponse|RedirectResponse|TemplateResponse
* @throws \Exception
*/
Expand Down Expand Up @@ -249,7 +245,7 @@ public function code(string $state = '', string $code = '', string $scope = '')
$plainHeaders = json_decode(base64_decode($header), true);
$plainPayload = json_decode(base64_decode($payload), true);

/** TODO: VALIATE SIGNATURE! */
/** TODO: VALIDATE SIGNATURE! */

// Check expiration
if ($plainPayload['exp'] < $this->timeFactory->getTime()) {
Expand Down
Loading
Loading