Authentification utilisateurs finaux

Inscription, connexion, JWT, OAuth, MFA TOTP/SMS, RLS PostgreSQL via auth.uid(). Isolation totale par projet via jwt_secret unique.

Authentification utilisateurs finaux

Chaque backend Pool C intègre un service d'authentification open source dédié : inscription, connexion, sessions, tokens JWT, providers OAuth, MFA. Isolation totale entre projets — un token émis par wzfbhd est rejeté par tout autre projet, garanti par un jwt_secret unique par projet.

Quand l'utiliser — quand non

Idéal pour

  • Apps mobile et web avec utilisateurs finaux
  • Onboarding email + mot de passe ou magic link
  • Connexion via providers OAuth (GitHub, Google, Apple, etc.)
  • MFA TOTP ou SMS
  • RLS PostgreSQL — auth.uid() dans les policies

Pas adapté

  • SSO d'entreprise multi-app (préférer un IdP dédié)
  • Auth par certificats X.509 client
  • Annuaire LDAP/Active Directory (préférer un IdP dédié)

Endpoints d'authentification

POST  /auth/v1/signup                          Inscription email/mdp
POST  /auth/v1/token?grant_type=password       Connexion email/mdp
POST  /auth/v1/token?grant_type=refresh_token  Refresh token
POST  /auth/v1/logout                          Déconnexion
GET   /auth/v1/user                            Profil connecté
PUT   /auth/v1/user                            Mise à jour profil
POST  /auth/v1/recover                         Reset mot de passe
POST  /auth/v1/magiclink                       Magic link email
POST  /auth/v1/otp                             OTP email ou SMS
GET   /auth/v1/verify                          Vérification email/OTP
GET   /auth/v1/authorize?provider=github       OAuth redirect
GET   /auth/v1/callback                        OAuth callback
GET   /auth/v1/admin/users                     Admin (service_role)

Tous accessibles sous https://wzfbhd.runtime.di2amp.com.

Structure du JWT

{
  "iss": "https://wzfbhd.runtime.di2amp.com/auth/v1",
  "sub": "550e8400-e29b-41d4-a716-446655440000",
  "aud": "authenticated",
  "role": "authenticated",
  "email": "user@example.com",
  "exp": 1717600000,
  "iat": 1717596400
}

Signature HS256 avec le jwt_secret unique du projet. Un token valide pour wzfbhd est rejeté par tout autre projet.

Inscription et connexion

# Inscription email + mot de passe
curl -L -X POST "https://wzfbhd.runtime.di2amp.com/auth/v1/signup" \
  -H "apikey: $ANON_KEY" -H "Content-Type: application/json" \
  -d '{"email":"alice@example.com","password":"MotDePasseSecure123!"}'

# Connexion
curl -L -X POST "https://wzfbhd.runtime.di2amp.com/auth/v1/token?grant_type=password" \
  -H "apikey: $ANON_KEY" -H "Content-Type: application/json" \
  -d '{"email":"alice@example.com","password":"MotDePasseSecure123!"}'
# Réponse contient access_token (JWT) + refresh_token

# Magic link
curl -L -X POST "https://wzfbhd.runtime.di2amp.com/auth/v1/magiclink" \
  -H "apikey: $ANON_KEY" -H "Content-Type: application/json" \
  -d '{"email":"alice@example.com","redirect_to":"https://monapp.com/dashboard"}'

Providers OAuth

ProviderConfiguration requise
GitHubClient ID + Secret OAuth App
GoogleClient ID + Secret OAuth2
AppleService ID + Team ID + Key ID + Private Key
DiscordClient ID + Secret
Twitter / XAPI Key + Secret v2
FacebookApp ID + Secret
MicrosoftClient ID + Secret (Azure AD)
GitLabClient ID + Secret (GitLab.com ou self-hosted)

Configuration par projet depuis le Studio BaaS. Redirect URI à enregistrer côté provider : https://wzfbhd.runtime.di2amp.com/auth/v1/callback.

MFA — TOTP et SMS

Authentification multifacteur supportée nativement :

  • TOTP (Google Authenticator, Authy, 1Password, etc.) — enrôlement avec QR code, vérification à 6 chiffres
  • OTP SMS via Twilio (provider configurable par projet)

RLS PostgreSQL — auth.uid()

La fonction auth.uid() retourne le sub du JWT de la requête courante, utilisable dans les policies RLS pour filtrer automatiquement les données par utilisateur :

-- Un user ne peut lire que ses propres todos
CREATE POLICY "users_select_own_todos" ON public.todos
  FOR SELECT USING (auth.uid() = user_id);

-- Un user ne peut écrire que dans ses propres données
CREATE POLICY "users_insert_own" ON public.todos
  FOR INSERT WITH CHECK (auth.uid() = user_id);

Sécurité et isolation

jwt_secret unique par projet. Tables auth (auth.users, auth.identities, auth.sessions, auth.audit_log_entries) dans le schéma auth du PostgreSQL projet — pas de base partagée entre tenants.

Pour aller plus loin

Tarification associée

Authentification incluse dans tous les plans. Aucun coût par utilisateur final actif. Voir tarifs.