mirror of
https://github.com/bitinflow/accounts.git
synced 2026-03-13 13:35:52 +00:00
Add oauth token method
This commit is contained in:
@@ -165,6 +165,12 @@ public function createDocument(array $parameters)
|
||||
public function createDocumentDownloadUrl(string $identifier, CarbonInterface $expiresAt = NULL)
|
||||
```
|
||||
|
||||
### Oauth
|
||||
|
||||
```php
|
||||
public function retrievingToken(string $grantType, array $attributes)
|
||||
```
|
||||
|
||||
### PaymentIntents
|
||||
|
||||
```php
|
||||
|
||||
@@ -20,6 +20,7 @@ class BitinflowAccounts
|
||||
|
||||
use Traits\ChargesTrait;
|
||||
use Traits\DocumentsTrait;
|
||||
use Traits\OauthTrait;
|
||||
use Traits\PaymentIntentsTrait;
|
||||
use Traits\SshKeysTrait;
|
||||
use Traits\UsersTrait;
|
||||
|
||||
44
src/GhostZero/BitinflowAccounts/Traits/OauthTrait.php
Normal file
44
src/GhostZero/BitinflowAccounts/Traits/OauthTrait.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GhostZero\BitinflowAccounts\Traits;
|
||||
|
||||
use GhostZero\BitinflowAccounts\Result;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
trait OauthTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* Retrieving a oauth token using a given grant type.
|
||||
*
|
||||
* @param string $grantType
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return Result
|
||||
*/
|
||||
public function retrievingToken(string $grantType, array $attributes): Result
|
||||
{
|
||||
try {
|
||||
$response = $this->client->request('POST', '/oauth/token', $attributes + [
|
||||
'form_params' => [
|
||||
'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->bitinflow = $this;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
25
tests/GhostZero/BitinflowAccounts/ApiOauthTest.php
Normal file
25
tests/GhostZero/BitinflowAccounts/ApiOauthTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GhostZero\BitinflowAccounts\Tests;
|
||||
|
||||
use GhostZero\BitinflowAccounts\Tests\TestCases\ApiTestCase;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
class ApiOauthTest extends ApiTestCase
|
||||
{
|
||||
|
||||
public function testGetOauthToken(): void
|
||||
{
|
||||
$this->getClient()->withClientId('5');
|
||||
$this->getClient()->withClientSecret('jejmtAJJWeEesW1siWwojjLn6zW9AIcWH1wqfFPq');
|
||||
$this->registerResult($result = $this->getClient()->retrievingToken('client_credentials', [
|
||||
'scope' => '',
|
||||
]));
|
||||
$this->assertTrue($result->success());
|
||||
$this->assertNotEmpty($result->data()->access_token);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user