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' --- Psso/AuthInterface/Groups.php | 6 ++++++ Psso/AuthInterface/UserExtra.php | 7 +++++++ Psso/AuthProvider/ConfigFile.php | 21 +++++++++++++++++++-- Psso/Context.php | 3 ++- Psso/Identity.php | 10 +++++++++- Psso/Session.php | 14 +++++++++++--- 6 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 Psso/AuthInterface/Groups.php create mode 100644 Psso/AuthInterface/UserExtra.php (limited to 'Psso') diff --git a/Psso/AuthInterface/Groups.php b/Psso/AuthInterface/Groups.php new file mode 100644 index 0000000..463fd0b --- /dev/null +++ b/Psso/AuthInterface/Groups.php @@ -0,0 +1,6 @@ +config['users'][$username]); } + + public function userGroups(string $username): array { + $gstr = $this->config['users'][$username]['groups'] ?? ''; + $groups = []; + for ($ng = strtok($gstr, ' '); $ng !== false; $ng = strtok(' ')) + $groups[] = $ng; + return $groups; + } + + public function userDisplayName(string $username): ?string { + return $this->config['users'][$username]['name'] ?? null; + } + + public function userEmailAddress(string $username): ?string { + return $this->config['users'][$username]['email'] ?? null; + } } diff --git a/Psso/Context.php b/Psso/Context.php index 5af2102..ed1e6f9 100644 --- a/Psso/Context.php +++ b/Psso/Context.php @@ -4,8 +4,9 @@ namespace Psso; class Context { public protected(set) array $results = []; public ?string $user = null; - public protected(set) array $groups = []; + public array $groups = []; public protected(set) array $tags = []; + public array $extras = []; public function addResult(ChallengeResult $result): void { $this->results[] = $result; diff --git a/Psso/Identity.php b/Psso/Identity.php index 68272d4..a06f57e 100644 --- a/Psso/Identity.php +++ b/Psso/Identity.php @@ -4,9 +4,17 @@ namespace Psso; class Identity { public protected(set) string $user; public protected(set) array $groups; + public array $extras; - public function __construct(string $user, array $groups = []) { + public function __construct( + string $user, array $groups = [], array $extras = [] + ) { $this->user = $user; $this->groups = $groups; + $this->extras = $extras; + } + + public static function fromContext(Context $context) { + return new static($context->user, $context->groups, $context->extras); } } diff --git a/Psso/Session.php b/Psso/Session.php index 34dd94a..9893096 100644 --- a/Psso/Session.php +++ b/Psso/Session.php @@ -7,7 +7,7 @@ class Session { protected static ?array $config = null; protected \PDO $db; - private ?string $token = null; + public protected(set) ?string $token = null; public static function setDsn( array $config, @@ -34,6 +34,14 @@ class Session { return self::$instance; } + public static function override(string $newToken): void { + if (!isset(self::$instance)) { + self::$instance = new self(); + } + self::$instance->token = $newToken; + self::$instance->setCookie(true); + } + protected function setup(): void { $this->db->exec( <<<'END' @@ -50,8 +58,8 @@ class Session { return explode('.', $_SERVER['HTTP_HOST'], 2)[1]; } - protected function setCookie(): void { - if (isset($_COOKIE['PSSO_session'])) return; + protected function setCookie(bool $force = false): void { + if (isset($_COOKIE['PSSO_session']) && !$force) return; header( 'Set-Cookie: PSSO_session=' . $this->currentToken() . '; Domain=' . $this->domain() -- cgit v1.3