Explorar o código

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 %!s(int64=5) %!d(string=hai) anos
pai
achega
2d66e8277a
Modificáronse 1 ficheiros con 12 adicións e 1 borrados
  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
 	return $response
 		->withHeader('Content-Type', 'application/json;charset=UTF-8')
 		->withHeader('Content-Type', 'application/json;charset=UTF-8')
 		->withStatus($GLOBALS['responseCode']);
 		->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']);
+});