Skip to content

Commit 1e0bd96

Browse files
Fix getToken call
1 parent 91dbfcc commit 1e0bd96

File tree

6 files changed

+8
-33
lines changed

6 files changed

+8
-33
lines changed

php/src/vaas/Authentication/AuthenticatorInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace VaasSdk\Authentication;
44

55
use Amp\Cancellation;
6+
use Amp\Future;
67

78
interface AuthenticatorInterface
89
{
9-
public function getToken(?Cancellation $cancellation = null): string;
10+
public function getTokenAsync(?Cancellation $cancellation = null): Future;
1011
}

php/src/vaas/Authentication/ClientCredentialsGrantAuthenticator.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace VaasSdk\Authentication;
44

5-
use Amp\Cancellation;
65
use Amp\Http\Client\HttpClient;
76

87
class ClientCredentialsGrantAuthenticator extends TokenReceiver implements AuthenticatorInterface
@@ -24,18 +23,6 @@ public function __construct(string $clientId, string $clientSecret, ?string $tok
2423
$this->clientSecret = $clientSecret;
2524
}
2625

27-
/**
28-
* Gets the access token asynchronously.
29-
* If the token is still valid, it will be returned immediately.
30-
* If the token is expired, a new token will be requested.
31-
* @param Cancellation|null $cancellation Cancellation token
32-
* @return string The access token string
33-
*/
34-
public function getToken(Cancellation $cancellation = null): string
35-
{
36-
return parent::getTokenAsync($cancellation)->await($cancellation);
37-
}
38-
3926
protected function tokenRequestToForm(): string
4027
{
4128
return http_build_query([

php/src/vaas/Authentication/ResourceOwnerPasswordGrantAuthenticator.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace VaasSdk\Authentication;
44

5-
use Amp\Cancellation;
65
use Amp\Http\Client\HttpClient;
76

87
class ResourceOwnerPasswordGrantAuthenticator extends TokenReceiver implements AuthenticatorInterface
@@ -28,18 +27,6 @@ public function __construct(string $clientId, string $userName, string $password
2827
$this->password = $password;
2928
}
3029

31-
/**
32-
* Gets the access token asynchronously.
33-
* If the token is still valid, it will be returned immediately.
34-
* If the token is expired, a new token will be requested.
35-
* @param Cancellation|null $cancellation Cancellation token
36-
* @return string The access token string
37-
*/
38-
public function getToken(Cancellation $cancellation = null): string
39-
{
40-
return parent::getTokenAsync($cancellation)->await($cancellation);
41-
}
42-
4330
protected function tokenRequestToForm(): string
4431
{
4532
return http_build_query([

php/src/vaas/Options/VaasOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class VaasOptions
1414
public function __construct(
1515
public bool $useHashLookup = true,
1616
public bool $useCache = true,
17-
public string $vaasUrl = 'https://gateway.production.vaas.gdatasecurity.de/',
17+
public string $vaasUrl = 'https://gateway.production.vaas.gdatasecurity.de',
1818
public int $timeout = 300
1919
) {}
2020
}

php/src/vaas/Vaas.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ private function addRequestHeadersAsync(Request $request, ?string $requestId = '
324324
{
325325
return async(function () use ($request, $requestId) {
326326
$this->logger->debug("Add request headers");
327-
$request->setHeader('Authorization', 'Bearer ' . $this->authenticator->getToken());
327+
$request->setHeader('Authorization', 'Bearer ' . $this->authenticator->getTokenAsync()->await());
328328
$this->logger->debug("Successfully added authorization header with bearer token");
329329
$request->setHeader('User-Agent', sprintf('%s/%s', self::PRODUCT_NAME, self::PRODUCT_VERSION));
330330
if (!empty($requestId)) {

php/tests/VaasTesting/AuthenticatorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function testClientCredentialsGrantAuthenticator_withInvalidCredentials_T
5656
clientSecret: "invalid"
5757
);
5858

59-
$authenticator->getToken();
59+
$authenticator->getTokenAsync()->await();
6060
}
6161

6262
public function testResourceOwnerPasswordGrantAuthenticator_withInvalidCredentials_ThrowsAccessDeniedException(): void
@@ -68,7 +68,7 @@ public function testResourceOwnerPasswordGrantAuthenticator_withInvalidCredentia
6868
password: "invalid"
6969
);
7070

71-
$authenticator->getToken();
71+
$authenticator->getTokenAsync()->await();
7272
}
7373

7474
public function testClientCredentialsGrantAuthenticator_withValidCredentials_ReturnsToken(): void
@@ -79,7 +79,7 @@ public function testClientCredentialsGrantAuthenticator_withValidCredentials_Ret
7979
tokenUrl: $_ENV["TOKEN_URL"]
8080
);
8181

82-
$token = $authenticator->getToken();
82+
$token = $authenticator->getTokenAsync()->await();
8383

8484
$this->assertNotNull($token);
8585
}
@@ -93,7 +93,7 @@ public function testResourceOwnerPasswordGrantAuthenticator_withValidCredentials
9393
tokenUrl: $_ENV["TOKEN_URL"]
9494
);
9595

96-
$token = $authenticator->getToken();
96+
$token = $authenticator->getTokenAsync()->await();
9797

9898
$this->assertNotNull($token);
9999
}

0 commit comments

Comments
 (0)