Skip to content

Commit 4783558

Browse files
committed
fix: don't throw an authentication exception when user isn't logged in, just return null for user
1 parent f20dbac commit 4783558

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/Guard/IntrospectGuard.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
namespace DesignMyNight\Laravel\OAuth2\Guard;
44

55
use DesignMyNight\Laravel\OAuth2\Introspect;
6+
use Illuminate\Auth\AuthenticationException;
67
use Illuminate\Contracts\Auth\Authenticatable;
78
use Illuminate\Contracts\Auth\Guard;
89

910
class IntrospectGuard implements Guard
1011
{
11-
protected $user;
12+
protected $user = false;
1213

1314
public function __construct(Introspect $introspect)
1415
{
@@ -22,7 +23,7 @@ public function authenticate()
2223

2324
public function check()
2425
{
25-
return ! is_null($this->user());
26+
return !is_null($this->user());
2627
}
2728

2829
public function guest()
@@ -37,10 +38,14 @@ public function id()
3738

3839
public function user()
3940
{
40-
if ($this->user === null) {
41-
$this->user = $this->introspect
42-
->verifyToken()
43-
->getUser();
41+
if ($this->user === false) {
42+
try {
43+
$this->user = $this->introspect
44+
->verifyToken()
45+
->getUser();
46+
} catch (AuthenticationException $e) {
47+
$this->user = null;
48+
}
4449
}
4550

4651
return $this->user;

0 commit comments

Comments
 (0)