mirror of
https://github.com/anikeen-com/id.git
synced 2026-11-04 22:59:41 +00:00
- Register the guard driver and the anikeen user provider with static closures: Laravel binds extend() closures to the AuthManager, so $this->makeGuard() failed. - Look the token's sub up in the user's Anikeen ID column (anikeen_id by default; provider 'column', services.anikeen.user_id_column or useUserIdField()), not in the primary key; works with the anikeen, eloquent and database providers. - JwtParser: key from services.anikeen.public_key(_path) or the bundled key, read once per process; misconfiguration is an error, not a 401. Passport tokens have no client claim, so it is optional now. - Optional revocation check against Anikeen ID (verify_revocation), cached per token. - anikeenTokenCan() without a token, anikeenTokenCanAny(), scope middleware accept JSON responses. - Update the bundled staging public key to the current staging key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VbpgPaLqhBzo1AXHNs9Cx5
57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Anikeen\Id;
|
|
|
|
use stdClass;
|
|
|
|
trait HasAnikeenTokens
|
|
{
|
|
/**
|
|
* The current access token for the authentication user.
|
|
*/
|
|
protected ?stdClass $accessToken = null;
|
|
|
|
/**
|
|
* Get the current access token being used by the user.
|
|
*
|
|
* @return stdClass|null
|
|
*/
|
|
public function anikeenToken(): ?stdClass
|
|
{
|
|
return $this->accessToken;
|
|
}
|
|
|
|
/**
|
|
* Determine if the current API token has a given scope.
|
|
*/
|
|
public function anikeenTokenCan(string $scope): bool
|
|
{
|
|
$scopes = (array) ($this->accessToken->scopes ?? []);
|
|
|
|
return in_array('*', $scopes, true) || in_array($scope, $scopes, true);
|
|
}
|
|
|
|
/**
|
|
* Determine if the current API token has any of the given scopes.
|
|
*/
|
|
public function anikeenTokenCanAny(array $scopes): bool
|
|
{
|
|
foreach ($scopes as $scope) {
|
|
if ($this->anikeenTokenCan($scope)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Set the current access token for the user.
|
|
*/
|
|
public function withAnikeenAccessToken(stdClass $accessToken): self
|
|
{
|
|
$this->accessToken = $accessToken;
|
|
|
|
return $this;
|
|
}
|
|
} |