mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-13 13:46:13 +00:00
refactored code
Signed-off-by: Maurice Preuß (envoyr) <hello@envoyr.com>
This commit is contained in:
35
src/Id/OauthTrait.php
Normal file
35
src/Id/OauthTrait.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Anikeen\Id;
|
||||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
|
||||
trait OauthTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* Retrieving an oauth token using a given grant type.
|
||||
*/
|
||||
public function retrievingToken(string $grantType, array $attributes): Result
|
||||
{
|
||||
try {
|
||||
$response = $this->client->request('POST', '/oauth/token', [
|
||||
'form_params' => $attributes + [
|
||||
'grant_type' => $grantType,
|
||||
'client_id' => $this->getClientId(),
|
||||
'client_secret' => $this->getClientSecret(),
|
||||
],
|
||||
]);
|
||||
|
||||
$result = new Result($response, null);
|
||||
} catch (RequestException $exception) {
|
||||
$result = new Result($exception->getResponse(), $exception);
|
||||
}
|
||||
|
||||
$result->anikeenId = $this;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user