# Auth: OTP, MFA, Organisationen und SSO

> Infaris Auth meldet die Nutzer deiner App an. Beginne mit einem E-Mail-Code. Ergänze Passkeys, SMS, TOTP-MFA, Google, Microsoft oder Apple. Organisationen haben Mitglieder, Rollen, Einladungen und einen eigenen OIDC- oder SAML-Anbieter.

Source: https://docs.infaris.com/de/pulseguard/hosting-auth

## Was es ist

Infaris Auth meldet die Nutzer deiner App an. Beginne mit einem E-Mail-Code. Ergänze Passkeys, SMS, TOTP-MFA, Google, Microsoft oder Apple. Organisationen haben Mitglieder, Rollen, Einladungen und einen eigenen OIDC- oder SAML-Anbieter.

## Schnellstart und CLI

```bash
infaris-guard hosting auth projects create --name mijn-app
infaris-guard hosting auth projects show <projectId>
infaris-guard hosting auth users invite <projectId> --email sanne@example.nl
infaris-guard hosting auth attach <projectId> --site <siteId>
infaris-guard hosting auth mfa policy <projectId> required
infaris-guard hosting auth providers <projectId>
infaris-guard hosting auth orgs <projectId>
infaris-guard hosting auth hooks list <projectId>
bun add @infaris/auth-js
```

## SDK und Code

```ts
import { createClient } from '@infaris/auth-js';
const auth = createClient(
  process.env.NEXT_PUBLIC_INFARIS_AUTH_URL!,
  process.env.NEXT_PUBLIC_INFARIS_AUTH_KEY!,
);
await auth.signInWithOtp({ email: 'sanne@example.nl' });
// code: the value entered by the user in the same browser.
const { data, error } = await auth.verifyOtp({ email: 'sanne@example.nl', token: code });
if (error) throw error;
if (data?.mfa) {
  // Enrol TOTP first when enrollRequired is true.
  console.log(data.mfa);
}
// After enabling a provider and allowing this exact redirect URL:
await auth.signInWithOAuth({ provider: 'google', redirectTo: 'https://app.example.nl/auth/callback' });
```

## Sichere Standards

Die Registrierung beginnt nur auf Einladung. Redirects und Origins stehen in expliziten Listen. PKCE bindet den Anmeldeversuch an den Browser. Der öffentliche Schlüssel ist für den Browser; `INFARIS_AUTH_SECRET_KEY` nur für den Server. Prüfe Organisation und Rolle in deiner Autorisierung. Hooks sind signiert: siehe [Auth-Hooks](hosting-auth-hooks).

## Grenzen

Ein Access Token gilt 15 Minuten. Maximal 20 Projekte pro Organisation, 100.000 Nutzer und 20 aktive Schlüssel pro Projekt. Maximal 20 Origins und 20 Redirects; 1.000 OTP-Mails pro Stunde und Projekt. Codes haben 6 bis 8 Ziffern und maximal 5 Versuche. MFA kann eine Challenge statt einer Sitzung zurückgeben. OAuth und SSO benötigen eine Anbieterkonfiguration; der SDK-Aufruf aktiviert keinen Anbieter.

## FAQ

**Werden Supabase-Passwörter importiert?** Nein, Nutzer fordern einen neuen Code an. **Keine Sitzung?** Schließe zuerst `data.mfa` ab. **SSO?** Organisation einrichten, Domain bestätigen und IdP konfigurieren; danach `auth.signInWithSso({ domain, redirectTo })` aufrufen. **Hooks?** Hooks prüfen den Login, Events dienen der späteren Verarbeitung; Fehler und erneute Zustellung berücksichtigen.

## MFA, Organisationen und Anbieter einrichten

Den Callback aus `providers` in der Anbieterkonsole eintragen. App-Redirect in den Projekteinstellungen erlauben. Das Client Secret unten kommt aus deiner eigenen geheimen Datei. Für SSO eine Organisationsdomain hinzufügen, verifizieren und den IdP einrichten. Dies ist App-Authentifizierung, nicht der Infaris-Verwaltungslogin.

```bash
infaris-guard hosting auth providers set <projectId> google --client-id <clientId> --enabled --client-secret-stdin < google-secret.txt
infaris-guard hosting auth orgs enable <projectId>
infaris-guard hosting auth orgs create <projectId> --name Acme --slug acme --owner <userId>
infaris-guard hosting auth orgs domains add <projectId> <orgId> --domain acme.example
infaris-guard hosting auth orgs domains verify <projectId> <orgId> <domainId>
infaris-guard hosting auth orgs idp <projectId> <orgId>
```

```ts
// auth: the client created above; appCode: the current authenticator code.
const { data: totp, error: enrollError } = await auth.mfa.enrollTotp({ name: 'Phone' });
if (enrollError) throw enrollError;
// Display totp.uri securely as a QR code, then ask the user for appCode.
if (totp) await auth.mfa.verify({ factorId: totp.factor.id, code: appCode });
const { data: organisations } = await auth.orgs.list();
await auth.orgs.activate('acme');
await auth.orgs.invite('acme', { email: 'colleague@acme.example', role: 'member' });
// Only after configuring and verifying the organisation's identity provider:
await auth.signInWithSso({ domain: 'acme.example', redirectTo: 'https://app.example.nl/auth/callback' });
```

## Verwaltete Microsoft- und Google-Anmeldung

In einem Hosting-Auth-Projekt können Sie Microsoft mit Ihrem Entra-Mandanten oder Google mit Ihrer Workspace-Domain verbinden. Wählen Sie den verwalteten Anbieter, um den Infaris-Client zu nutzen. Begrenzen Sie den Zugriff auf den vorgesehenen Mandanten oder die Domain und ergänzen Sie die Weiterleitungsadresse Ihrer App. Bei Microsoft öffnet ein Entra-Administrator einmalig den Zustimmungslink.
