55use Carbon \Carbon ;
66use DateInterval ;
77use DateTimeInterface ;
8+ use Illuminate \Contracts \Encryption \Encrypter ;
89use League \OAuth2 \Server \ResourceServer ;
910use Mockery ;
1011use Psr \Http \Message \ServerRequestInterface ;
@@ -38,23 +39,50 @@ class Passport
3839 * The date when access tokens expire.
3940 *
4041 * @var \DateTimeInterface|null
42+ *
43+ * @deprecated Will be removed in the next major Passport release.
4144 */
4245 public static $ tokensExpireAt ;
4346
47+ /**
48+ * The interval when access tokens expire.
49+ *
50+ * @var \DateInterval|null
51+ */
52+ public static $ tokensExpireIn ;
53+
4454 /**
4555 * The date when refresh tokens expire.
4656 *
4757 * @var \DateTimeInterface|null
58+ *
59+ * @deprecated Will be removed in the next major Passport release.
4860 */
4961 public static $ refreshTokensExpireAt ;
5062
63+ /**
64+ * The date when refresh tokens expire.
65+ *
66+ * @var \DateInterval|null
67+ */
68+ public static $ refreshTokensExpireIn ;
69+
5170 /**
5271 * The date when personal access tokens expire.
5372 *
5473 * @var \DateTimeInterface|null
74+ *
75+ * @deprecated Will be removed in the next major Passport release.
5576 */
5677 public static $ personalAccessTokensExpireAt ;
5778
79+ /**
80+ * The date when personal access tokens expire.
81+ *
82+ * @var \DateInterval|null
83+ */
84+ public static $ personalAccessTokensExpireIn ;
85+
5886 /**
5987 * The name for API token cookies.
6088 *
@@ -133,10 +161,19 @@ class Passport
133161 public static $ unserializesCookies = false ;
134162
135163 /**
164+ * Indicates if client secrets will be hashed.
165+ *
136166 * @var bool
137167 */
138168 public static $ hashesClientSecrets = false ;
139169
170+ /**
171+ * The callback that should be used to generate JWT encryption keys.
172+ *
173+ * @var callable
174+ */
175+ public static $ tokenEncryptionKeyCallback ;
176+
140177 /**
141178 * Indicates the scope should inherit its parent scope.
142179 *
@@ -235,12 +272,11 @@ public static function tokensCan(array $scopes)
235272 public static function tokensExpireIn (DateTimeInterface $ date = null )
236273 {
237274 if (is_null ($ date )) {
238- return static ::$ tokensExpireAt
239- ? Carbon::now ()->diff (static ::$ tokensExpireAt )
240- : new DateInterval ('P1Y ' );
275+ return static ::$ tokensExpireIn ?? new DateInterval ('P1Y ' );
241276 }
242277
243278 static ::$ tokensExpireAt = $ date ;
279+ static ::$ tokensExpireIn = Carbon::now ()->diff ($ date );
244280
245281 return new static ;
246282 }
@@ -254,12 +290,11 @@ public static function tokensExpireIn(DateTimeInterface $date = null)
254290 public static function refreshTokensExpireIn (DateTimeInterface $ date = null )
255291 {
256292 if (is_null ($ date )) {
257- return static ::$ refreshTokensExpireAt
258- ? Carbon::now ()->diff (static ::$ refreshTokensExpireAt )
259- : new DateInterval ('P1Y ' );
293+ return static ::$ refreshTokensExpireIn ?? new DateInterval ('P1Y ' );
260294 }
261295
262296 static ::$ refreshTokensExpireAt = $ date ;
297+ static ::$ refreshTokensExpireIn = Carbon::now ()->diff ($ date );
263298
264299 return new static ;
265300 }
@@ -273,12 +308,11 @@ public static function refreshTokensExpireIn(DateTimeInterface $date = null)
273308 public static function personalAccessTokensExpireIn (DateTimeInterface $ date = null )
274309 {
275310 if (is_null ($ date )) {
276- return static ::$ personalAccessTokensExpireAt
277- ? Carbon::now ()->diff (static ::$ personalAccessTokensExpireAt )
278- : new DateInterval ('P1Y ' );
311+ return static ::$ personalAccessTokensExpireIn ?? new DateInterval ('P1Y ' );
279312 }
280313
281314 static ::$ personalAccessTokensExpireAt = $ date ;
315+ static ::$ personalAccessTokensExpireIn = Carbon::now ()->diff ($ date );
282316
283317 return new static ;
284318 }
@@ -590,6 +624,32 @@ public static function hashClientSecrets()
590624 return new static ;
591625 }
592626
627+ /**
628+ * Specify the callback that should be invoked to generate encryption keys for encrypting JWT tokens.
629+ *
630+ * @param callable $callback
631+ * @return static
632+ */
633+ public static function encryptTokensUsing ($ callback )
634+ {
635+ static ::$ tokenEncryptionKeyCallback = $ callback ;
636+
637+ return new static ;
638+ }
639+
640+ /**
641+ * Generate an encryption key for encrypting JWT tokens.
642+ *
643+ * @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
644+ * @return string
645+ */
646+ public static function tokenEncryptionKey (Encrypter $ encrypter )
647+ {
648+ return is_callable (static ::$ tokenEncryptionKeyCallback ) ?
649+ (static ::$ tokenEncryptionKeyCallback )($ encrypter ) :
650+ $ encrypter ->getKey ();
651+ }
652+
593653 /**
594654 * Configure Passport to not register its migrations.
595655 *
0 commit comments