From 96387025da63025894f6259f7eebed0fc6fc53ac Mon Sep 17 00:00:00 2001 From: winter Sparkles Date: Sun, 9 Aug 2026 15:44:18 +0100 Subject: implement the rest of login process incl. cookie redirects and 'next' --- routes/integration/auth-request.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'routes/integration') diff --git a/routes/integration/auth-request.php b/routes/integration/auth-request.php index 82d1f03..51b54d8 100644 --- a/routes/integration/auth-request.php +++ b/routes/integration/auth-request.php @@ -4,11 +4,27 @@ // returns 200 for allowed requests // otherwise, returns 401 and sends the login page url as a header +function addHeader(array $config, string $baseName, string $value): void { + $prefix = $config['integration']['header-prefix']; + header("$prefix-$baseName: $value"); +} + function GET(array $config) { - // in the absence of any auth backends i will say No to all requests + $session = Psso\Session::get(); + $identity = $session->getIdentity(); + if (isset($identity)) { + // ok + addHeader($config, 'User', $identity->user); + addHeader($config, 'Groups', implode(',', $identity->groups)); + foreach ($identity->extras as $key => $value) { + if ($value !== null) addHeader($config, ucfirst($key), $value); + } + return; + } + http_response_code(401); - header( - $config['integration']['header-prefix'] . '-Location: https://' - . $config['site']['primary-domain'] . '/login' + addHeader( + $config, 'Location', + 'https://' . $config['site']['primary-domain'] . '/login' ); } -- cgit v1.3