Browse Source

Add /token/validate v2 API endpoint

Adds an additional API endpoint to the v2 API to provide the ability to externally validate Organizr JWT tokens to support custom SSO applications.
TehMuffinMoo 5 years ago
parent
commit
2d66e8277a
1 changed files with 12 additions and 1 deletions
  1. 12 1
      api/v2/routes/token.php

+ 12 - 1
api/v2/routes/token.php

@@ -8,4 +8,15 @@ $app->delete('/token/{id}', function ($request, $response, $args) {
 	return $response
 		->withHeader('Content-Type', 'application/json;charset=UTF-8')
 		->withStatus($GLOBALS['responseCode']);
-});
+});
+
+$app->post('/token/validate', function ($request, $response, $args) {
+        $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
+        if ($Organizr->qualifyRequest(999, true)) {
+                $GLOBALS['api']['response']['data'] = $Organizr->jwtParse($_REQUEST["Token"]);
+        }
+        $response->getBody()->write(jsonE($GLOBALS['api']));
+        return $response
+                ->withHeader('Content-Type', 'application/json;charset=UTF-8')
+                ->withStatus($GLOBALS['responseCode']);
+});