Give trusted apps the user's role

Anikeen ID now sends trusted apps the user's role (admin or user) in
GET v1/user, a user read by ID and user.updated, so an app like the
Console can take its admins from Anikeen ID. Enums\Role, the Socialite
user's role and Resources\User::role()/isAdmin() expose it.
This commit is contained in:
envoyr committed 2026-11-07 15:24:48 +00:00
1 parent 31de31aa47
commit 642e518259
8 files changed
+154 -1

No files matched your search

+18
View File
@@ -2,6 +2,7 @@
namespace Anikeen\Id\Resources;
use Anikeen\Id\Enums\Role;
use DateTimeImmutable;
use JsonSerializable;
@@ -27,6 +28,7 @@ use JsonSerializable;
* @property ?string $created_at REST shapes
* @property ?string $pending_email profile updates only: a new address waiting for confirmation
* @property ?string $pending_email_expires_at profile updates only
* @property ?string $role trusted apps only: Role::ADMIN or Role::USER
*/
class User implements JsonSerializable
{
@@ -97,6 +99,22 @@ class User implements JsonSerializable
return (int) ($this->data->profile_version ?? $this->data->version ?? 0);
}
/**
* Role::ADMIN or Role::USER; null for apps that aren't trusted (they never see it).
*/
public function role(): ?string
{
return $this->data->role ?? null;
}
/**
* An Anikeen ID admin (trusted apps only; false when the role isn't known).
*/
public function isAdmin(): bool
{
return $this->role() === Role::ADMIN;
}
/**
* A new email address waiting for the user's confirmation (profile updates only); `email`
* stays the current address until then.