diff options
Diffstat (limited to 'routes/integration/auth-request.php')
| -rw-r--r-- | routes/integration/auth-request.php | 24 |
1 files changed, 20 insertions, 4 deletions
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' ); } |
