-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
550caf5
commit 947a077
Showing
19 changed files
with
458 additions
and
204 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace VaasSdk\Authentication; | ||
|
||
use Amp\Cancellation; | ||
use Amp\Future; | ||
|
||
interface AuthenticatorInterface | ||
{ | ||
public function getTokenAsync(?Cancellation $cancellation = null): Future; | ||
} |
46 changes: 46 additions & 0 deletions
46
php/src/vaas/Authentication/ClientCredentialsGrantAuthenticator.php
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,46 @@ | ||
<?php | ||
|
||
namespace VaasSdk\Authentication; | ||
|
||
use Amp\Cancellation; | ||
use Amp\Future; | ||
use Amp\Http\Client\HttpClient; | ||
use VaasSdk\Options\AuthenticationOptions; | ||
use function Amp\async; | ||
|
||
class ClientCredentialsGrantAuthenticator implements AuthenticatorInterface | ||
{ | ||
private TokenReceiver $tokenReceiver; | ||
|
||
/** | ||
* The authenticator for the client credentials grant type if you have a client id and client secret. | ||
* @param string $clientId The client id | ||
* @param string $clientSecret The client secret | ||
* @param string|null $tokenUrl The optional token url. Defaults to 'https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token' | ||
* @param HttpClient|null $httpClient Your optional custom http client. | ||
*/ | ||
public function __construct(string $clientId, string $clientSecret, ?string $tokenUrl = null, ?HttpClient $httpClient = null) | ||
{ | ||
$options = new AuthenticationOptions( | ||
grantType: GrantType::CLIENT_CREDENTIALS, | ||
clientId: $clientId, | ||
tokenUrl: $tokenUrl ?? 'https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token', | ||
clientSecret: $clientSecret | ||
); | ||
$this->tokenReceiver = new TokenReceiver($options, $httpClient); | ||
} | ||
|
||
/** | ||
* Gets the access token asynchronously. | ||
* If the token is still valid, it will be returned immediately. | ||
* If the token is expired, a new token will be requested. | ||
* @param Cancellation|null $cancellation Cancellation token | ||
* @return Future Future that resolves to the access token string | ||
*/ | ||
public function getTokenAsync(?Cancellation $cancellation = null): Future | ||
{ | ||
return async(function () use ($cancellation) { | ||
return $this->tokenReceiver->getTokenAsync($cancellation)->await(); | ||
}); | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
php/src/vaas/Authentication/ResourceOwnerPasswordGrantAuthenticator.php
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,49 @@ | ||
<?php | ||
|
||
namespace VaasSdk\Authentication; | ||
|
||
use Amp\Cancellation; | ||
use Amp\Future; | ||
use Amp\Http\Client\HttpClient; | ||
use VaasSdk\Options\AuthenticationOptions; | ||
use function Amp\async; | ||
|
||
class ResourceOwnerPasswordGrantAuthenticator implements AuthenticatorInterface | ||
{ | ||
private TokenReceiver $tokenReceiver; | ||
|
||
/** | ||
* The authenticator for the resource owner password grant type if you have a client id, username and password. | ||
* This is the choice if you have registered yourself on https://vaas.gdata.de/login. In this case, the client id is `vaas-customer`. | ||
* @param string $clientId The client id | ||
* @param string $userName Your username or email | ||
* @param string $password Your password | ||
* @param string|null $tokenUrl The optional token url. Defaults to 'https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token' | ||
* @param HttpClient|null $httpClient Your optional custom http client. | ||
*/ | ||
public function __construct(string $clientId, string $userName, string $password, ?string $tokenUrl = null, ?HttpClient $httpClient = null) | ||
{ | ||
$options = new AuthenticationOptions( | ||
grantType: GrantType::PASSWORD, | ||
clientId: $clientId, | ||
tokenUrl: $tokenUrl ?? 'https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token', | ||
userName: $userName, | ||
password: $password | ||
); | ||
$this->tokenReceiver = new TokenReceiver($options, $httpClient); | ||
} | ||
|
||
/** | ||
* Gets the access token asynchronously. | ||
* If the token is still valid, it will be returned immediately. | ||
* If the token is expired, a new token will be requested. | ||
* @param Cancellation|null $cancellation Cancellation token | ||
* @return Future Future that resolves to the access token string | ||
*/ | ||
public function getTokenAsync(?Cancellation $cancellation = null): Future | ||
{ | ||
return async(function () use ($cancellation) { | ||
return $this->tokenReceiver->getTokenAsync($cancellation)->await(); | ||
}); | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace VaasSdk\Exceptions; | ||
|
||
use Exception; | ||
|
||
class FileDoesNotExistException extends Exception | ||
{ | ||
public function __construct(string $message = 'File does not exist', int $code = 0, Exception $previous = null) | ||
{ | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace VaasSdk\Exceptions; | ||
|
||
use Exception; | ||
|
||
class InvalidSha256Exception extends Exception | ||
{ | ||
public function __construct(string $message = 'Invalid SHA256 hash', int $code = 0, Exception $previous = null) | ||
{ | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
Oops, something went wrong.