1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Superbrave\AuthZeroHttpClient; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* The object containing the configuration values required for successful Machine-to-Machine |
7
|
|
|
* authentication with Auth0 using the Oauth2 Client Credentials Flow. |
8
|
|
|
* |
9
|
|
|
* @author Niels Nijens <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
readonly class AuthZeroConfiguration |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Constructs a new AuthZeroConfiguration instance. |
15
|
|
|
* |
16
|
|
|
* @param string $tenantUri Your Auth0 tenant URL |
17
|
|
|
* @param string $clientId Your application's Client ID |
18
|
|
|
* @param string $clientSecret Your application's Client Secret |
19
|
|
|
* @param string $audience The unique identifier of the target API you want to access |
20
|
|
|
*/ |
21
|
8 |
|
public function __construct( |
22
|
|
|
private string $tenantUri, |
23
|
|
|
private string $clientId, |
24
|
|
|
private string $clientSecret, |
25
|
|
|
private string $audience |
26
|
|
|
) { |
27
|
8 |
|
} |
28
|
|
|
|
29
|
4 |
|
public function getAudience(): string |
30
|
|
|
{ |
31
|
4 |
|
return $this->audience; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns the URL to request an Auth0 access token. |
36
|
|
|
*/ |
37
|
5 |
|
public function getTenantTokenUrl(): string |
38
|
|
|
{ |
39
|
5 |
|
return sprintf('%s/oauth/token', $this->tenantUri); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Returns the payload required to request an Auth0 access token. |
44
|
|
|
*/ |
45
|
5 |
|
public function getAuthenticationPayload(): array |
46
|
|
|
{ |
47
|
5 |
|
return [ |
48
|
5 |
|
'client_id' => $this->clientId, |
49
|
5 |
|
'client_secret' => $this->clientSecret, |
50
|
5 |
|
'audience' => $this->audience, |
51
|
5 |
|
'grant_type' => 'client_credentials', |
52
|
5 |
|
]; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|