Guard

Auth: OTP, MFA, organisations and SSO

Infaris Auth signs in the users of your app. Start with an email code. Add passkeys, SMS, TOTP MFA, Google, Microsoft or Apple. Organisations have members, roles, invitations and their own OIDC or SAML provider.

What it is

Infaris Auth signs in the users of your app. Start with an email code. Add passkeys, SMS, TOTP MFA, Google, Microsoft or Apple. Organisations have members, roles, invitations and their own OIDC or SAML provider.

Quick start and CLI

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 and code

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' });

Secure defaults

Signup starts as invite only. Redirects and origins use explicit lists. PKCE binds the sign-in attempt to the browser. The publishable key is for the browser; INFARIS_AUTH_SECRET_KEY is server only. Check organisation and role in your own authorisation. Hooks are signed: see Auth hooks.

Limits

An access token lasts 15 minutes. At most 20 projects per organisation, 100,000 users and 20 active keys per project. At most 20 origins and 20 redirects; 1,000 OTP emails per hour per project. Codes have 6 to 8 digits and at most 5 attempts. MFA can return a challenge instead of a session. OAuth and SSO need provider configuration; naming a provider in the SDK does not enable it.

FAQ

Are Supabase passwords imported? No, users request a new code. No session? Complete data.mfa first. SSO? Configure an organisation, verify its domain and configure its IdP, then call auth.signInWithSso({ domain, redirectTo }). Hooks? Use hooks for sign-in checks and events for later processing; handle failures and redelivery.

Configure MFA, organisations and providers

Use the callback from providers in the provider console. Allow the app redirect in project settings. The client secret below comes from your own secret file. For SSO add an organisation domain, verify it and configure its IdP. This is application authentication, not the Infaris management login.

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>
// 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' });

Managed Microsoft and Google sign-in

In a Hosting Auth project, you can connect Microsoft to your Entra tenant or Google to your Workspace domain. Choose the managed provider to use the Infaris client. Restrict access to the intended tenant or domain and add your application redirect to the project. For Microsoft, an Entra administrator opens the admin consent link once.