'Unauthorized - JWT Authentication requied'], 401); } $token = explode(" ", $auth)[1]; $jwt = \JOSE_JWT::decode($token); // Verifichiamo che la richiesta sia destinata alla nostra piattaforma e dominio if($domain != ($jwt->header["domain"] ?? "") || $platform != ($jwt->header["platform"] ?? "") ) { return HTTP::respondJson(['error' => 'Unauthorized - Invalid JWT for current platform and domain'], 401); } // Otteniamo la chiave pubblica per verificare la firma try { $verificationKey = KeyStore::get("sign", $domain, "public"); } catch(\Exception $ex) { return HTTP::respondJson(['error' => 'Unauthorized - This platform/domain combo might not be federated'] ); } // Verifichiamo la firma try { $jws = $jwt->verify($verificationKey, "RS512"); } catch(\JOSE_Exception_VerificationFailed $ex) { return HTTP::respondJson(['error' => "Unauthorized - Invalid signature"], 401); } // Il JWT รจ firmato correttamente, ora verifichiamo che siano firmati anche i contenuti della richiesta $bodyHash = sha1(file_get_contents("php://input")); if($bodyHash !== ($jws->claims["bodyHash"] ?? "")) { return HTTP::respondJson(['error' => 'Unauthorized - Tampered body'], 401); } // Richiesta autenticata return true; } } }