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
94 lines
2.5 KiB
PHP
94 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Anikeen\Id\Auth;
|
|
|
|
use Anikeen\Id\AnikeenId;
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
use Illuminate\Contracts\Auth\UserProvider as Base;
|
|
|
|
class UserProvider implements Base
|
|
{
|
|
/**
|
|
* Create a new AnikeenId user provider.
|
|
*/
|
|
public function __construct(protected Base $provider, protected string $providerName, protected ?string $column = null)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* The column that holds a user's Anikeen ID: the provider's `column`, else
|
|
* `services.anikeen.user_id_column`, else AnikeenId::getUserIdField() (`anikeen_id`).
|
|
*/
|
|
public function column(): string
|
|
{
|
|
return $this->column ?: (config('services.anikeen.user_id_column') ?: AnikeenId::getUserIdField());
|
|
}
|
|
|
|
/**
|
|
* Find the user of an Anikeen ID (the `sub` of an access token).
|
|
*/
|
|
public function retrieveByAnikeenId(string $anikeenId): ?Authenticatable
|
|
{
|
|
if (method_exists($this->provider, 'retrieveByAnikeenId')) {
|
|
return $this->provider->retrieveByAnikeenId($anikeenId);
|
|
}
|
|
|
|
// eloquent / database providers: a plain where on the column
|
|
return $this->provider->retrieveByCredentials([$this->column() => $anikeenId]);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function retrieveById($identifier): ?Authenticatable
|
|
{
|
|
return $this->provider->retrieveById($identifier);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function retrieveByToken($identifier, $token): ?Authenticatable
|
|
{
|
|
return $this->provider->retrieveByToken($identifier, $token);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function updateRememberToken(Authenticatable $user, $token): void
|
|
{
|
|
$this->provider->updateRememberToken($user, $token);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function retrieveByCredentials(array $credentials): ?Authenticatable
|
|
{
|
|
return $this->provider->retrieveByCredentials($credentials);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function validateCredentials(Authenticatable $user, array $credentials): bool
|
|
{
|
|
return $this->provider->validateCredentials($user, $credentials);
|
|
}
|
|
|
|
/**
|
|
* Get the name of the user provider.
|
|
*/
|
|
public function getProviderName(): string
|
|
{
|
|
return $this->providerName;
|
|
}
|
|
|
|
public function rehashPasswordIfRequired(Authenticatable $user, #[\SensitiveParameter] array $credentials, bool $force = false)
|
|
{
|
|
$this->provider->rehashPasswordIfRequired($user, $credentials, $force);
|
|
}
|
|
}
|