Loheide-eu-mitarbeiterplatt.../app/Identity/Entra/EntraDriver.php
Friederich Loheide 4fcc41ed30
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m41s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m48s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m15s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m17s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m48s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m41s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m26s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m59s
Phase 6 (Teil 2): OpenID Connect, LDAP/AD und SAML 2
- Gemeinsamer Treiber-Unterbau (App\Identity\IdentityDriver, IdentityDrivers,
  IdentityLogin, AttributeProfile); Entra ID nutzt ihn ebenfalls
- Plugins oidc, ldap und saml mit Profil- und Gruppen-Zuordnung
- Admin: Verfahren wählen, Formular je Verfahren, zuletzt empfangene Angaben
- onelogin/php-saml als neue Abhängigkeit

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 12:38:32 +00:00

114 lines
3.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Identity\Entra;
use App\Http\Controllers\Auth\IdentityLoginController;
use App\Identity\IdentityDriver;
use App\Identity\IdentityException;
use App\Models\IdentityProvider;
use App\Models\User;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Microsoft Entra ID – OpenID Connect plus Microsoft Graph (Profil, Gruppen, Foto,
* Hintergrund-Abgleich). Die Formularfelder stehen wegen ihres Umfangs direkt in
* der Admin-Ressource.
*/
class EntraDriver extends IdentityDriver
{
public function __construct(private readonly EntraLogin $login) {}
public function type(): string
{
return IdentityProvider::ENTRA;
}
public function label(): string
{
return 'Microsoft Entra ID';
}
public function description(): string
{
return 'Microsoft 365 / Azure AD mit Gruppen, App-Rollen, Profilfoto und Hintergrund-Abgleich.';
}
public function defaultButtonLabel(IdentityProvider $provider): string
{
return 'Mit Microsoft anmelden';
}
public function connectionSchema(): array
{
return [];
}
public function secretFields(): array
{
return ['client_secret'];
}
public function defaultAttributeMap(): array
{
return EntraAttributes::DEFAULT_MAP;
}
public function attributePattern(): string
{
return EntraAttributes::PATH_PATTERN;
}
public function attributeLabel(): string
{
return 'Graph-Attribut';
}
public function supportsManager(): bool
{
return true;
}
public function supportsPhoto(): bool
{
return true;
}
public function supportsAppRoles(): bool
{
return true;
}
public function groupValueLabel(): string
{
return 'Objekt-ID der Gruppe';
}
public function start(IdentityProvider $provider, Request $request): Response
{
$start = $this->login->start($provider, IdentityLoginController::callbackUrlFor($provider));
$request->session()->put('identity_login', $start['session']);
return redirect()->away($start['url']);
}
public function complete(IdentityProvider $provider, Request $request): User
{
$session = $request->session()->pull('identity_login');
if ($request->filled('error')) {
// z. B. Abbruch durch die Person oder fehlende Zustimmung in Entra
logger()->notice('Entra-Anmeldung abgebrochen: '.$request->string('error').' '.$request->string('error_description'));
throw new IdentityException($request->string('error')->toString() === 'access_denied'
? 'Die Anmeldung wurde abgebrochen.'
: 'Microsoft hat die Anmeldung abgelehnt. Bitte wenden Sie sich an die Administration.');
}
if (! is_array($session) || ! hash_equals($session['state'] ?? '', (string) $request->query('state')) || ($session['provider'] ?? null) !== (string) $provider->id) {
throw new IdentityException('Die Anmeldung ist abgelaufen. Bitte erneut versuchen.');
}
return $this->login->complete($provider, (string) $request->query('code'), IdentityLoginController::callbackUrlFor($provider), $session);
}
}