Skip to content

Commit

Permalink
webhook verification token
Browse files Browse the repository at this point in the history
  • Loading branch information
yparitcher committed Nov 25, 2024
1 parent ddae715 commit 1635824
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ RINGCENTRAL_CLIENT_ID=
RINGCENTRAL_CLIENT_SECRET=
RINGCENTRAL_SERVER_URL=
RINGCENTRAL_JWT=
RINGCENTRAL_VERIFICATION_TOKEN=

#The below are only used for the test suite
RINGCENTRAL_SENDER=
RINGCENTRAL_RECEIVER=
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
RINGCENTRAL_CLIENT_SECRET: ${{ secrets.RINGCENTRAL_CLIENT_SECRET }}
RINGCENTRAL_SERVER_URL: ${{ secrets.RINGCENTRAL_SERVER_URL }}
RINGCENTRAL_JWT: ${{ secrets.RINGCENTRAL_JWT }}
RINGCENTRAL_VERIFICATION_TOKEN: ${{ secrets.RINGCENTRAL_VERIFICATION_TOKEN }}
RINGCENTRAL_SENDER: ${{ secrets.RINGCENTRAL_SENDER }}
RINGCENTRAL_RECEIVER: ${{ secrets.RINGCENTRAL_RECEIVER }}
RINGCENTRAL_DELAY_REQUEST_SECONDS: ${{ secrets.RINGCENTRAL_DELAY_REQUEST_SECONDS }}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ RINGCENTRAL_CLIENT_ID=my_client_id
RINGCENTRAL_CLIENT_SECRET=my_client_secret
RINGCENTRAL_SERVER_URL=my_server_url
RINGCENTRAL_JWT=my_jwt
RINGCENTRAL_VERIFICATION_TOKEN=my_verification_token
```
This package uses the JWT autentication method. You can learn more about setting up JWT for your RingCentral account [here](https://developers.ringcentral.com/guide/authentication/jwt/quick-start).

Expand Down
1 change: 1 addition & 0 deletions config/ringcentral.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
'client_secret' => function_exists('env') ? env('RINGCENTRAL_CLIENT_SECRET', '') : '',
'server_url' => function_exists('env') ? env('RINGCENTRAL_SERVER_URL', '') : '',
'jwt' => function_exists('env') ? env('RINGCENTRAL_JWT', '') : '',
'verification_token' => function_exists('env') ? env('RINGCENTRAL_VERIFICATION_TOKEN', '') : '',
];
14 changes: 7 additions & 7 deletions src/RingCentral.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,32 @@ class RingCentral {
protected string $clientId;
protected string $clientSecret;
protected string $jwt;
protected string $verification_token;
protected string $loggedInExtension;
protected string $loggedInExtensionId;

public function setClientId(string $clientId): static {
$this->clientId = $clientId;

return $this;
}

public function setClientSecret(string $clientSecret): static {
$this->clientSecret = $clientSecret;

return $this;
}

public function setServerUrl(string $serverUrl): static {
$this->serverUrl = $serverUrl;

return $this;
}

public function setjWT(string $jwt): static {
$this->jwt = $jwt;
return $this;
}

public function setVerificationToken(string $verification_token): static {
$this->verification_token = $verification_token;
return $this;
}

Expand Down Expand Up @@ -252,18 +254,16 @@ public function listWebhooks(): Collection {
return $this->get('/subscription')->collect('records');
}

public function createWebhook(array $filters, int $expiresIn, string $address, ?string $verificationToken = null): Response {
public function createWebhook(array $filters, int $expiresIn, string $address): Response {
$data = [
'eventFilters' => $filters,
'expiresIn' => $expiresIn,
'deliveryMode' => [
'transportType' => 'WebHook',
'address' => $address,
'verificationToken' => $this->verification_token,
],
];
if ($verificationToken) {
$data['deliveryMode']['verificationToken'] = $verificationToken;
}
return $this->post('/subscription', $data);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/RingCentralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ protected function setUp(): void {
->setClientId(env('RINGCENTRAL_CLIENT_ID'))
->setClientSecret(env('RINGCENTRAL_CLIENT_SECRET'))
->setServerUrl(env('RINGCENTRAL_SERVER_URL'))
->setJwt(env('RINGCENTRAL_JWT'));
->setJwt(env('RINGCENTRAL_JWT'))
->setVerificationToken(env('RINGCENTRAL_VERIFICATION_TOKEN'));

$this->delay();
}
Expand Down

0 comments on commit 1635824

Please sign in to comment.