feat: identify the authenticated account in the userinfo claims
This commit is contained in:
@@ -26,8 +26,9 @@ class UserinfoController extends AbstractController
|
||||
#[Route('/userinfo', name: 'api_userinfo', methods: ['GET'])]
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
// basic scopes applicable to all authenticated users
|
||||
$scopes = ['email'];
|
||||
// basic scopes applicable to all authenticated users. `sub` is not gated on a scope of its
|
||||
// own: it identifies the account every other claim describes, so it is always exported.
|
||||
$scopes = ['sub', 'email'];
|
||||
|
||||
// extend scopes depending on granted permissions
|
||||
if ($this->isGranted('ROLE_OAUTH2_ID')) {
|
||||
@@ -53,6 +54,13 @@ class UserinfoController extends AbstractController
|
||||
return new JsonResponse(['message' => $data->message, 'code' => $data->code], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
// Patch the identity of the account that authenticated. BusPro accepts any of the
|
||||
// addresses on a person's record as a login and answers all of them with the same
|
||||
// ids and the same first contact address, so only the local account tells the staff
|
||||
// account and the private one apart — and they hold different roles.
|
||||
$data->subject = (string) $user->getId();
|
||||
$data->loginEmail = $user->getEmail();
|
||||
|
||||
// Patch current user's roles. The implicit ROLE_USER says nothing about the
|
||||
// account — every authenticated user holds it — and is not exported.
|
||||
$data->roles = Role::effectiveOnly($user->getRoles());
|
||||
|
||||
Reference in New Issue
Block a user