Skip to content

Commit 2cc073a

Browse files
committed
fix post oauth token method
1 parent 0235deb commit 2cc073a

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

src/Authentication/Hosted.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* ----------------------------------------------------------------------------------
1313
*
1414
* @author lanlin
15-
* @change 2021/09/22
15+
* @change 2021/11/23
1616
*/
1717
class Hosted
1818
{
@@ -80,19 +80,16 @@ public function sendAuthorizationCode(string $code): array
8080
{
8181
V::doValidate(V::stringType()->notEmpty(), $code);
8282

83-
$query = [
84-
'code' => $code,
85-
'grant_type' => 'authorization_code',
86-
];
87-
88-
$client = [
83+
$params = [
84+
'code' => $code,
85+
'grant_type' => 'authorization_code',
8986
'client_id' => $this->options->getClientId(),
9087
'client_secret' => $this->options->getClientSecret(),
9188
];
9289

9390
return $this->options
9491
->getSync()
95-
->setQuery(\array_merge($query, $client))
92+
->setFormParams($params)
9693
->post(API::LIST['oAuthToken']);
9794
}
9895

src/Webhooks/Signature.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(Options $options)
3737
// ------------------------------------------------------------------------------
3838

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

6060
/**
61-
* get notification & parse it
61+
* get notification & parse it (for fpm mode)
6262
*
6363
* @return array
6464
* [
@@ -87,7 +87,7 @@ public function getNotification(): array
8787
// ------------------------------------------------------------------------------
8888

8989
/**
90-
* webhook X-Nylas-Signature header verification
90+
* webhook X-Nylas-Signature header verification (for other mode)
9191
*
9292
* @see https://docs.nylas.com/reference#receiving-notifications
9393
*

tests/Authentication/HostedTest.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @see https://developer.nylas.com/docs/api/#tag--Hosted-Authentication
1313
*
1414
* @author lanlin
15-
* @change 2021/09/22
15+
* @change 2021/11/23
1616
*
1717
* @internal
1818
*/
@@ -42,15 +42,16 @@ public function testSendAuthorizationCode(): void
4242
$code = $this->faker->postcode;
4343

4444
$this->mockResponse([
45-
'client_id' => $this->faker->uuid,
46-
'client_secret' => $this->faker->email,
47-
'grant_type' => 'authorization_code',
48-
'code' => $this->faker->postcode,
45+
'provider' => 'gmail',
46+
'token_type' => 'bearer',
47+
'account_id' => $this->faker->md5,
48+
'access_token' => $this->faker->md5,
49+
'email_address' => $this->faker->email,
4950
]);
5051

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

53-
$this->assertTrue(!empty($data['client_id']));
54+
$this->assertTrue(!empty($data['access_token']));
5455
}
5556

5657
// ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)