OpenNIT

Quelltext des aktuellen Standes

Fassung 1.1.1

oauth.php

2 KB
<?php

declare(strict_types=1);

/**
 * OAuth2 / OpenID Connect Konfiguration
 *
 * Unterstützte Provider: Microsoft Entra ID (Azure AD), Keycloak
 * SICHERHEITSKRITISCH: Client Secrets niemals im Code speichern!
 */

return [
    'provider' => 'azure',

    // Microsoft Entra ID (Azure AD) Einstellungen
    'azure' => [
        'tenant_id' => $_ENV['AZURE_TENANT_ID'] ?? '',
        'client_id' => $_ENV['AZURE_CLIENT_ID'] ?? '',
        'client_secret' => $_ENV['AZURE_CLIENT_SECRET'] ?? '',
        'redirect_uri' => $_ENV['AZURE_REDIRECT_URI'] ?? '',

        // OAuth2 Endpunkte (automatisch aus Tenant-ID generiert)
        'url_authorize' => 'https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize',
        'url_access_token' => 'https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token',
        'url_resource_owner_details' => 'https://graph.microsoft.com/v1.0/me',

        // Scopes für OpenID Connect
        'scopes' => [
            'openid',
            'profile',
            'email',
            'offline_access', // Für Refresh Token
            'User.Read',
        ],

        // Token-Einstellungen
        'token' => [
            'access_token_lifetime' => 3600, // 1 Stunde
            'refresh_token_lifetime' => 86400, // 24 Stunden
        ],
    ],

    // Keycloak OIDC Einstellungen
    // Wird über Admin-Einstellungen befüllt (config/runtime.php überschreibt diese Defaults)
    'keycloak' => [
        'base_url'      => $_ENV['KEYCLOAK_BASE_URL']      ?? '',  // z.B. https://sso.example.com
        'realm'         => $_ENV['KEYCLOAK_REALM']         ?? '',
        'client_id'     => $_ENV['KEYCLOAK_CLIENT_ID']     ?? '',
        'client_secret' => $_ENV['KEYCLOAK_CLIENT_SECRET'] ?? '',
        'redirect_uri'  => $_ENV['KEYCLOAK_REDIRECT_URI']  ?? '',
        'scopes'        => ['openid', 'profile', 'email', 'offline_access'],
    ],

    // PKCE (Proof Key for Code Exchange) - zusätzliche Sicherheit
    'pkce' => [
        'enabled' => true,
        'method' => 'S256', // SHA-256
    ],

    // State-Parameter Einstellungen
    'state' => [
        'lifetime' => 600, // 10 Minuten
        'entropy' => 32, // Bytes Zufallsdaten
    ],

    // Nonce für ID Token Validierung
    'nonce' => [
        'lifetime' => 600,
        'entropy' => 32,
    ],
];