# Identity for Publishers (/docs/identity/publisher)



When an app receives a call from Voidnet, the request can carry the buyer's Voidnet identity in the `X-Voidnet-Identity` header. The value is a signed JWT. Validating it needs no Voidnet SDK and no call back to Voidnet.

To let people sign in to your own website with their Voidnet account, see [Sign in with Voidnet](https://docs.openvoidnet.com/docs/identity/sign-in).

## Enable it [#enable-it]

1. Open **Console → Identity**.
2. Copy your **audience** URI. It is unique to your publisher account.
3. Set each app's mode to `optional` or `required`.
4. Deploy the validation below.

The audience URI and the issuer do not change per app.

## The contract [#the-contract]

| Value          | Where                                                                    |
| -------------- | ------------------------------------------------------------------------ |
| Issuer         | `https://oauth.openvoidnet.com`                                          |
| Public keys    | `https://oauth.openvoidnet.com/.well-known/jwks.json`                    |
| Audience       | Console → Identity, `https://api.openvoidnet.com/id/publisher/<your-id>` |
| Header         | `X-Voidnet-Identity`                                                     |
| Token lifetime | 15 minutes                                                               |

## Validate [#validate]

The token is an RS256 JWT access token. Verify the signature, the issuer, the audience and the expiry. Never trust an unverified claim.

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

const jwks = createRemoteJWKSet(
  new URL("https://oauth.openvoidnet.com/.well-known/jwks.json"),
);

export async function resolveVoidnetUser(header: string | undefined) {
  if (!header) return null;

  const { payload } = await jwtVerify(header, jwks, {
    issuer: "https://oauth.openvoidnet.com",
    audience: "https://api.openvoidnet.com/id/publisher/YOUR_PUBLISHER_ID",
  });

  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,
    username: typeof payload.preferred_username === "string" ? payload.preferred_username : null,
  };
}
```

If verification fails, treat the call as having no identity. Do not fall back to the email header, a query parameter, or an unsigned value.

## Claims [#claims]

| Claim                        | Present when                          |
| ---------------------------- | ------------------------------------- |
| `iss`                        | always                                |
| `sub`                        | always, the stable Voidnet user id    |
| `aud`                        | always, your audience URI             |
| `exp`, `iat`                 | always                                |
| `scope`                      | always                                |
| `email`, `email_verified`    | the buyer granted the `email` scope   |
| `name`, `preferred_username` | the buyer granted the `profile` scope |

## Match it to your user [#match-it-to-your-user]

1. Look up the external identity `(provider = "voidnet", sub)`. If it exists, that is your user.
2. If not, and `email_verified` is true, find a local user with that verified email. If exactly one exists, link it and store `sub`.
3. If there is no match or the match is ambiguous, ask the buyer to link explicitly.
4. After linking, resolve by `sub` only. Email changes no longer affect the link.

This is the same pattern you already use for Google, Microsoft Entra ID, or your own password accounts: one local user, several external identities.

## Handle the two errors [#handle-the-two-errors]

| Error                    | Meaning                                                    | What to do                                                        |
| ------------------------ | ---------------------------------------------------------- | ----------------------------------------------------------------- |
| `identity_link_required` | The app requires identity and the buyer has not connected. | Return the error unchanged so the buyer can connect from Voidnet. |
| `identity_unavailable`   | The identity provider could not issue a token.             | Return the error; do not serve the call as anonymous.             |

## Revocation [#revocation]

When a buyer disconnects, Voidnet stops issuing tokens for that publisher. A token already issued stays valid until it expires, at most 15 minutes. Your server needs no revocation endpoint.

## Security notes [#security-notes]

* Validate the audience. A token issued for another publisher must not be accepted.
* Do not log the token. Log the resolved `sub` if you need a correlation id.
* Treat absence of the header as "no identity", not as an error, unless your app is set to `required`.
