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
- 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>
114 lines
3.2 KiB
PHP
114 lines
3.2 KiB
PHP
<?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);
|
||
}
|
||
}
|