Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.00% covered (warning)
80.00%
4 / 5
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
AuthKey
80.00% covered (warning)
80.00%
4 / 5
80.00% covered (warning)
80.00%
4 / 5
5.20
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getModule
n/a
0 / 0
n/a
0 / 0
0
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFriendlyName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCreatedTimestamp
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 supportsPasswordlessLogin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 verify
n/a
0 / 0
n/a
0 / 0
0
1<?php
2
3namespace MediaWiki\Extension\OATHAuth\Key;
4
5use JsonSerializable;
6use MediaWiki\Extension\OATHAuth\OATHUser;
7
8abstract class AuthKey implements JsonSerializable {
9
10    protected bool $supportsPasswordless = false;
11
12    public function __construct(
13        protected readonly ?int $id,
14        protected ?string $friendlyName,
15        protected readonly ?string $createdTimestamp,
16    ) {
17    }
18
19    /**
20     * @return string The name of the module this key is attached to
21     * @see IModule::getName()
22     */
23    abstract public function getModule(): string;
24
25    /**
26     * @return int|null the ID of this key in the oathauth_devices table, or null if this key has not been saved yet
27     */
28    public function getId(): ?int {
29        return $this->id;
30    }
31
32    /**
33     * @return string|null the user generated name of this key in the oathauth_devices table,
34     * or null if this key was created before this data was saved in the database
35     */
36    public function getFriendlyName(): ?string {
37        return $this->friendlyName;
38    }
39
40    /**
41     * @return string|null the timestamp of this key in the oathauth_devices table, or null if this key was created
42     * before timestamp data was saved in the database
43     */
44    public function getCreatedTimestamp(): ?string {
45        return $this->createdTimestamp;
46    }
47
48    /**
49     * @return bool whether the auth key supports passwordless login or not
50     */
51    public function supportsPasswordlessLogin(): bool {
52        return $this->supportsPasswordless;
53    }
54
55    abstract public function verify( OATHUser $user, array $data ): bool;
56}