@@ -324,19 +324,14 @@ private static function generatePayload(array $config, array $extend): array
324324 private static function getPublicKey (string $ algorithm , int $ tokenType = self ::ACCESS_TOKEN ): string
325325 {
326326 $ config = self ::_getConfig ();
327- switch ($ algorithm ) {
328- case 'HS256 ' :
329- $ key = self ::ACCESS_TOKEN == $ tokenType ? $ config ['access_secret_key ' ] : $ config ['refresh_secret_key ' ];
330- break ;
331- case 'RS512 ' :
332- case 'RS256 ' :
333- $ key = self ::ACCESS_TOKEN == $ tokenType ? $ config ['access_public_key ' ] : $ config ['refresh_public_key ' ];
334- break ;
335- default :
336- $ key = $ config ['access_secret_key ' ];
327+
328+ $ isAccessToken = $ tokenType === self ::ACCESS_TOKEN ;
329+
330+ if (in_array ($ algorithm , ['HS512 ' , 'HS384 ' , 'HS256 ' ], true )) {
331+ return $ isAccessToken ? $ config ['access_secret_key ' ] : $ config ['refresh_secret_key ' ];
337332 }
338333
339- return $ key ;
334+ return $ isAccessToken ? $ config [ ' access_public_key ' ] : $ config [ ' refresh_public_key ' ] ;
340335 }
341336
342337 /**
@@ -347,19 +342,13 @@ private static function getPublicKey(string $algorithm, int $tokenType = self::A
347342 */
348343 private static function getPrivateKey (array $ config , int $ tokenType = self ::ACCESS_TOKEN ): string
349344 {
350- switch ($ config ['algorithms ' ]) {
351- case 'HS256 ' :
352- $ key = self ::ACCESS_TOKEN == $ tokenType ? $ config ['access_secret_key ' ] : $ config ['refresh_secret_key ' ];
353- break ;
354- case 'RS512 ' :
355- case 'RS256 ' :
356- $ key = self ::ACCESS_TOKEN == $ tokenType ? $ config ['access_private_key ' ] : $ config ['refresh_private_key ' ];
357- break ;
358- default :
359- $ key = $ config ['access_secret_key ' ];
345+ $ isAccessToken = $ tokenType === self ::ACCESS_TOKEN ;
346+
347+ if (in_array ($ config ['algorithms ' ], ['HS512 ' , 'HS384 ' , 'HS256 ' ], true )) {
348+ return $ isAccessToken ? $ config ['access_secret_key ' ] : $ config ['refresh_secret_key ' ];
360349 }
361350
362- return $ key ;
351+ return $ isAccessToken ? $ config [ ' access_private_key ' ] : $ config [ ' refresh_private_key ' ] ;
363352 }
364353
365354 /**
0 commit comments