-
-
Notifications
You must be signed in to change notification settings - Fork 452
Expand file tree
/
Copy pathAppCheck.php
More file actions
51 lines (41 loc) · 1.58 KB
/
AppCheck.php
File metadata and controls
51 lines (41 loc) · 1.58 KB
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
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace Kreait\Firebase;
use Kreait\Firebase\AppCheck\ApiClient;
use Kreait\Firebase\AppCheck\AppCheckToken;
use Kreait\Firebase\AppCheck\AppCheckTokenGenerator;
use Kreait\Firebase\AppCheck\AppCheckTokenOptions;
use Kreait\Firebase\AppCheck\AppCheckTokenVerifier;
use Kreait\Firebase\AppCheck\VerifyAppCheckTokenResponse;
use Kreait\Firebase\Contract\AppCheckWithReplayProtection;
use SensitiveParameter;
use function is_array;
/**
* @internal
*/
final readonly class AppCheck implements Contract\AppCheck, AppCheckWithReplayProtection
{
public function __construct(
private ApiClient $client,
private AppCheckTokenGenerator $tokenGenerator,
private AppCheckTokenVerifier $tokenVerifier,
) {
}
public function createToken(string $appId, AppCheckTokenOptions|array|null $options = null): AppCheckToken
{
if (is_array($options)) {
$options = AppCheckTokenOptions::fromArray($options);
}
$customToken = $this->tokenGenerator->createCustomToken($appId, $options);
$result = $this->client->exchangeCustomToken($appId, $customToken);
return AppCheckToken::fromArray($result);
}
public function verifyToken(#[SensitiveParameter] string $appCheckToken): VerifyAppCheckTokenResponse
{
return $this->tokenVerifier->verifyToken($appCheckToken);
}
public function verifyTokenWithReplayProtection(#[SensitiveParameter] string $appCheckToken): VerifyAppCheckTokenResponse
{
return $this->tokenVerifier->verifyToken($appCheckToken, true);
}
}