|
24 | 24 | use CodeIgniter\Shield\Entities\UserIdentity; |
25 | 25 | use CodeIgniter\Shield\Exceptions\LogicException; |
26 | 26 | use CodeIgniter\Shield\Exceptions\ValidationException; |
27 | | -use DateInterval; |
28 | | -use DateTime; |
29 | 27 | use Exception; |
30 | 28 | use Faker\Generator; |
31 | 29 | use InvalidArgumentException; |
@@ -104,39 +102,6 @@ private function checkUserId(User $user): void |
104 | 102 | } |
105 | 103 | } |
106 | 104 |
|
107 | | - private function checkExpiresAtFormat(string $expiresAt): string |
108 | | - { |
109 | | - $expireMatch = []; |
110 | | - |
111 | | - // Check Y-m-d h:i:s format. |
112 | | - preg_match('/\d{4}-\d{2}-\d{2}.\d{2}:\d{2}:\d{2}/', $expiresAt, $expireMatch, PREG_UNMATCHED_AS_NULL); |
113 | | - |
114 | | - // Format Y-m-d h:i:s not found. |
115 | | - if ($expireMatch === []) { |
116 | | - // Looking for relative format like 1 day, 2 weeks and process all |
117 | | - preg_match_all('/[1].(second|minute|hour|day|week|month|year)|[2,3,4,5,6,7,8,9].(seconds|minutes|hours|days|weeks|months|years)/', $expiresAt, $expireMatch, PREG_PATTERN_ORDER); |
118 | | - |
119 | | - if ($expireMatch[0] !== []) { |
120 | | - // Dummy DateTime to add() DateInterval |
121 | | - $dateTime = new DateTime(); |
122 | | - |
123 | | - // Turn the preg_match array into string splitted by ' + ' |
124 | | - // to be fed into DateTime->add() to generate new date |
125 | | - $relativeTime = implode(' + ', $expireMatch[0]); |
126 | | - |
127 | | - // add relative formats |
128 | | - $dateTime->add(DateInterval::createFromDateString($relativeTime)); |
129 | | - |
130 | | - // return Dummy DateTime |
131 | | - return $dateTime->format('Y-m-d h:i:s'); |
132 | | - } |
133 | | - |
134 | | - throw new InvalidArgumentException('$expiresAt should be a DateTime string formatted as "Y-m-d h:i:s" or a DateTime relative formats.'); |
135 | | - } |
136 | | - |
137 | | - return $expiresAt; |
138 | | - } |
139 | | - |
140 | 105 | /** |
141 | 106 | * Create an identity with 6 digits code for auth action |
142 | 107 | * |
@@ -190,10 +155,6 @@ public function generateAccessToken(User $user, string $name, array $scopes = [' |
190 | 155 | { |
191 | 156 | $this->checkUserId($user); |
192 | 157 |
|
193 | | - // if ($expiresAt !== null && $expiresAt !== '' && $expiresAt !== '0') { |
194 | | - // $expiresAt = $this->checkExpiresAtFormat($expiresAt); |
195 | | - // } |
196 | | - |
197 | 158 | helper('text'); |
198 | 159 |
|
199 | 160 | $return = $this->insert([ |
@@ -320,10 +281,6 @@ public function generateHmacToken(User $user, string $name, array $scopes = ['*' |
320 | 281 | { |
321 | 282 | $this->checkUserId($user); |
322 | 283 |
|
323 | | - // if ($expiresAt !== null && $expiresAt !== '' && $expiresAt !== '0') { |
324 | | - // $expiresAt = $this->checkExpiresAtFormat($expiresAt); |
325 | | - // } |
326 | | - |
327 | 284 | $encrypter = new HmacEncrypter(); |
328 | 285 | $rawSecretKey = $encrypter->generateSecretKey(); |
329 | 286 | $secretKey = $encrypter->encrypt($rawSecretKey); |
|
0 commit comments