mirror of
https://github.com/anikeen-com/id.git
synced 2026-11-07 16:18:33 +00:00
Read a connected user's profile by ID for trusted apps
This commit is contained in:
3 files changed
+249
No files matched your search
@@ -6,6 +6,7 @@ namespace Anikeen\Id\Concerns;
|
||||
use Anikeen\Id\ApiOperations\Get;
|
||||
use Anikeen\Id\ApiOperations\Post;
|
||||
use Anikeen\Id\Exceptions\ApiException;
|
||||
use Anikeen\Id\Resources\User;
|
||||
use Anikeen\Id\Result;
|
||||
use Anikeen\Id\Support\AppRequest;
|
||||
use Throwable;
|
||||
@@ -95,6 +96,30 @@ trait ManagesUsers
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The profile of a user connected to your app, by their Anikeen ID (trusted apps, app token),
|
||||
* e.g. to catch up on a missed user.updated webhook. The email address is returned even while
|
||||
* it isn't verified (emailVerified() is false then). No scope needed.
|
||||
*
|
||||
* @return User|null null when the user is unknown, deleted or not connected to your app
|
||||
* (404 "user_not_found"; the three look the same)
|
||||
* @throws ApiException 403 "client_not_allowed" (not a trusted app), 429 "too_many_requests",
|
||||
* or another failure
|
||||
*/
|
||||
public function findUserById(string $userId): ?User
|
||||
{
|
||||
try {
|
||||
return new User(AppRequest::send('GET', sprintf('v1/client/users/%s', rawurlencode($userId)))->data);
|
||||
} catch (ApiException $e) {
|
||||
// only Anikeen ID's own answer means "no such user", not e.g. an unknown route
|
||||
if ($e->isNotFound() && $e->error === 'user_not_found') {
|
||||
return null;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the user of a social login or create it (trusted apps, app token).
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user