• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

valkyrjaio / valkyrja / 15659546660

15 Jun 2025 04:39AM UTC coverage: 47.202% (-0.4%) from 47.589%
15659546660

push

github

MelechMizrachi
Update Config.

5331 of 11294 relevant lines covered (47.2%)

16.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Valkyrja/Auth/Repository/ApiTokenizedRepository.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <melechmizrachi@gmail.com>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace Valkyrja\Auth\Repository;
15

16
use Valkyrja\Auth\Entity\Contract\TokenizableUser;
17
use Valkyrja\Exception\RuntimeException;
18

19
use function is_string;
20

21
/**
22
 * Class ApiTokenizedRepository.
23
 *
24
 * Use this repository in case an api provides a token you need to use for requests,
25
 *  but you cannot decrypt it in your application. Note that this will still require a user to
26
 *  be set via setUser() to work properly.
27
 *
28
 * @author Melech Mizrachi
29
 *
30
 * @property TokenizableUser $user
31
 */
32
class ApiTokenizedRepository extends Repository implements Contract\TokenizedRepository
33
{
34
    /**
35
     * The token.
36
     *
37
     * @var string
38
     */
39
    protected string $token;
40

41
    /**
42
     * @inheritDoc
43
     */
44
    public function authenticateFromSession(): static
45
    {
46
        parent::authenticateFromSession();
×
47

48
        $this->user::setTokenized($this->getToken());
×
49

50
        return $this;
×
51
    }
52

53
    /**
54
     * @inheritDoc
55
     */
56
    public function setSession(): static
57
    {
58
        parent::setSession();
×
59

60
        $this->session->set($this->user::getTokenSessionId(), $this->getToken());
×
61

62
        return $this;
×
63
    }
64

65
    /**
66
     * @inheritDoc
67
     */
68
    public function getToken(): string
69
    {
70
        return $this->token
×
71
            ??= $this->getTokenFromSession();
×
72
    }
73

74
    /**
75
     * @inheritDoc
76
     */
77
    public function authenticateFromToken(string $token): static
78
    {
79
        $this->token = $token;
×
80

81
        return $this;
×
82
    }
83

84
    /**
85
     * Get the token from the session.
86
     *
87
     * @return string
88
     */
89
    protected function getTokenFromSession(): string
90
    {
91
        $token = $this->session->get($this->user::getTokenSessionId());
×
92

93
        if (! is_string($token)) {
×
94
            throw new RuntimeException('Invalid session token');
×
95
        }
96

97
        return $token;
×
98
    }
99
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc