From 2cc073a72cae4ddd2fff0ebb7b1b1a6c93ae1096 Mon Sep 17 00:00:00 2001 From: lanlin Date: Tue, 23 Nov 2021 18:32:08 +0800 Subject: [PATCH] fix post oauth token method --- src/Authentication/Hosted.php | 13 +++++-------- src/Webhooks/Signature.php | 6 +++--- tests/Authentication/HostedTest.php | 13 +++++++------ 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Authentication/Hosted.php b/src/Authentication/Hosted.php index 790102d..f62d58d 100644 --- a/src/Authentication/Hosted.php +++ b/src/Authentication/Hosted.php @@ -12,7 +12,7 @@ * ---------------------------------------------------------------------------------- * * @author lanlin - * @change 2021/09/22 + * @change 2021/11/23 */ class Hosted { @@ -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']); } diff --git a/src/Webhooks/Signature.php b/src/Webhooks/Signature.php index d2705d1..325f111 100644 --- a/src/Webhooks/Signature.php +++ b/src/Webhooks/Signature.php @@ -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. */ @@ -58,7 +58,7 @@ public function echoChallenge(): void // ------------------------------------------------------------------------------ /** - * get notification & parse it + * get notification & parse it (for fpm mode) * * @return array * [ @@ -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 * diff --git a/tests/Authentication/HostedTest.php b/tests/Authentication/HostedTest.php index c132817..2a99bb2 100644 --- a/tests/Authentication/HostedTest.php +++ b/tests/Authentication/HostedTest.php @@ -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 */ @@ -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'])); } // ------------------------------------------------------------------------------