Skip to content

Commit

Permalink
fix post oauth token method
Browse files Browse the repository at this point in the history
  • Loading branch information
lanlin committed Nov 23, 2021
1 parent 0235deb commit 2cc073a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
13 changes: 5 additions & 8 deletions src/Authentication/Hosted.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* ----------------------------------------------------------------------------------
*
* @author lanlin
* @change 2021/09/22
* @change 2021/11/23
*/
class Hosted
{
Expand Down Expand Up @@ -80,19 +80,16 @@ public function sendAuthorizationCode(string $code): array
{
V::doValidate(V::stringType()->notEmpty(), $code);

$query = [
'code' => $code,
'grant_type' => 'authorization_code',
];

$client = [
$params = [
'code' => $code,
'grant_type' => 'authorization_code',
'client_id' => $this->options->getClientId(),
'client_secret' => $this->options->getClientSecret(),
];

return $this->options
->getSync()
->setQuery(\array_merge($query, $client))
->setFormParams($params)
->post(API::LIST['oAuthToken']);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Webhooks/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(Options $options)
// ------------------------------------------------------------------------------

/**
* echo challenge to validate webhook
* echo challenge to validate webhook (for fpm mode)
*
* TIPS: you'd better use the output method from your framework.
*/
Expand All @@ -58,7 +58,7 @@ public function echoChallenge(): void
// ------------------------------------------------------------------------------

/**
* get notification & parse it
* get notification & parse it (for fpm mode)
*
* @return array
* [
Expand Down Expand Up @@ -87,7 +87,7 @@ public function getNotification(): array
// ------------------------------------------------------------------------------

/**
* webhook X-Nylas-Signature header verification
* webhook X-Nylas-Signature header verification (for other mode)
*
* @see https://docs.nylas.com/reference#receiving-notifications
*
Expand Down
13 changes: 7 additions & 6 deletions tests/Authentication/HostedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @see https://developer.nylas.com/docs/api/#tag--Hosted-Authentication
*
* @author lanlin
* @change 2021/09/22
* @change 2021/11/23
*
* @internal
*/
Expand Down Expand Up @@ -42,15 +42,16 @@ public function testSendAuthorizationCode(): void
$code = $this->faker->postcode;

$this->mockResponse([
'client_id' => $this->faker->uuid,
'client_secret' => $this->faker->email,
'grant_type' => 'authorization_code',
'code' => $this->faker->postcode,
'provider' => 'gmail',
'token_type' => 'bearer',
'account_id' => $this->faker->md5,
'access_token' => $this->faker->md5,
'email_address' => $this->faker->email,
]);

$data = $this->client->Authentication->Hosted->sendAuthorizationCode($code);

$this->assertTrue(!empty($data['client_id']));
$this->assertTrue(!empty($data['access_token']));
}

// ------------------------------------------------------------------------------
Expand Down

0 comments on commit 2cc073a

Please sign in to comment.