@@ 62-81 (lines=20) @@ | ||
59 | * @throws GuzzleException |
|
60 | * @throws ServerException |
|
61 | */ |
|
62 | public function loginTenant(string $email, string $password): string |
|
63 | { |
|
64 | $response = $this->httpClient->request( |
|
65 | 'POST', '/tenant/login', [ |
|
66 | 'json' => [ |
|
67 | 'email' => $email, |
|
68 | 'password' => $password, |
|
69 | ], |
|
70 | ] |
|
71 | ); |
|
72 | ||
73 | $result = json_decode($response->getBody()->getContents(), true); |
|
74 | if (array_key_exists('accessToken', $result)) { |
|
75 | $token = $result['accessToken']; |
|
76 | } else { |
|
77 | throw new AccessTokenNotFound(); |
|
78 | } |
|
79 | ||
80 | return $token; |
|
81 | } |
|
82 | ||
83 | /** |
|
84 | * @param string $tenantToken |
|
@@ 90-108 (lines=19) @@ | ||
87 | * @throws DecodedSectionNotFound |
|
88 | * @throws ServerException |
|
89 | */ |
|
90 | public function verifyTenantToken(string $tenantToken): TenantTokenVerificationResult |
|
91 | { |
|
92 | $response = $this->httpClient->request( |
|
93 | 'POST', '/tenant/verify', [ |
|
94 | 'json' => [ |
|
95 | 'token' => $tenantToken, |
|
96 | ], |
|
97 | ] |
|
98 | ); |
|
99 | ||
100 | $responseData = json_decode($response->getBody()->getContents(), true); |
|
101 | if (! array_key_exists('decoded', $responseData)) { |
|
102 | throw new DecodedSectionNotFound('Decoded section not found'); |
|
103 | } |
|
104 | ||
105 | $params = $responseData['decoded']; |
|
106 | ||
107 | return new TenantTokenVerificationResult($params); |
|
108 | } |
|
109 | ||
110 | /** |
|
111 | * @param string $tenantToken |
|
@@ 170-192 (lines=23) @@ | ||
167 | * @throws AccessTokenNotFound |
|
168 | * @throws ServerException |
|
169 | */ |
|
170 | public function loginUser(array $data, string $tenantToken): string |
|
171 | { |
|
172 | $response = $this->httpClient->request( |
|
173 | 'POST', |
|
174 | '/auth', |
|
175 | [ |
|
176 | 'json' => $data, |
|
177 | 'headers' => [ |
|
178 | 'Authorization' => 'Bearer '.$tenantToken, |
|
179 | ], |
|
180 | ] |
|
181 | ); |
|
182 | ||
183 | $result = json_decode($response->getBody()->getContents(), true); |
|
184 | ||
185 | if (array_key_exists('accessToken', $result)) { |
|
186 | $token = $result['accessToken']; |
|
187 | } else { |
|
188 | throw new AccessTokenNotFound(); |
|
189 | } |
|
190 | ||
191 | return $token; |
|
192 | } |
|
193 | ||
194 | /** |
|
195 | * @param string $userToken |