Skip to content

Commit

Permalink
Validate driver is session only and set default guard
Browse files Browse the repository at this point in the history
  • Loading branch information
roDRYgo0 committed Jan 21, 2021
1 parent f902d9f commit 0eecf01
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/Guard.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,28 @@ public function __construct(AuthFactory $auth, $expiration = null, $provider = n
*/
public function __invoke(Request $request)
{
$guards = array_keys(config('auth.guards'));

if (empty($guards)) {
$guards = [null];
}

foreach ($guards as $guard) {
if ($user = $this->auth->guard($guard)->user()) {
if ($default_guard = config('sanctum.guard')) {
if ($user = $this->auth->guard($default_guard)->user()) {
return $this->supportsTokens($user)
? $user->withAccessToken(new TransientToken)
: $user;
}
} else {
$guards = collect(config('auth.guards'))->filter(function ($guard) {
return $guard['driver'] === 'session';
})->keys();

if (empty($guards)) {
$guards = [null];
}

foreach ($guards as $guard) {
if ($user = $this->auth->guard($guard)->user()) {
return $this->supportsTokens($user)
? $user->withAccessToken(new TransientToken)
: $user;
}
}
}

if ($token = $request->bearerToken()) {
Expand Down

0 comments on commit 0eecf01

Please sign in to comment.