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
36
36
*/
37
37
private static $ adminAuthTokens = [];
38
38
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
+
39
46
/**
40
47
* Return the API token for an admin user
41
48
* 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)
63
70
}
64
71
65
72
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
+ }
67
79
}
68
80
69
81
try {
@@ -97,6 +109,7 @@ public static function getAdminToken($username = null, $password = null)
97
109
$ token = json_decode ($ response );
98
110
if ($ token !== null ) {
99
111
self ::$ adminAuthTokens [$ login ] = $ token ;
112
+ self ::$ adminAuthTokenTimestamps [$ login ] = time ();
100
113
return $ token ;
101
114
}
102
115
$ errMessage = "Invalid response: {$ response }" ;
You can’t perform that action at this time.
0 commit comments