Docs
Quickstart
Step 1: Create a workspace
Sign up and pick your workspace's address, like
acme.authxi.com. That address is the issuer your apps use. Set who can sign in under the workspace's access rules.Step 2: Create an app
In the workspace, add an application and pick its type:
- Web app for server-rendered apps (Node, Laravel). It gets a client secret.
- Single-page app for code that runs in the browser (React, plain JavaScript). It uses PKCE, with no secret.
- Native for mobile and desktop apps.
Add your callback URL, for example
https://app.acme.com/auth/callback. authxi only returns to registered URLs, matched exactly. For local work, create a separate app marked as development: it also acceptshttp://localhoston any port.Copy the client id, and the client secret for a web app. The secret is shown once.
Step 3: Add the code
Pick your stack. Each SDK handles PKCE, state, nonce and ID token checks, and returns the page the user started on as
returnTo.Terminal npm install @authxi/jsauth.ts import { createAuthxi } from '@authxi/js'; export const authxi = createAuthxi({ issuer: 'https://acme.authxi.com', clientId: 'app_...', redirectUri: `${location.origin}/auth/callback`, }); // Sends the user to sign in. returnTo defaults to the current page. await authxi.login();On /auth/callback const { user, returnTo } = await authxi.handleRedirect(); location.replace(returnTo); // the page they started onNo bundler: load authxi.js from the CDN.
Every page <script src="https://cdn.authxi.com/authxi.js"></script> <script> const authxi = Authxi.createAuthxi({ issuer: 'https://acme.authxi.com', clientId: 'app_...', redirectUri: 'https://app.acme.com/auth/callback', }); document.querySelector('#sign-in').onclick = () => authxi.login({ returnTo: location.pathname + location.search }); </script>Callback page (/auth/callback) <script type="module"> const { user, returnTo } = await authxi.handleRedirect(); location.replace(returnTo); // back to the page they started on </script>Terminal npm install @authxi/reactmain.tsx import { AuthxiProvider } from '@authxi/react'; <AuthxiProvider issuer="https://acme.authxi.com" clientId="app_..." redirectUri={`${location.origin}/auth/callback`} onRedirect={(returnTo) => router.navigate(returnTo, { replace: true })} > <App /> </AuthxiProvider>billing.tsx import { RequireAuth, useAuth } from '@authxi/react'; function Billing() { const { user, logout } = useAuth(); return <p>Signed in as {user?.email} <button onClick={() => logout()}>Sign out</button></p>; } // Signs in first if needed, then comes back to this exact page. <RequireAuth> <Billing /> </RequireAuth>Node 18 or later. Without Express, use createLoginRedirect() and handleCallback() directly.
Terminal npm install @authxi/nodeserver.ts import express from 'express'; import { createAuthxiServer, expressAuthxi } from '@authxi/node'; const authxi = createAuthxiServer({ issuer: 'https://acme.authxi.com', clientId: process.env.AUTHXI_CLIENT_ID, clientSecret: process.env.AUTHXI_CLIENT_SECRET, redirectUri: 'https://app.acme.com/auth/callback', cookieSecret: process.env.AUTHXI_COOKIE_SECRET, // at least 32 characters }); const app = express(); // Serves GET /login?returnTo=..., GET /auth/callback and GET /logout app.use( expressAuthxi(authxi, { onSignIn(req, res, { user, returnTo }) { req.session.user = { id: user.id, email: user.email }; res.redirect(returnTo); }, onSignOut: (req) => req.session.destroy(), }), );A Laravel Socialite driver. redirect()->intended() sends the user back to the page they started on.
Terminal composer require authxi/laravel.env AUTHXI_CLIENT_ID=app_... AUTHXI_CLIENT_SECRET=axs_... # from the app's Credentials tabconfig/services.php 'authxi' => [ 'issuer' => 'https://acme.authxi.com', 'client_id' => env('AUTHXI_CLIENT_ID'), 'client_secret' => env('AUTHXI_CLIENT_SECRET'), 'redirect' => '/auth/callback', ],routes/web.php use App\Models\User; use Illuminate\Support\Facades\Auth; use Laravel\Socialite\Facades\Socialite; Route::get('/login', fn () => Socialite::driver('authxi')->redirect()); Route::get('/auth/callback', function () { $u = Socialite::driver('authxi')->user(); // ID token already verified Auth::login(User::updateOrCreate(['authxi_id' => $u->getId()], [ 'email' => $u->getEmail(), 'name' => $u->getName(), ])); return redirect()->intended('/dashboard'); // back to the page they started on });Settings for any OpenID Connect library issuer https://acme.authxi.com discovery https://acme.authxi.com/.well-known/openid-configuration client id app_... client secret axs_... # server apps only scopes openid email profile flow authorization code with PKCE (S256)Step 4: Try it
Sign out, then open a page deep in your app, like
/billing/invoices?tab=due. You go through Google, then land back on that page, signed in. The sign-in shows up in the dashboard's sign-in log.If your browser app calls your own API, send the ID token along and check it there. Server apps already have the verified user from the callback.
api.ts import { verifyIdToken } from '@authxi/js'; // On your API, for ID tokens your browser app sends const claims = await verifyIdToken(token, { issuer: 'https://acme.authxi.com', audience: 'app_...', // your client id });Step 5: Next
- Ask for two-step verification before sensitive actions with step-up checks.
- Handle
access_deniedand other errors on your callback page. - Read the SDK reference for sign-out, silent sign-in and Express middleware.