44
55use Micro \Plugin \Security \Business \Token \Decoder \DecoderFactoryInterface ;
66use Micro \Plugin \Security \Configuration \Provider \ProviderConfigurationInterface ;
7- use Micro \Plugin \Security \Exception \TokenExpiredException ;
87use Micro \Plugin \Security \Business \Token \Encoder \EncoderFactoryInterface ;
98use Micro \Plugin \Security \Token \Token ;
109use Micro \Plugin \Security \Token \TokenInterface ;
@@ -27,25 +26,14 @@ public function __construct(
2726 /**
2827 * {@inheritDoc}
2928 */
30- public function generateToken (array $ sourceData, int $ lifetime = null ): TokenInterface
29+ public function generateToken (array $ sourceData ): TokenInterface
3130 {
32- $ createdAt = time ();
33- $ lifetime = $ lifetime ?: $ this ->providerConfiguration ->getLifetimeDefault ();
34-
35- $ tokenContainerData = [
36- TokenInterface::TOKEN_PARAM_DATA => $ sourceData ,
37- TokenInterface::TOKEN_PARAM_LIFETIME => $ lifetime ,
38- TokenInterface::TOKEN_PARAM_CREATED_AT => $ createdAt ,
39- ];
40-
4131 $ generatedTokenString = $ this ->encoderFactory
4232 ->create ($ this ->providerConfiguration )
43- ->encode ($ tokenContainerData );
33+ ->encode ($ sourceData );
4434
4535 return $ this ->createToken (
4636 $ generatedTokenString ,
47- $ createdAt ,
48- $ lifetime ,
4937 $ sourceData
5038 );
5139 }
@@ -60,31 +48,21 @@ public function decodeToken(string $encoded): TokenInterface
6048 ->decode ($ encoded );
6149
6250 return $ this ->createToken (
63- $ encoded ,
64- createdAt: $ decoded [TokenInterface::TOKEN_PARAM_CREATED_AT ],
65- lifetime: $ decoded [TokenInterface::TOKEN_PARAM_LIFETIME ],
66- tokenData: (array ) $ decoded [TokenInterface::TOKEN_PARAM_DATA ]
51+ encoded: $ encoded ,
52+ tokenData: $ decoded
6753 );
6854 }
6955
7056 /**
7157 * @param string $encoded
72- * @param int $createdAt
73- * @param int $lifetime
7458 * @param array $tokenData
7559 *
7660 * @return Token
7761 */
78- protected function createToken (string $ encoded , int $ createdAt , int $ lifetime , array $ tokenData ): TokenInterface
62+ protected function createToken (string $ encoded , array $ tokenData ): TokenInterface
7963 {
80- if ($ lifetime > 0 && (time () > $ lifetime + $ createdAt )) {
81- throw new TokenExpiredException ($ encoded );
82- }
83-
8464 return new Token (
8565 source: $ encoded ,
86- createdAt: $ createdAt ,
87- lifetime: $ lifetime ,
8866 parameters: $ tokenData
8967 );
9068 }
0 commit comments