Skip to content

Commit

Permalink
updated root api routes to include optional slash
Browse files Browse the repository at this point in the history
consolidated auth endpoints
  • Loading branch information
causefx committed Apr 20, 2022
1 parent 07b08e5 commit fa4c279
Showing 1 changed file with 7 additions and 62 deletions.
69 changes: 7 additions & 62 deletions api/v2/routes/root.php
Expand Up @@ -10,7 +10,7 @@
->withHeader('Location', '/api/v2/status')
->withStatus(302);
});
$app->get('/status', function ($request, $response, $args) {
$app->get('/status[/]', function ($request, $response, $args) {
/**
* @OA\Get(
* path="/api/v2/status",
Expand All @@ -25,78 +25,23 @@
*/
$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
if ($Organizr->checkRoute($request)) {
$GLOBALS['api']['response']['data'] = $Organizr->status(true);
$GLOBALS['api']['response']['data'] = $Organizr->status(false);
}
$response->getBody()->write(jsonE($GLOBALS['api']));
return $response
->withHeader('Content-Type', 'application/json;charset=UTF-8')
->withStatus($GLOBALS['responseCode']);
});
$app->any('/auth', function ($request, $response, $args) {
/**
* @OA\Get(
* path="/api/v2/auth",
* summary="Nginx auth_request",
* @OA\Parameter(
* name="group",
* description="The id of the group allowed",
* @OA\Schema(
* type="integer",
* format="int64",
* ),
* in="query",
* required=false
* ),
* @OA\Parameter(
* name="whitelist",
* description="Whitelisted Ip's",
* @OA\Schema(
* type="array",
* @OA\Items(
* type="string",
* ),
* ),
* in="query",
* explode=false,
* required=false
* ),
* @OA\Parameter(
* name="blacklist",
* description="Blacklisted Ip's",
* @OA\Schema(
* type="array",
* @OA\Items(
* type="string",
* ),
* ),
* in="query",
* explode=false,
* required=false
* ),
* @OA\Response(
* response="200",
* description="Success",
* ),
* @OA\Response(response="401",description="Unauthorized"),
* )
*/
$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
$Organizr->auth();
$response->getBody()->write(jsonE($GLOBALS['api']));
return $response
->withHeader('Content-Type', 'application/json;charset=UTF-8')
->withStatus($GLOBALS['responseCode']);
});
$app->any('/auth-{group}', function ($request, $response, $args) {
$app->any('/auth-[{group}[/]]', function ($request, $response, $args) {
$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
$_GET['group'] = $args['group'];
$_GET['group'] = $args['group'] ?? 0;
$Organizr->auth();
$response->getBody()->write(jsonE($GLOBALS['api']));
return $response
->withHeader('Content-Type', 'application/json;charset=UTF-8')
->withStatus($GLOBALS['responseCode']);
});
$app->any('/auth/[{group}[/{type}[/{ips}]]]', function ($request, $response, $args) {
$app->any('/auth[/[{group}[/{type}[/{ips}]]]]', function ($request, $response, $args) {
$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
$_GET['group'] = $args['group'] ?? 0;
$_GET['type'] = $args['type'] ?? 'deny';
Expand All @@ -107,7 +52,7 @@
->withHeader('Content-Type', 'application/json;charset=UTF-8')
->withStatus($GLOBALS['responseCode']);
});
$app->any('/organizr-auth/[{group}[/{type}[/{ips}]]]', function ($request, $response, $args) {
$app->any('/organizr-auth[/[{group}[/{type}[/{ips}]]]]', function ($request, $response, $args) {
$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
$_GET['group'] = $args['group'] ?? 0;
$_GET['type'] = $args['type'] ?? 'deny';
Expand All @@ -118,7 +63,7 @@
->withHeader('Content-Type', 'application/json;charset=UTF-8')
->withStatus($GLOBALS['responseCode']);
});
$app->get('/launch', function ($request, $response, $args) {
$app->get('/launch[/]', function ($request, $response, $args) {
$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
$tabInfo = $Organizr->getUserTabsAndCategories();
$GLOBALS['api']['response']['data']['categories'] = ($tabInfo['categories']) ?? false;
Expand Down

0 comments on commit fa4c279

Please sign in to comment.