Skip to content

Commit e4c90ec

Browse files
committed
remerge gnp
2 parents 3680db7 + 1137c3e commit e4c90ec

File tree

7 files changed

+108
-35
lines changed

7 files changed

+108
-35
lines changed

README.md

Lines changed: 98 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,81 @@ If you would like to have the system randomly pick a FROM number from the number
445445
leave off the second parameter to `\Vonage\Voice\OutboundCall`'s constructor, and the system will select a number
446446
at random for you.
447447

448-
## Using the Conversations API
448+
### Using the SimSwap API
449+
450+
SimSwap uses CAMARA standards in order to determine how long a SIM has been inside a cellular device. This
451+
means the auth mechanism is slightly more complex than other APIs. You will need:
452+
453+
> To have your own *Subscriber Number* that has been registered with the Vonage Global Network Platform.
454+
> Your Dashboard Application ID
455+
> Your Private Key
456+
457+
### Using the Number Verification API
458+
459+
Number Verification uses CAMARA API standards and is used to determine whether a request is valid. Unlike other SDKs,
460+
the SDK is split between the start of the process and the end of the process.
461+
462+
You will need:
463+
464+
> To have your own *Subscriber Number* that has been registered with the Vonage Global Network Platform.
465+
> Your Dashboard Application ID
466+
> Your Private Key, downloaded from the Vonage Dashboard
467+
468+
#### Usage
469+
470+
1. Your backend needs to serve a custom URL that will be used to fire off the verification request. To do
471+
this, use the `buildFrontEndUrl()` method on the client. When calling this, you'll need to supply the route
472+
your application is expected to receive a callback from containing a unique `code`. You will need to have an
473+
authorised phone number in an authorised territory for this to work. Here is dummy example:
474+
475+
```php
476+
class VerificationController extends MyFrameworkAbsractController
477+
{
478+
$credentials = new \Vonage\Client\Credentials\Gnp(
479+
'077380777111',
480+
file_get_contents('../private.key'),
481+
'0dadaeb4-7c79-4d39-b4b0-5a6cc08bf537'
482+
)
483+
484+
$client = new \Vonage\Client($credentials);
485+
486+
$verifyUrl = $client->numberVerification()->buildFrontEndUrl(
487+
'07777777777',
488+
'https://myapp.com/auth/numberVerify'
489+
);
490+
491+
return $this->render('verify.html.twig', [
492+
'verifyLink' => $verifyUrl
493+
]);
494+
}
495+
```
496+
497+
2. Your backend then needs to be able to configured to consume the incoming webhook. The SDK will take care
498+
care of handling the Auth methods required to do this, once you have extracted the `code`.
499+
The method returns a boolean from the API. Here is an example:
500+
501+
```php
502+
$code = $request->get('code');
503+
504+
$result = $client->numberVerification()->verifyNumber(
505+
'09947777777',
506+
$code
507+
);
508+
509+
if ($result) {
510+
Auth::login($request->user())
511+
}
512+
513+
return redirect('login');
514+
}
515+
```
516+
517+
### Using the Conversations API
449518

450519
This API is used for in-app messaging and is contains a wide range of features and
451-
concepts. For more information, take a look at the [API Documentation]()
520+
concepts. For more information, take a look at the [API Documentation](https://developer.vonage.com/en/api/conversation?source=conversation)
452521

453-
### Retrieve a list of Conversations with Filter
522+
#### Retrieve a list of Conversations with Filter
454523

455524
```php
456525
$credentials = new \Vonage\Client\Credentials\Keypair(file_get_contents('./path-to-my-key.key', 'my-app-id'));
@@ -464,7 +533,7 @@ $conversations = $client->conversations()->listConversations($filter)
464533
var_dump($conversations);
465534
```
466535

467-
### Create a Conversation
536+
#### Create a Conversation
468537

469538
```php
470539

@@ -490,7 +559,7 @@ var_dump($response);
490559

491560
```
492561

493-
### List Members in a Conversation
562+
#### List Members in a Conversation
494563

495564
```php
496565

@@ -516,7 +585,7 @@ var_dump($members);
516585

517586
```
518587

519-
### Create a Member in a Conversation
588+
#### Create a Member in a Conversation
520589

521590
```php
522591

@@ -1200,29 +1269,29 @@ var_dump($response);
12001269

12011270
## Supported APIs
12021271

1203-
| API | API Release Status | Supported? |
1204-
|------------------------|:--------------------:|:----------:|
1205-
| Account API | General Availability ||
1206-
| Alerts API | General Availability ||
1207-
| Application API | General Availability ||
1208-
| Audit API | Beta ||
1209-
| Conversation API | Beta ||
1210-
| Dispatch API | Beta ||
1211-
| External Accounts API | Beta ||
1212-
| Media API | Beta ||
1213-
| Meetings API | General Availability ||
1214-
| Messages API | General Availability ||
1215-
| Number Insight API | General Availability ||
1216-
| Number Management API | General Availability ||
1217-
| Pricing API | General Availability ||
1218-
| ProActive Connect API | Beta ||
1219-
| Redact API | General Availability ||
1220-
| Reports API | Beta ||
1221-
| SMS API | General Availability ||
1222-
| Subaccounts API | General Availability ||
1223-
| Verify API | General Availability ||
1224-
| Verify API (Version 2) | General Availability ||
1225-
| Voice API | General Availability ||
1272+
| API | API Release Status | Supported? |
1273+
|-------------------------|:--------------------:|:----------:|
1274+
| Account API | General Availability ||
1275+
| Alerts API | General Availability ||
1276+
| Application API | General Availability ||
1277+
| Audit API | Beta ||
1278+
| Conversation API | Beta ||
1279+
| Dispatch API | Beta ||
1280+
| External Accounts API | Beta ||
1281+
| Media API | Beta ||
1282+
| Meetings API | General Availability ||
1283+
| Messages API | General Availability ||
1284+
| Number Insight API | General Availability ||
1285+
| Number Management API | General Availability ||
1286+
| Pricing API | General Availability ||
1287+
| ProActive Connect API | Beta ||
1288+
| Redact API | General Availability ||
1289+
| Reports API | Beta ||
1290+
| SMS API | General Availability ||
1291+
| Subaccounts API | General Availability ||
1292+
| Verify API | General Availability ||
1293+
| Verify API (Version 2) | General Availability ||
1294+
| Voice API | General Availability ||
12261295

12271296
## Troubleshooting
12281297

src/Client.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use Vonage\Insights\ClientFactory as InsightsClientFactory;
4343
use Vonage\Meetings\ClientFactory as MeetingsClientFactory;
4444
use Vonage\Numbers\ClientFactory as NumbersClientFactory;
45+
use Vonage\NumberVerification\ClientFactory as NumberVerificationClientFactory;
4546
use Vonage\Redact\ClientFactory as RedactClientFactory;
4647
use Vonage\Secrets\ClientFactory as SecretsClientFactory;
4748
use Vonage\SimSwap\ClientFactory as SimSwapClientFactory;
@@ -79,6 +80,7 @@
7980
* @method Conversation\Client conversation()
8081
* @method Insights\Client insights()
8182
* @method Numbers\Client numbers()
83+
* @method NumberVerification\Client numberVerification()
8284
* @method Redact\Client redact()
8385
* @method Secrets\Client secrets()
8486
* @method SimSwap\Client simswap()
@@ -218,6 +220,7 @@ public function __construct(
218220
'conversation' => ConversationClientFactory::class,
219221
'insights' => InsightsClientFactory::class,
220222
'numbers' => NumbersClientFactory::class,
223+
'numberVerification' => NumberVerificationClientFactory::class,
221224
'meetings' => MeetingsClientFactory::class,
222225
'messages' => MessagesClientFactory::class,
223226
'redact' => RedactClientFactory::class,

src/Client/APIResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function addAuth(RequestInterface $request): RequestInterface
7676
break;
7777
} catch (\RuntimeException $e) {
7878
continue; // We are OK if multiple are sent but only one match
79+
// This has a really nasty side effect for complex handlers where we never see the error
7980
}
8081
throw new \RuntimeException(
8182
'Unable to set credentials, please check configuration and

src/NumberVerification/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public function verifyNumber(string $phoneNumber, string $code, string $state):
5151
$phoneNumberKey = 'hashedPhoneNumber';
5252
}
5353

54-
// By the time this hits Number Verification, the handler will have
55-
// completed the OAuth flow
54+
// By the time this hits the Number Verification API, the handler will have
55+
// completed the CAMARA OAuth flow
5656
$response = $this->getAPIResource()->create(
5757
[$phoneNumberKey => $phoneNumber],
5858
'verify'

src/NumberVerification/ClientFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
use Psr\Container\ContainerInterface;
66
use Vonage\Client\APIResource;
7-
use Vonage\Client\Credentials\Handler\SimSwapGnpHandler;
7+
use Vonage\Client\Credentials\Handler\NumberVerificationGnpHandler;
88

99
class ClientFactory
1010
{
1111
public function __invoke(ContainerInterface $container): Client
1212
{
13-
$handler = new SimSwapGnpHandler();
13+
$handler = new NumberVerificationGnpHandler();
1414
$handler->setBaseUrl('https://oidc.idp.vonage.com/oauth2/auth');
1515
$handler->setTokenUrl('https://api-eu.vonage.com/oauth2/token');
1616
$handler->setScope('openid+dpv:FraudPreventionAndDetection#number-verification-verify-read');
@@ -23,6 +23,7 @@ public function __invoke(ContainerInterface $container): Client
2323
$api
2424
->setBaseUrl('https://api-eu.vonage.com/camara/number-verification/v031')
2525
->setIsHAL(false)
26+
->setClient($client)
2627
->setErrorsOn200(false)
2728
->setAuthHandlers($handler);
2829

src/SimSwap/ClientFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public function __invoke(ContainerInterface $container): Client
1313
$handler = new SimSwapGnpHandler();
1414
$handler->setBaseUrl('https://api-eu.vonage.com/oauth2/bc-authorize');
1515
$handler->setTokenUrl('https://api-eu.vonage.com/oauth2/token');
16-
$handler->setScope('openid dpv:FraudPreventionAndDetection#check-sim-swap');
1716

1817
$client = $container->get(\Vonage\Client::class);
1918
$handler->setClient($client);
@@ -23,6 +22,7 @@ public function __invoke(ContainerInterface $container): Client
2322
$api
2423
->setBaseUrl('https://api-eu.vonage.com/camara/sim-swap/v040')
2524
->setIsHAL(false)
25+
->setClient($client)
2626
->setErrorsOn200(false)
2727
->setAuthHandlers($handler);
2828

test/SimSwap/ClientTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public function setUp(): void
4343
$handler = new Client\Credentials\Handler\SimSwapGnpHandler();
4444
$handler->setBaseUrl('https://api-eu.vonage.com/oauth2/bc-authorize');
4545
$handler->setTokenUrl('https://api-eu.vonage.com/oauth2/token');
46-
// $handler->setScope('dpv:FraudPreventionAndDetection#check-sim-swap');
4746
$handler->setClient($revealedClient);
4847

4948
$this->api = (new APIResource())

0 commit comments

Comments
 (0)