fix(ms365): HTTPS-Protokoll für Integration-Redirect-URI erzwingen

Traefik leitet x-forwarded-proto nicht korrekt weiter, sodass der
Controller http:// statt https:// generierte — Azure lehnt nicht-HTTPS
Redirect-URIs für nicht-localhost ab (AADSTS50011).

Protokoll wird jetzt aus der konfigurierten SSO-Redirect-URI abgeleitet
(immer HTTPS), der Host bleibt dynamisch (IP oder DNS).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Thomas Reitz 2026-03-12 23:26:10 +01:00
parent 1f6e59d362
commit 82e6a03bb9

View file

@ -65,9 +65,16 @@ export class IntegrationsController {
@Req() req: Request, @Req() req: Request,
): Promise<{ success: boolean; data: { url: string } }> { ): Promise<{ success: boolean; data: { url: string } }> {
// Redirect-URI dynamisch aus dem Anfrage-Host ableiten // Redirect-URI dynamisch aus dem Anfrage-Host ableiten
// Unterstuetzt sowohl IP als auch DNS-Name (z.B. insight.xinion.lan) // Protokoll: aus der konfigurierten SSO-URI (HTTPS) — Azure akzeptiert nur HTTPS
// fuer nicht-localhost URIs. x-forwarded-proto koennte http sein (Traefik-intern).
const host = (req.get('x-forwarded-host') || req.get('host') || '').split(',')[0].trim(); const host = (req.get('x-forwarded-host') || req.get('host') || '').split(',')[0].trim();
const proto = req.get('x-forwarded-proto') || req.protocol || 'http'; const configuredUri = this.entraIdService.getIntegrationRedirectUri();
let proto = 'https';
try {
proto = new URL(configuredUri).protocol.replace(':', '');
} catch {
proto = req.get('x-forwarded-proto') || 'https';
}
const redirectUri = host const redirectUri = host
? `${proto}://${host}/api/v1/auth/integrations/microsoft-365/callback` ? `${proto}://${host}/api/v1/auth/integrations/microsoft-365/callback`
: undefined; : undefined;