File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
src/Magento/FunctionalTestingFramework/DataTransport/Auth Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,13 @@ class WebApiAuth
3636 */
3737 private static $ adminAuthTokens = [];
3838
39+ /**
40+ * Timestamps of when admin user tokens were created. They need to be refreshed every ~4 hours
41+ *
42+ * @var int[]
43+ */
44+ private static $ adminAuthTokenTimestamps = [];
45+
3946 /**
4047 * Return the API token for an admin user
4148 * Use MAGENTO_ADMIN_USERNAME and MAGENTO_ADMIN_PASSWORD when $username and/or $password is/are omitted
@@ -63,7 +70,12 @@ public static function getAdminToken($username = null, $password = null)
6370 }
6471
6572 if (isset (self ::$ adminAuthTokens [$ login ])) {
66- return self ::$ adminAuthTokens [$ login ];
73+ $ threeHours = 60 * 60 * 3 ;
74+ $ isTokenAboutToExpire = time () - self ::$ adminAuthTokenTimestamps [$ login ] > $ threeHours ;
75+
76+ if (!$ isTokenAboutToExpire ) {
77+ return self ::$ adminAuthTokens [$ login ];
78+ }
6779 }
6880
6981 try {
@@ -97,6 +109,7 @@ public static function getAdminToken($username = null, $password = null)
97109 $ token = json_decode ($ response );
98110 if ($ token !== null ) {
99111 self ::$ adminAuthTokens [$ login ] = $ token ;
112+ self ::$ adminAuthTokenTimestamps [$ login ] = time ();
100113 return $ token ;
101114 }
102115 $ errMessage = "Invalid response: {$ response }" ;
You can’t perform that action at this time.
0 commit comments