mirror of
https://github.com/anikeen-com/id.git
synced 2026-11-08 00:28:32 +00:00
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:
8 files changed
+154
-1
No files matched your search
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user