feat: set preferred role on login via get parameter

This commit is contained in:
Björn Fromme
2024-02-14 15:56:38 +01:00
parent 2cb4fa1933
commit f32cfcd9f2
5 changed files with 27 additions and 15 deletions
+10 -5
View File
@@ -63,8 +63,9 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
return null;
}
// Finale checks and local user loading/creation
$user = $this->getOrCreateLocalUser($response, $email, $password);
// Final checks and local user loading/creation
$preferredRole = $request->request->get('_role');
$user = $this->getOrCreateLocalUser($response, $email, $password, $preferredRole);
if (null === $user) {
return null;
@@ -98,8 +99,12 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
return new RedirectResponse($url);
}
private function getOrCreateLocalUser(ProfileResponse $profileResponse, string $email, string $password): ?User
{
private function getOrCreateLocalUser(
ProfileResponse $profileResponse,
string $email,
string $password,
?string $preferredRole
): ?User {
// Fetch CRM attributes, early return in case of an API error
try {
/** @var CrmAttributesResponse $crmAttributes */
@@ -111,7 +116,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
// Collect user's roles from CRM attributes
$roles = $this
->userDataHandler
->collectRoles($crmAttributes)
->collectRoles($crmAttributes, $preferredRole)
;
// User is expected to have at least one role