AuthZeroConfiguration::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 2
b 0
f 0
nc 1
nop 4
dl 0
loc 6
ccs 1
cts 1
cp 1
crap 1
rs 10
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