---
title: Helper libraries
summary: Sign-in itself is plain OpenID Connect, so use any certified library for it (the quickstarts use Auth.js, openid-client, go-oidc and Authlib). You need more only when your code has to check Tessera...
section: connect
order: 6
---
# Helper libraries

> **Planned.** Tessera will publish small Go and TypeScript helper libraries for the checks that APIs and backends often need. They are not published yet, and there is nothing to install. Everything they would do is standard OAuth 2.0 and OpenID Connect, and this page shows how to do each job today with libraries you already use.

Sign-in itself is plain OpenID Connect, so use any certified library for it (the quickstarts use Auth.js, openid-client, go-oidc and Authlib). You need more only when your code has to check Tessera tokens or events for itself.

## What to use for each job

| Job | The plain way |
| --- | --- |
| Validate an access token in your API | Check the signature against `<issuer>/jwks`, then `typ`, `iss`, `aud` and `exp`: [below](#validate-an-access-token-in-your-api) |
| Validate an ID token | Your OIDC library does it (`openid-client`, `go-oidc`, Authlib, Auth.js) |
| Verify back-channel logout tokens | [Logout](/docs/connect/logout.md) lists the checks |
| Verify webhook signatures | HMAC-SHA256 over `timestamp.body`, in TypeScript and Python on [Webhooks](/docs/connect/webhooks.md#verify-every-delivery) |
| Check roles and permissions | Read the `roles` and `permissions` claims after validating: [claims](/docs/reference/claims.md) |
| Protect an MCP server | The metadata document and the `401` challenge: [MCP quickstart](/docs/quickstart/mcp-server.md) |
| Follow the revocation feed | `GET /revocations`, a signed document: [endpoints](/docs/reference/endpoints.md#revocations-feed-revocations) |
| Introspect or revoke a token | `POST /introspect` and `POST /revoke`: [endpoints](/docs/reference/endpoints.md) |
| Get and renew a token for an agent or job | One `POST /token`: [get and refresh tokens in code](/docs/agents/token-source.md) |
| Device flow, token exchange | Plain form posts: [get and refresh tokens in code](/docs/agents/token-source.md) |
| Call the admin API | A bearer token with audience `tessera-admin`: [calling the admin API](/docs/agents/overview.md#calling-the-admin-api) |

## Validate an access token in your API

An access token is a signed JWT. Your API checks, on every request:

- the signature, against the realm's keys at `<issuer>/jwks` (`EdDSA` or `RS256`, chosen by the header's `kid`; cache the key set and refetch on an unknown `kid`);
- the header `typ` is `at+jwt`, so an ID token or logout token is never taken for an access token;
- `iss` equals your realm's issuer exactly (for example `https://login.kurthlabs.com/realms/acme`);
- `aud` contains your API's identifier. For a token a plain sign-in app got for itself (no `resource`), the audience is the app's `client_id`;
- `exp` has not passed, with a little clock leeway.

TypeScript, with [`jose`](https://github.com/panva/jose):

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

const issuer = "https://login.kurthlabs.com/realms/acme";
const jwks = createRemoteJWKSet(new URL(`${issuer}/jwks`));

export async function validate(token: string) {
  const { payload } = await jwtVerify(token, jwks, {
    issuer,
    audience: "https://api.example.com",
    typ: "at+jwt",
    algorithms: ["EdDSA", "RS256"],
  });
  return payload; // throws on any failure: answer 401
}
```

Go, with [`go-oidc`](https://github.com/coreos/go-oidc) (its verifier checks the signature, `iss` and `exp`; the audience and `typ` are two lines of your own):

```go
const (
	issuer   = "https://login.kurthlabs.com/realms/acme"
	audience = "https://api.example.com"
)

var verifier = oidc.NewVerifier(issuer, oidc.NewRemoteKeySet(context.Background(), issuer+"/jwks"), &oidc.Config{
	SkipClientIDCheck:    true, // the audience is checked below
	SupportedSigningAlgs: []string{"EdDSA", "RS256"},
})

func validate(ctx context.Context, raw string) (map[string]any, error) {
	header, _, _ := strings.Cut(raw, ".")
	decoded, err := base64.RawURLEncoding.DecodeString(header)
	if err != nil {
		return nil, err
	}
	var h struct{ Typ string }
	if json.Unmarshal(decoded, &h) != nil || !strings.EqualFold(h.Typ, "at+jwt") {
		return nil, errors.New("not an access token")
	}
	token, err := verifier.Verify(ctx, raw)
	if err != nil {
		return nil, err
	}
	if !slices.Contains(token.Audience, audience) {
		return nil, errors.New("token is for another API")
	}
	var claims map[string]any
	return claims, token.Claims(&claims)
}
```

Return `401` with a `WWW-Authenticate: Bearer` header when validation fails. For an MCP server the header also points at your protected-resource metadata: see the [MCP quickstart](/docs/quickstart/mcp-server.md). These checks happen offline, so a revoked token is noticed only when it expires. To notice sooner, call `POST /introspect` for sensitive actions or follow the [revocation feed](/docs/agents/revocation-and-kill-switch.md#revocation-feed).

## Webhooks and logout

Webhook signatures are an HMAC you can check with the standard library in any language: [Webhooks](/docs/connect/webhooks.md#verify-every-delivery) has TypeScript and Python code. Back-channel logout tokens are JWTs signed with the same keys as above: [Logout](/docs/connect/logout.md) lists what to check.
