@@ -107,7 +107,7 @@ public function isLoggedIn()
107107 * @param array $data
108108 * @return AuthSession
109109 */
110- public function login (string $ accountTypeName , array $ data ):AuthSession
110+ public function login (string $ accountTypeName , array $ data ): AuthSession
111111 {
112112 if (!$ account = $ this ->getAccountType ($ accountTypeName )) {
113113 throw new AuthException (ErrorCode::AUTH_INVALID_ACCOUNT_TYPE );
@@ -121,7 +121,7 @@ public function login(string $accountTypeName, array $data):AuthSession
121121 if ($ this ->cacheEnable === true ) {
122122 try {
123123 $ this ->getCacheClient ()->set (
124- $ this ->getCacheKey ($ result ->getIdentity ()),
124+ $ this ->getCacheKey ($ result ->getIdentity (), $ result -> getExtendedData () ),
125125 $ session ->getToken (),
126126 $ session ->getExpirationTime ()
127127 );
@@ -133,9 +133,12 @@ public function login(string $accountTypeName, array $data):AuthSession
133133 return $ session ;
134134 }
135135
136- protected function getCacheKey ($ identity )
136+ protected function getCacheKey (string $ identity, array $ extendedData )
137137 {
138- return $ this ->prefix . $ identity ;
138+ if (empty ($ extendedData )) {
139+ return $ this ->prefix . $ identity ;
140+ }
141+ return $ this ->prefix . $ identity . (string )$ extendedData [0 ];
139142 }
140143
141144 /**
@@ -218,7 +221,7 @@ public function getCacheClient()
218221 * @return bool
219222 * @throws AuthException
220223 */
221- public function authenticateToken (string $ token ):bool
224+ public function authenticateToken (string $ token ): bool
222225 {
223226 try {
224227 /** @var AuthSession $session */
@@ -245,7 +248,7 @@ public function authenticateToken(string $token):bool
245248
246249 if ($ this ->cacheEnable === true ) {
247250 try {
248- $ cache = $ this ->getCacheClient ()->get ($ this ->getCacheKey ($ session ->getIdentity ()));
251+ $ cache = $ this ->getCacheClient ()->get ($ this ->getCacheKey ($ session ->getIdentity (), $ session -> getExtendedData () ));
249252 if (!$ cache || $ cache !== $ token ) {
250253 throw new AuthException (ErrorCode::AUTH_TOKEN_INVALID );
251254 }
0 commit comments