# Sign in with Voidnet (/docs/identity/sign-in)



“Sign in with Voidnet” lets people authenticate with their Voidnet account and arrive at your site with a stable identity. You map that identity to the account you already have, exactly as you would with Google or Microsoft Entra.

## Create a client [#create-a-client]

1. Open **Console → Sign in**.
2. Choose a type:
   * **Confidential** for a website with a backend. You receive a secret, shown once.
   * **Public** for a native app or a backend-for-frontend. No secret; PKCE is mandatory.
3. Add at least one redirect URI. HTTPS is required; HTTP is accepted only for `localhost`.
4. Optionally add post-logout redirect URIs, a logo, and policy links.

The client id looks like `pub_…`. The authorize, token, JWKS and logout endpoints are shown on the same page.

## The flow [#the-flow]

1. Send the browser to the authorization endpoint with `response_type=code`, your `client_id`, your `redirect_uri`, `scope=openid profile email`, a random `state`, a random `nonce`, and a PKCE challenge.
2. The user signs in at Voidnet and approves the request.
3. Voidnet redirects back to your `redirect_uri` with `code` and the same `state`.
4. Your backend exchanges the code at the token endpoint.
5. Verify the `id_token`, then read `sub`, `email`, `email_verified`, `name` and `preferred_username`.

```ts
import { createRemoteJWKSet, jwtVerify } from "jose";

const ISSUER = "https://oauth.openvoidnet.com";
const jwks = createRemoteJWKSet(new URL(`${ISSUER}/.well-known/jwks.json`));

export function authorizeUrl(clientId: string, redirectUri: string, state: string, nonce: string, challenge: string) {
  const url = new URL(`${ISSUER}/oauth2/auth`);
  url.searchParams.set("response_type", "code");
  url.searchParams.set("client_id", clientId);
  url.searchParams.set("redirect_uri", redirectUri);
  url.searchParams.set("scope", "openid profile email");
  url.searchParams.set("state", state);
  url.searchParams.set("nonce", nonce);
  url.searchParams.set("code_challenge", challenge);
  url.searchParams.set("code_challenge_method", "S256");
  return url.toString();
}

export async function exchange(clientId: string, clientSecret: string, code: string, redirectUri: string) {
  const basic = Buffer.from(`${clientId}:${clientSecret}`).toString("base64");
  const response = await fetch(`${ISSUER}/oauth2/token`, {
    method: "POST",
    headers: {
      Authorization: `Basic ${basic}`,
      "Content-Type": "application/x-www-form-urlencoded",
    },
    body: new URLSearchParams({ grant_type: "authorization_code", code, redirect_uri: redirectUri }),
  });
  if (!response.ok) throw new Error(`token exchange failed: ${response.status}`);
  return response.json() as Promise<{ id_token: string; access_token: string }>;
}

export async function verify(idToken: string, clientId: string, expectedNonce: string) {
  const { payload } = await jwtVerify(idToken, jwks, { issuer: ISSUER, audience: clientId });
  if (payload.nonce !== expectedNonce) throw new Error("nonce mismatch");
  return {
    sub: String(payload.sub),
    email: typeof payload.email === "string" ? payload.email : null,
    emailVerified: payload.email_verified === true,
    name: typeof payload.name === "string" ? payload.name : null,
  };
}
```

Public clients use PKCE instead of a secret: send `code_challenge` and `code_challenge_method=S256` on the authorization request, and `code_verifier` on the token request, with no client secret.

A browser-only SPA exchanges the code through its own backend. Voidnet does not open the token endpoint to arbitrary origins.

## Match the user [#match-the-user]

1. Look up `(provider = "voidnet", sub)`. If it exists, that is your user.
2. Otherwise, if `email_verified` is true and exactly one local user has that verified email, link it and store `sub`.
3. Otherwise, ask the user to link explicitly or create an account.
4. Afterwards resolve by `sub` only.

This is the same rule as call-time identity, so a user who signs in here is already resolved when their calls arrive through Voidnet.

## Logout [#logout]

Send the browser to the end-session endpoint with `id_token_hint` and one of your registered post-logout redirect URIs. Voidnet clears its session and returns to your site.

## Errors [#errors]

| Case                      | What happens                                                              |
| ------------------------- | ------------------------------------------------------------------------- |
| Unregistered redirect URI | The authorization request is rejected; nothing is redirected              |
| Wrong or reused code      | `invalid_grant` from the token endpoint                                   |
| Nonce or state mismatch   | Your own check rejects the response; do not trust it                      |
| Deleted client            | New authorizations fail immediately; issued tokens expire within one hour |
