aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/OAuth2/Models/RefreshToken.php
blob: cf9a253e377096fb03cffea01c30ada9a2f57147 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php

namespace Studip\OAuth2\Models;

/**
 * @property int $id
 * @property string $access_token_id
 * @property string $client_id
 * @property bool $revoked
 * @property int $expires_at
 */
class RefreshToken extends \SimpleORMap
{
    use RevokedHelper;

    protected static function configure($config = [])
    {
        $config['db_table'] = 'oauth2_refresh_tokens';

        $config['belongs_to']['access_token'] = [
            'class_name'  => AccessToken::class,
            'foreign_key' => 'access_token_id',
        ];

        parent::configure($config);
    }

    /**
     * Revokes refresh tokens by access token id.
     *
     * @param string $tokenId
     */
    public static function revokeByAccessTokenId($tokenId): void
    {
        $refreshTokens = self::findBySQL('access_token_id = ?', [$tokenId]);
        foreach ($refreshTokens as $refreshToken) {
            $refreshToken->revoke();
        }
    }
}