Skip to content

Commit 3831461

Browse files
committed
Add support for admin WebAPI token refresh
1 parent 9d86d8f commit 3831461

File tree

1 file changed

+21
-8
lines changed
  • src/Magento/FunctionalTestingFramework/DataTransport/Auth

1 file changed

+21
-8
lines changed

src/Magento/FunctionalTestingFramework/DataTransport/Auth/WebApiAuth.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,8 @@ public static function getAdminToken($username = null, $password = null)
6969
throw new FastFailException($message, $context);
7070
}
7171

72-
if (isset(self::$adminAuthTokens[$login])) {
73-
$tokenLifetime = getenv('MAGENTO_ADMIN_WEBAPI_TOKEN_LIFETIME');
74-
75-
$isTokenAboutToExpire = $tokenLifetime && time() - self::$adminAuthTokenTimestamps[$login] > $tokenLifetime;
76-
77-
if (!$isTokenAboutToExpire) {
78-
return self::$adminAuthTokens[$login];
79-
}
72+
if (self::hasExistingToken($login)) {
73+
return self::$adminAuthTokens[$login];
8074
}
8175

8276
try {
@@ -131,4 +125,23 @@ public static function getAdminToken($username = null, $password = null)
131125
$context = ['url' => $authUrl];
132126
throw new FastFailException($message, $context);
133127
}
128+
129+
/**
130+
* Is there an existing WebAPI admin token for this login?
131+
*
132+
* @param string $login
133+
* @return bool
134+
*/
135+
private static function hasExistingToken(string $login)
136+
{
137+
if (!isset(self::$adminAuthTokens[$login])) {
138+
return false;
139+
}
140+
141+
$tokenLifetime = getenv('MAGENTO_ADMIN_WEBAPI_TOKEN_LIFETIME');
142+
143+
$isTokenExpired = $tokenLifetime && time() - self::$adminAuthTokenTimestamps[$login] > $tokenLifetime;
144+
145+
return !$isTokenExpired;
146+
}
134147
}

0 commit comments

Comments
 (0)