-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished GNP Auth and SimSwap MVP implementation (#475)
* Finished GNP Auth and SimSwap MVP implementation * Add documentation * PSR-4 fix * clean imports * Finished GNP Auth and SimSwap MVP implementation * bring psr7 trait back (#482) * Fix broken git history
- Loading branch information
Showing
47 changed files
with
692 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vonage\Client\Credentials; | ||
|
||
class Gnp extends Keypair | ||
{ | ||
public function __construct(protected string $msisdn, protected string $key, $application = null) | ||
{ | ||
parent::__construct($key, $application); | ||
} | ||
|
||
public function getMsisdn(): string | ||
{ | ||
return $this->msisdn; | ||
} | ||
|
||
public function setMsisdn(string $msisdn): Gnp | ||
{ | ||
$this->msisdn = $msisdn; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Vonage\Client\Credentials\Handler; | ||
|
||
use Psr\Http\Message\RequestInterface; | ||
use Vonage\Client; | ||
use Vonage\Client\APIResource; | ||
use Vonage\Client\Credentials\CredentialsInterface; | ||
use Vonage\Client\Credentials\Gnp; | ||
|
||
/** | ||
* This handler is for Vonage GNP APIs that require the CAMARA standard OAuth Flow | ||
*/ | ||
class GnpHandler extends AbstractHandler | ||
{ | ||
use Client\ClientAwareTrait; | ||
use Client\ScopeAwareTrait; | ||
|
||
protected const VONAGE_GNP_AUTH_BACKEND_URL = 'https://api-eu.vonage.com/oauth2/bc-authorize'; | ||
protected const VONAGE_GNP_AUTH_TOKEN_URL = 'https://api-eu.vonage.com/oauth2/token'; | ||
protected const VONAGE_GNP_AUTH_TOKEN_GRANT_TYPE = 'urn:openid:params:grant-type:ciba'; | ||
|
||
public function __invoke(RequestInterface $request, CredentialsInterface $credentials): RequestInterface | ||
{ | ||
/** @var Gnp $credentials */ | ||
$credentials = $this->extract(Gnp::class, $credentials); | ||
$msisdn = $credentials->getMsisdn(); | ||
|
||
// Request OIDC, returns Auth Request ID | ||
// Reconfigure new client for GNP Auth | ||
$api = new APIResource(); | ||
$api->setAuthHandlers(new KeypairHandler()); | ||
$api->setClient($this->getClient()); | ||
$api->setBaseUrl(self::VONAGE_GNP_AUTH_BACKEND_URL); | ||
|
||
// This handler requires an injected client configured with a Gnp credentials object and a configured scope | ||
$response = $api->submit([ | ||
'login_hint' => $msisdn, | ||
'scope' => $this->getScope() | ||
]); | ||
|
||
$decoded = json_decode($response, true, 512, JSON_THROW_ON_ERROR); | ||
|
||
$authReqId = $decoded['auth_req_id']; | ||
|
||
// CAMARA Access Token | ||
$api->setBaseUrl(self::VONAGE_GNP_AUTH_TOKEN_URL); | ||
$response = $api->submit([ | ||
'grant_type' => self::VONAGE_GNP_AUTH_TOKEN_GRANT_TYPE, | ||
'auth_req_id' => $authReqId | ||
]); | ||
|
||
$decoded = json_decode($response, true, 512, JSON_THROW_ON_ERROR); | ||
|
||
$token = $decoded['access_token']; | ||
|
||
// Add CAMARA Access Token to request and return to make API call | ||
return $request->withHeader('Authorization', 'Bearer ' . $token); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vonage\Client; | ||
|
||
use RuntimeException; | ||
use Vonage\Client; | ||
|
||
trait ScopeAwareTrait | ||
{ | ||
protected ?string $scope = null; | ||
|
||
public function setScope(string $scope): self | ||
{ | ||
$this->scope = $scope; | ||
|
||
return $this; | ||
} | ||
|
||
public function getScope(): ?string | ||
{ | ||
return $this->scope; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.