Beliebige Entra-Attribute ins Profil übernehmen; eigene Profilfelder
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m43s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m52s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m49s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m49s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m12s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 1m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 1m59s
CI / Build-Artefakte aktuell (pull_request) Successful in 57s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m43s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m52s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m49s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m49s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m12s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 1m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 1m59s
CI / Build-Artefakte aktuell (pull_request) Successful in 57s
- Profilfelder frei definierbar (Typ, Sichtbarkeit, selbst pflegbar), Werte als JSON am Benutzer - Attribut-Zuordnung je Anbieter statt fester Feldliste: jedes Graph-Attribut inkl. verschachtelter Pfade, onPremisesExtensionAttributes und Verzeichniserweiterungen - Erweiterungsattribute per Knopf aus Entra laden - $select dynamisch aus der Zuordnung; Delta-Abgleich startet bei geänderter Zuordnung neu - Rückfall auf Grundattribute, wenn einzelne Attribute nicht lesbar sind - Ältere Konfiguration (synced_fields) wird weiter gelesen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
51c94cd0cf
commit
6269d3302c
79 changed files with 1442 additions and 273 deletions
|
|
@ -2,31 +2,57 @@
|
|||
|
||||
namespace App\Identity\Entra;
|
||||
|
||||
use App\Models\IdentityProvider;
|
||||
|
||||
/**
|
||||
* Normalisiert Entra-/Graph-Benutzerdaten auf die Profilfelder des Portals.
|
||||
* Normalisiert Entra-/Graph-Benutzerdaten auf die Profilfelder des Portals –
|
||||
* gemäß der Attribut-Zuordnung des Anbieters.
|
||||
*
|
||||
* Ergebnis: display_name, Kernfelder (first_name, email, …), freie Felder unter
|
||||
* „custom“ und – falls abgefragt – manager_subject.
|
||||
*/
|
||||
final class EntraProfile
|
||||
{
|
||||
/** Felder, die bei Graph abgefragt werden. */
|
||||
public const SELECT = 'id,displayName,givenName,surname,mail,userPrincipalName,jobTitle,department,officeLocation,businessPhones,mobilePhone,accountEnabled,userType';
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $graphUser Antwort von /me bzw. /users/{id}
|
||||
* @param array<string, mixed> $graphUser Antwort von /me, /users/{id} oder /users/delta
|
||||
* @param bool $partial Delta-Antwort: nur Felder liefern, deren Attribut enthalten ist
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function fromGraph(array $graphUser, ?string $managerSubject = null, bool $withManager = false): array
|
||||
public static function fromGraph(IdentityProvider $provider, array $graphUser, ?string $managerSubject = null, bool $withManager = false, bool $partial = false): array
|
||||
{
|
||||
$profile = [
|
||||
'display_name' => $graphUser['displayName'] ?? null,
|
||||
'first_name' => $graphUser['givenName'] ?? null,
|
||||
'last_name' => $graphUser['surname'] ?? null,
|
||||
'email' => $graphUser['mail'] ?? (str_contains((string) ($graphUser['userPrincipalName'] ?? ''), '#EXT#') ? null : ($graphUser['userPrincipalName'] ?? null)),
|
||||
'job_title' => $graphUser['jobTitle'] ?? null,
|
||||
'department' => $graphUser['department'] ?? null,
|
||||
'location' => $graphUser['officeLocation'] ?? null,
|
||||
'phone' => $graphUser['businessPhones'][0] ?? null,
|
||||
'mobile' => $graphUser['mobilePhone'] ?? null,
|
||||
];
|
||||
$present = fn (string $path) => ! $partial || array_key_exists(EntraAttributes::topLevel($path), $graphUser);
|
||||
$profile = [];
|
||||
|
||||
if ($present('displayName')) {
|
||||
$profile['display_name'] = EntraAttributes::value($graphUser, 'displayName');
|
||||
}
|
||||
|
||||
// Grundwerte für Kontoanlage und Verknüpfung; die Zuordnung überschreibt sie.
|
||||
foreach (['first_name' => 'givenName', 'last_name' => 'surname', 'email' => 'mail'] as $field => $path) {
|
||||
if ($present($path)) {
|
||||
$profile[$field] = EntraAttributes::value($graphUser, $path);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($provider->attributeMap() as $target => $path) {
|
||||
if (! $present($path)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = EntraAttributes::value($graphUser, $path);
|
||||
|
||||
if (str_starts_with($target, 'custom.')) {
|
||||
$profile['custom'][substr($target, 7)] = $value;
|
||||
} else {
|
||||
$profile[$target] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// Gastkonten haben oft keine „mail“; der UPN ist dann eine #EXT#-Adresse.
|
||||
if (array_key_exists('email', $profile) && $profile['email'] === null && ! $partial) {
|
||||
$upn = (string) ($graphUser['userPrincipalName'] ?? '');
|
||||
$profile['email'] = $upn !== '' && ! str_contains($upn, '#EXT#') ? $upn : null;
|
||||
}
|
||||
|
||||
if ($withManager) {
|
||||
$profile['manager_subject'] = $managerSubject;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue