Skip to content

Commit 9a3b47b

Browse files
[13.x] Fix Exception Caused by Missing AccessToken Attributes (#1829)
* check access token attrs * check access token attrs
1 parent 524a4ff commit 9a3b47b

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/AccessToken.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ public static function fromPsrRequest(ServerRequestInterface $request): static
6060
*/
6161
public function can(string $scope): bool
6262
{
63-
return in_array('*', $this->oauth_scopes) || $this->scopeExistsIn($scope, $this->oauth_scopes);
63+
if (empty($this->attributes['oauth_scopes'])) {
64+
return false;
65+
}
66+
67+
return in_array('*', $this->attributes['oauth_scopes'])
68+
|| $this->scopeExistsIn($scope, $this->attributes['oauth_scopes']);
6469
}
6570

6671
/**
@@ -84,15 +89,31 @@ public function transient(): bool
8489
*/
8590
public function revoke(): bool
8691
{
87-
return (bool) Passport::token()->newQuery()->whereKey($this->oauth_access_token_id)->update(['revoked' => true]);
92+
if ($this->token) {
93+
return $this->token->revoke();
94+
}
95+
96+
if (isset($this->attributes['oauth_access_token_id'])) {
97+
return (bool) Passport::token()->newQuery()->whereKey($this->attributes['oauth_access_token_id'])->update(['revoked' => true]);
98+
}
99+
100+
return false;
88101
}
89102

90103
/**
91104
* Get the token instance.
92105
*/
93106
protected function getToken(): ?Token
94107
{
95-
return $this->token ??= Passport::token()->newQuery()->find($this->oauth_access_token_id);
108+
if ($this->token) {
109+
return $this->token;
110+
}
111+
112+
if (isset($this->attributes['oauth_access_token_id'])) {
113+
return $this->token = Passport::token()->newQuery()->find($this->attributes['oauth_access_token_id']);
114+
}
115+
116+
return null;
96117
}
97118

98119
/**

0 commit comments

Comments
 (0)