Completed
Push — master ( 138234...77e005 )
by Anton
12s
created

AbstractProvider::authenticate()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Bluz PHP Team
4
 * @link      https://github.com/bluzphp/skeleton
5
 */
6
7
declare(strict_types=1);
8
9
namespace Application\Auth\Provider;
10
11
use \Application\Auth\Row;
12
use \Application\Auth\Table;
13
use \Application\Users\Row as User;
14
15
/**
16
 * AbstractProvider
17
 *
18
 * @package  Application\Auth\Provider
19
 * @author   Anton Shevchuk
20
 */
21
abstract class AbstractProvider
22
{
23
    const PROVIDER = 'abstract';
24
25
    /**
26
     * Authenticate user by token
27
     *
28
     * @param string $token
29
     *
30
     * @return void
31
     * @throws \Application\Exception
32
     * @throws \Bluz\Auth\AuthException
33
     */
34
    abstract public static function authenticate($token);
35
36
    /**
37
     * Check if supplied cookie is valid
38
     *
39
     * @param string $token
40
     *
41
     * @return Row
42
     * @throws \Bluz\Auth\AuthException
43
     */
44
    abstract public static function verify($token) : Row;
45
46
    /**
47
     * Create and save Auth record, and send cookies
48
     *
49
     * @param User $user
50
     *
51
     * @return Row
52
     * @throws \Application\Exception
53
     * @throws \Bluz\Auth\AuthException
54
     */
55
    abstract public static function create($user) : Row;
56
57
    /**
58
     * Remove Auth record by user ID
59
     *
60
     * @param integer $id User ID
61
     *
62
     * @return void
63
     * @throws \Bluz\Db\Exception\DbException
64
     */
65 2
    public static function remove($id)
66
    {
67
        // clear previous generated Auth record
68
        // works with change password
69 2
        Table::delete(
70
            [
71 2
                'userId' => $id,
72 2
                'provider' => static::PROVIDER,
73 2
                'tokenType' => Table::TYPE_ACCESS
74
            ]
75
        );
76 2
    }
77
}
78