diff options
| author | winter Sparkles | 2026-08-09 15:44:18 +0100 |
|---|---|---|
| committer | winter Sparkles | 2026-08-09 15:44:18 +0100 |
| commit | 96387025da63025894f6259f7eebed0fc6fc53ac (patch) | |
| tree | a83d73eeb7ec419b24ff78291634503d4ebceec1 /Psso | |
| parent | c8998ccdff070d7c73a634e031a041260b87c3b1 (diff) | |
implement the rest of login process incl. cookie redirects and 'next'
Diffstat (limited to 'Psso')
| -rw-r--r-- | Psso/AuthInterface/Groups.php | 6 | ||||
| -rw-r--r-- | Psso/AuthInterface/UserExtra.php | 7 | ||||
| -rw-r--r-- | Psso/AuthProvider/ConfigFile.php | 21 | ||||
| -rw-r--r-- | Psso/Context.php | 3 | ||||
| -rw-r--r-- | Psso/Identity.php | 10 | ||||
| -rw-r--r-- | Psso/Session.php | 14 |
6 files changed, 54 insertions, 7 deletions
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 @@ +<?php +namespace Psso\AuthInterface; + +interface Groups { + public function userGroups(string $username): array; +} diff --git a/Psso/AuthInterface/UserExtra.php b/Psso/AuthInterface/UserExtra.php new file mode 100644 index 0000000..3a3de93 --- /dev/null +++ b/Psso/AuthInterface/UserExtra.php @@ -0,0 +1,7 @@ +<?php +namespace Psso\AuthInterface; + +interface UserExtra { + public function userDisplayName(string $username): ?string; + public function userEmailAddress(string $username): ?string; +} diff --git a/Psso/AuthProvider/ConfigFile.php b/Psso/AuthProvider/ConfigFile.php index 688c193..e9b45ce 100644 --- a/Psso/AuthProvider/ConfigFile.php +++ b/Psso/AuthProvider/ConfigFile.php @@ -1,9 +1,10 @@ <?php namespace Psso\AuthProvider; -use Psso\{AuthProvider, AuthInterface}; +use Psso\AuthProvider; +use Psso\AuthInterface\{Groups, Password, UserExists, UserExtra}; class ConfigFile extends AuthProvider -implements AuthInterface\Password, AuthInterface\UserExists { +implements Password, UserExists, UserExtra, Groups { public function validatePassword( string $username, #[\SensitiveParameter] string $password @@ -18,4 +19,20 @@ implements AuthInterface\Password, AuthInterface\UserExists { public function userExists(string $username): bool { return isset($this->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() |
