Skip to content

Commit

Permalink
TTL argument
Browse files Browse the repository at this point in the history
  • Loading branch information
stancl committed Jun 29, 2020
1 parent 405a137 commit b362c16
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Features/UserImpersonation.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ public function bootstrap(Tenancy $tenancy): void
* Impersonate a user and get an HTTP redirect response.
*
* @param string|ImpersonationToken $token
* @param int $ttl
* @return RedirectResponse
*/
public static function makeResponse($token): RedirectResponse
public static function makeResponse($token, int $ttl = null): RedirectResponse
{
$token = $token instanceof ImpersonationToken ? $token : ImpersonationToken::findOrFail($token);

if (((string) $token->tenant_id) !== ((string) tenant()->getTenantKey())) {
abort(403);
}

if ($token->created_at->diffInSeconds(Carbon::now()) > static::$ttl) {
$ttl = $ttl ?? static::$ttl;

if ($token->created_at->diffInSeconds(Carbon::now()) > $ttl) {
abort(403);
}

Expand Down

0 comments on commit b362c16

Please sign in to comment.