File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed
app/code/Magento/Integration/Model Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 20
20
use Magento \Integration \Helper \Oauth \Data as OauthHelper ;
21
21
22
22
/**
23
+ * Reads user token data
24
+ *
23
25
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
24
26
*/
25
27
class Reader implements UserTokenReaderInterface
@@ -112,6 +114,7 @@ private function getTokenModel(string $token): Token
112
114
* Validate the given user type
113
115
*
114
116
* @param int $userType
117
+ * @throws UserTokenException
115
118
*/
116
119
private function validateUserType (int $ userType ): void
117
120
{
Original file line number Diff line number Diff line change @@ -34,10 +34,30 @@ public function __construct(DtUtil $datetimeUtil)
34
34
*/
35
35
public function validate (UserToken $ token ): void
36
36
{
37
- if ($ token ->getUserContext ()->getUserType () !== UserContextInterface::USER_TYPE_INTEGRATION
38
- && $ token ->getData ()->getExpires ()->getTimestamp () <= $ this ->datetimeUtil ->gmtTimestamp ()
39
- ) {
37
+ if (!$ this ->isIntegrationToken ($ token ) && $ this ->isTokenExpired ($ token )) {
40
38
throw new AuthorizationException (__ ('Consumer key has expired ' ));
41
39
}
42
40
}
41
+
42
+ /**
43
+ * Check if a token is expired
44
+ *
45
+ * @param UserToken $token
46
+ * @return bool
47
+ */
48
+ private function isTokenExpired (UserToken $ token ): bool
49
+ {
50
+ return $ token ->getData ()->getExpires ()->getTimestamp () <= $ this ->datetimeUtil ->gmtTimestamp ();
51
+ }
52
+
53
+ /**
54
+ * Check if a token is an integration token
55
+ *
56
+ * @param UserToken $token
57
+ * @return bool
58
+ */
59
+ private function isIntegrationToken (UserToken $ token ): bool
60
+ {
61
+ return $ token ->getUserContext ()->getUserType () === UserContextInterface::USER_TYPE_INTEGRATION ;
62
+ }
43
63
}
You can’t perform that action at this time.
0 commit comments