Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ownCloud]: Organize Utils #61

Merged
merged 1 commit into from
Oct 16, 2023
Merged
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
10 changes: 5 additions & 5 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@

return [
// The string under which your app will be referenced in owncloud
'id' => 'sciencemesh',
"id" => "sciencemesh",

// The sorting weight for the navigation.
// The higher the number, the higher will it be listed in the navigation
'order' => 10,
"order" => 10,

// The route that will be shown on startup
'href' => $urlGenerator->linkToRoute('sciencemesh.app.contacts'),
"href" => $urlGenerator->linkToRoute("sciencemesh.app.contacts"),

// The icon that will be shown in the navigation, located in img/
'icon' => $urlGenerator->imagePath('sciencemesh', 'app-white.svg'),
"icon" => $urlGenerator->imagePath("sciencemesh", "app-white.svg"),

// The application's title, used in the navigation & the settings page of your app
'name' => OC::$server->getL10N('sciencemesh')->t('ScienceMesh'),
"name" => OC::$server->getL10N("sciencemesh")->t("ScienceMesh"),
];
});
40 changes: 7 additions & 33 deletions lib/Controller/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OC\Config;
use OCA\ScienceMesh\ServerConfig;
use OCA\ScienceMesh\ShareProvider\ScienceMeshShareProvider;
use OCA\ScienceMesh\Utils\Utils;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
Expand Down Expand Up @@ -44,6 +45,9 @@ class AuthController extends Controller
/** @var IUserManager */
private IUserManager $userManager;

/** @var Utils */
private Utils $utils;

/** @var ScienceMeshShareProvider */
private ScienceMeshShareProvider $shareProvider;

Expand Down Expand Up @@ -79,22 +83,7 @@ public function __construct(
$this->logger = $logger;
$this->userManager = $userManager;
$this->shareProvider = $shareProvider;
}

// TODO: @Mahdi Move to utils.

/**
* @throws NotPermittedException
* @throws Exception
*/
private function checkRevadAuth()
{
error_log("checkRevadAuth");
$authHeader = $this->request->getHeader('X-Reva-Secret');

if ($authHeader != $this->config->getRevaSharedSecret()) {
throw new NotPermittedException('Please set an http request header "X-Reva-Secret: <your_shared_secret>"!');
}
$this->utils = new Utils($l10n, $logger, $shareProvider);
}

/**
Expand All @@ -111,7 +100,7 @@ public function Authenticate($userId): JSONResponse
{
error_log("Authenticate: " . $userId);

$this->checkRevadAuth();
$this->utils->checkRevadAuth($this->request, $this->config->getRevaSharedSecret());

if ($this->userManager->userExists($userId)) {
$userId = $this->request->getParam("clientID");
Expand Down Expand Up @@ -143,7 +132,7 @@ public function Authenticate($userId): JSONResponse
// "path": "some/file/path.txt"
// }
$result = [
"user" => $this->formatUser($user),
"user" => $this->utils->formatUser($user, $this->config->getIopIdp()),
"scopes" => [
"user" => [
"resource" => [
Expand All @@ -160,19 +149,4 @@ public function Authenticate($userId): JSONResponse

return new JSONResponse("Username / password not recognized", Http::STATUS_UNAUTHORIZED);
}

// TODO: @Mahdi Move to utils.
private function formatUser($user): array
{
return [
"id" => [
"idp" => $this->config->getIopIdp(),
"opaque_id" => $user->getUID(),
],
"display_name" => $user->getDisplayName(),
"username" => $user->getUID(),
"email" => $user->getEmailAddress(),
"type" => 1,
];
}
}
Loading
Loading