> ## Documentation Index
> Fetch the complete documentation index at: https://docs.didit.me/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication Quickstart: First Sign-In in 10 Minutes

> Turn on Didit Authentication in a sandbox application, sign a person in with the hosted page and verify their access token on your server.

This quickstart gets Didit Authentication working end to end in about 10 minutes.
You register a callback in a sandbox application, turn on a sign-in method, sign a person in with the hosted sign-in page, verify their access token on your server, and see the sign-in in the console.

## Prerequisites

* A Didit account with a Sandbox application. Creating an account is free, and every Sandbox application has Authentication turned on.
* Node.js 20 or later, and a web app you can run on `http://localhost:3000`.

## Steps

**1. Open your sandbox application**

In the [Business Console](https://business.didit.me), use the application switcher to select your **Sandbox** application, then open **Authentication**.

A Sandbox application accepts `http://localhost` callbacks and Didit's test credentials for social sign-in, and it is never billed.
A Live application turns Authentication on from the **Products** page instead: see [prepare your application](https://docs.didit.me/authentication/overview.md#prepare-your-application).

**2. Register your callback and origin**

Open **Authentication > Security and sessions > Redirect URLs and allowed origins** and add:

| What | Value |
| - | - |
| Redirect URL | `http://localhost:3000/auth/callback` |
| Allowed origin | `http://localhost:3000` |

Didit only returns a person to a redirect URL you registered, character by character.
The allowed origin lets the browser exchange the code with your application's Didit origin.

![The Redirect URLs and allowed origins card in the Didit Business Console, next to the allowlist and blocklist and the sign-in URL](https://mintcdn.com/didit-0f962782/RpqZjIB1GnUPdMTN/images/authentication/console-redirect-urls.png?fit=max\&auto=format\&n=RpqZjIB1GnUPdMTN\&q=85\&s=8bf9cdacf97580097f4e8c6bd242af6f)

Redirect URLs and allowed origins, under Authentication > Security and sessions.

**3. Turn on a sign-in method**

Open **Authentication > Sign-in methods** and turn on **Email code**.
A new application starts with every method off, and the hosted page offers only the methods you turn on.

Add **Passkeys** too if you like, or a social sign-in method with **Didit test credentials**, which work in Sandbox without an app of your own.
Every method is described in [sign-in methods](https://docs.didit.me/authentication/sign-in-methods.md).

![The Sign-in methods page in the Didit Business Console, with the hosted sign-in page card, the passwordless and password methods, and a live preview of the hosted page](https://mintcdn.com/didit-0f962782/RpqZjIB1GnUPdMTN/images/authentication/console-sign-in-methods.png?fit=max\&auto=format\&n=RpqZjIB1GnUPdMTN\&q=85\&s=4f71ad0125f22dd8184ad837854ec8db)

Authentication > Sign-in methods, with a live preview of the hosted page.

**4. Copy your publishable key**

Open **Authentication > Developers** and copy the **Publishable key**.
In a Sandbox application it starts with `pk_test_`.

The publishable key is public and names your application's Didit sign-in origin.
Never put the **Secret key** in browser or mobile code.

**5. Install the SDK and sign in**

```bash theme={null}
npm install @didit-protocol/auth
```

```ts auth.ts theme={null}
import { createDiditAuth } from "@didit-protocol/auth";

export const auth = createDiditAuth({
  publishableKey: "pk_test_...",
  redirectUri: "http://localhost:3000/auth/callback",
});

// Your sign-in button
export async function onSignInClick() {
  await auth.signIn({ returnTo: "/dashboard" });
}

// Run once on http://localhost:3000/auth/callback
export async function onCallbackPage() {
  const { session, returnTo } = await auth.handleRedirectCallback();
  console.log(session.email, session.vendorData);
  window.location.replace(returnTo ?? "/");
}
```

Click your button: the hosted page asks for an email address and sends a six-digit code.
Enter the code, and Didit returns you to your callback, which exchanges the one-time code for the session's tokens.
A first sign-in with an address that has no account creates one, because the default sign-up policy lets anyone sign up.

![The hosted sign-in page on a phone, with a passkey button and email and password fields](https://mintcdn.com/didit-0f962782/RpqZjIB1GnUPdMTN/images/authentication/hosted-sign-in-phone.png?fit=max\&auto=format\&n=RpqZjIB1GnUPdMTN\&q=85\&s=842077ff63a6dcffc50b0f0542ab07e4)

The hosted sign-in page on a phone. It shows only the methods you turned on.

**6. Verify the token on your server**

Send the access token from `auth.getToken()` to your backend in the `Authorization` header, and verify it there on every protected request:

```ts server.ts theme={null}
import { verifyToken } from "@didit-protocol/auth/server";

export async function authenticate(request: Request) {
  const header = request.headers.get("authorization") ?? "";
  const token = header.startsWith("Bearer ") ? header.slice(7) : "";
  try {
    const claims = await verifyToken(token, { publishableKey: process.env.DIDIT_PUBLISHABLE_KEY });
    return { personId: claims.sub, vendorData: claims.vendor_data };
  } catch {
    return null;
  }
}
```

`verifyToken` checks the ES256 signature against your issuer's published keys, the issuer and the expiry.
Access tokens last at most 5 minutes, and `auth.getToken()` refreshes them for you.
Other languages verify the same token with the [server SDKs](https://docs.didit.me/integration/server-sdks/overview.md) or any JWT library, as [tokens and JWKS](https://docs.didit.me/authentication/tokens-and-jwks.md#verify-a-token-on-your-server) shows.

**7. See the sign-in in the console**

Open **Authentication > Sign-ins**.
Your sign-in is listed with its result, method, device, location and risk, next to the example sign-ins every sandbox starts with.
The person appears under **Users**.

![The Sign-ins page in the Didit Business Console, listing sign-in attempts with their state, person, method, device, location, risk and time](https://mintcdn.com/didit-0f962782/RpqZjIB1GnUPdMTN/images/authentication/console-sign-ins.png?fit=max\&auto=format\&n=RpqZjIB1GnUPdMTN\&q=85\&s=3c79b4e120c911b732d738e52d1687c8)

Authentication > Sign-ins: every attempt, with filters for state, method and risk.

To receive sign-in activity on your server, subscribe a [webhook destination](https://docs.didit.me/integration/webhooks.md) to `auth.signup` and `auth.login`. See [events and webhooks](https://docs.didit.me/authentication/events-and-webhooks.md).

## Before you go live

1. Turn on Authentication for your Live application on the **Products** page.
2. Register your production `https://` redirect URLs and origins there: a Live application accepts `https://` only.
3. Replace Didit's test credentials for social sign-in with your own app's client ID and secret.
4. Copy the Live publishable key (`pk_live_`) into your production configuration.
5. Walk through the [go-live checklist](https://docs.didit.me/authentication/integration-guide.md#go-live-checklist).

## Next steps

> [card] [Integration guide](https://docs.didit.me/authentication/integration-guide.md)
>
> Hosted or your own screens, token storage, sessions, step-up and troubleshooting.

> [card] [React and Next.js](https://docs.didit.me/authentication/quickstarts/nextjs.md)
>
> Components, hooks, HttpOnly cookies and `auth()` on the server.

> [card] [iOS, Android, React Native and Flutter](https://docs.didit.me/authentication/quickstarts/ios.md)
>
> Native sign-in with the system browser, passkeys and protected storage.

> [card] [Bot protection](https://docs.didit.me/authentication/bot-protection.md)
>
> Turn on the policies that stop bots and account takeover.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.