Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
RefreshTokenRepository
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 5
56
0.00% covered (danger)
0.00%
0 / 1
 getNewRefreshToken
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 persistNewRefreshToken
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
12
 revokeRefreshToken
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isRefreshTokenRevoked
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getCacheKeyType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\OAuth\Repository;
4
5use InvalidArgumentException;
6use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
7use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException;
8use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
9use MediaWiki\Extension\OAuth\Entity\RefreshTokenEntity;
10
11class RefreshTokenRepository extends CacheRepository implements RefreshTokenRepositoryInterface {
12
13    /**
14     * Creates a new refresh token
15     *
16     * @return RefreshTokenEntityInterface|null
17     */
18    public function getNewRefreshToken() {
19        return new RefreshTokenEntity();
20    }
21
22    /**
23     * Create a new refresh token_name.
24     *
25     * @param RefreshTokenEntityInterface $refreshTokenEntity
26     *
27     * @throws UniqueTokenIdentifierConstraintViolationException
28     */
29    public function persistNewRefreshToken( RefreshTokenEntityInterface $refreshTokenEntity ) {
30        if ( !$refreshTokenEntity instanceof RefreshTokenEntity ) {
31            throw new InvalidArgumentException(
32                '$refreshTokenEntity must be instance of ' .
33                RefreshTokenEntity::class . ', got ' . get_class( $refreshTokenEntity ) . ' instead'
34            );
35        }
36        if ( $this->has( $refreshTokenEntity->getIdentifier() ) ) {
37            throw UniqueTokenIdentifierConstraintViolationException::create();
38        }
39
40        $this->set(
41            $refreshTokenEntity->getIdentifier(),
42            $refreshTokenEntity->jsonSerialize(),
43            $refreshTokenEntity->getExpiryDateTime()->getTimestamp()
44        );
45    }
46
47    /**
48     * Revoke the refresh token.
49     *
50     * @param string $tokenId
51     */
52    public function revokeRefreshToken( $tokenId ) {
53        $this->delete( $tokenId );
54    }
55
56    /**
57     * Check if the refresh token has been revoked.
58     *
59     * @param string $tokenId
60     *
61     * @return bool Return true if this token has been revoked
62     */
63    public function isRefreshTokenRevoked( $tokenId ) {
64        return $this->has( $tokenId ) === false;
65    }
66
67    /**
68     * Get object type for session key
69     *
70     * @return string
71     */
72    protected function getCacheKeyType(): string {
73        return "RefreshToken";
74    }
75}