Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
OidcSession
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
7 / 7
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAuthorizationState
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getAuthorizationState
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 clearAuthorizationState
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 setIdToken
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getIdToken
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 clearIdToken
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * OIDC session helper.
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2026 phpMyFAQ Team
13 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link      https://www.phpmyfaq.de
15 * @since     2026-04-18
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Auth\Oidc;
21
22use phpMyFAQ\Session\AbstractSession;
23use Symfony\Component\HttpFoundation\Session\Session;
24
25final class OidcSession extends AbstractSession
26{
27    final public const string OIDC_STATE = 'pmf-oidc-state';
28    final public const string OIDC_NONCE = 'pmf-oidc-nonce';
29    final public const string OIDC_PKCE_CODE = 'pmf-oidc-pkce-code';
30    final public const string OIDC_ID_ASSERTION = 'pmf-oidc-id-assertion';
31
32    public function __construct(Session $session)
33    {
34        parent::__construct($session);
35    }
36
37    public function setAuthorizationState(string $state, string $nonce, string $pkceVerifier): void
38    {
39        $this->set(self::OIDC_STATE, $state);
40        $this->set(self::OIDC_NONCE, $nonce);
41        $this->set(self::OIDC_PKCE_CODE, $pkceVerifier);
42    }
43
44    /**
45     * @return array{state: string, nonce: string, verifier: string}
46     */
47    public function getAuthorizationState(): array
48    {
49        return [
50            'state' => (string) $this->get(self::OIDC_STATE),
51            'nonce' => (string) $this->get(self::OIDC_NONCE),
52            'verifier' => (string) $this->get(self::OIDC_PKCE_CODE),
53        ];
54    }
55
56    public function clearAuthorizationState(): void
57    {
58        $this->set(self::OIDC_STATE, '');
59        $this->set(self::OIDC_NONCE, '');
60        $this->set(self::OIDC_PKCE_CODE, '');
61    }
62
63    public function setIdToken(#[\SensitiveParameter] string $idToken): void
64    {
65        $this->set(self::OIDC_ID_ASSERTION, $idToken);
66    }
67
68    public function getIdToken(): string
69    {
70        return (string) $this->get(self::OIDC_ID_ASSERTION);
71    }
72
73    public function clearIdToken(): void
74    {
75        $this->set(self::OIDC_ID_ASSERTION, '');
76    }
77}