1 | <?php |
||
9 | class ApiKey |
||
10 | { |
||
11 | use AdjustUrl; |
||
12 | |||
13 | /** @var \GuzzleHttp\Client */ |
||
14 | protected $client; |
||
15 | |||
16 | /** @var Headers */ |
||
17 | protected $headers; |
||
18 | |||
19 | /** @var string The environment this is being run in */ |
||
20 | protected $environment; |
||
21 | |||
22 | /** The URI of the action */ |
||
23 | const URI = 'https://api.signere.no/api/ApiToken'; |
||
24 | |||
25 | /** |
||
26 | * Instantiate the class. |
||
27 | * |
||
28 | * @param Client $client |
||
29 | * @param Headers $headers |
||
30 | * @param string $environment |
||
31 | */ |
||
32 | 5 | public function __construct(Client $client, Headers $headers, $environment = null) |
|
38 | |||
39 | /** |
||
40 | * Renews the primary API key. |
||
41 | * |
||
42 | * @param string $key |
||
43 | * @return object |
||
44 | */ |
||
45 | 1 | public function renewPrimary(string $key) |
|
62 | |||
63 | /** |
||
64 | * Renews the secondary API key. |
||
65 | * |
||
66 | * @param string $key |
||
67 | * @return object |
||
68 | */ |
||
69 | 1 | public function renewSecondary(string $key) |
|
86 | |||
87 | /** |
||
88 | * Generate a new primary key and return it. |
||
89 | * |
||
90 | * @param string $providerId |
||
91 | * @param int $otpCode |
||
92 | * @return object |
||
93 | */ |
||
94 | 1 | public function createPrimary(string $providerId, int $otpCode) |
|
95 | { |
||
96 | // make the URL for this request |
||
97 | 1 | $url = $this->transformUrl(sprintf( |
|
98 | 1 | '%s/OTP/RenewPrimaryKeyStep2/Provider/%s/OTPCode/%s', |
|
99 | 1 | self::URI, |
|
100 | 1 | $providerId, |
|
101 | 1 | $otpCode |
|
102 | )); |
||
103 | |||
104 | // get the headers for this request |
||
105 | 1 | $headers = $this->headers->make('POST', $url, [], null); |
|
106 | |||
107 | // get the response |
||
108 | 1 | $response = $this->client->post($url, [ |
|
109 | 1 | 'headers' => $headers, |
|
110 | 'json' => [], |
||
111 | ]); |
||
112 | |||
113 | // return the response |
||
114 | 1 | return $response; |
|
115 | } |
||
116 | |||
117 | /** |
||
118 | * Sends an OTP code in an SMS to |
||
119 | * the given mobile number. |
||
120 | * |
||
121 | * @param array $body |
||
122 | * @return object |
||
123 | */ |
||
124 | 1 | public function recoverPrimary(array $body) |
|
155 | } |
||
156 |