# OIDC Trusted Workloads (/docs/api/guides/oidc-trusted-workloads)

Authenticate backend services to Strave Public API v2 with short-lived OIDC tokens instead of static API keys.

Static API keys can leak and stay valid until revoked. Strave recommends
**OIDC Trusted Workloads** for every production backend, and strictly requires
short-lived OIDC/OAuth 2.1 JWT access tokens on sensitive routes such as 2D
replay viewer session minting.

## 1. Register your workload in the Developer Portal [#1-register-your-workload-in-the-developer-portal]

1. Open your organisation's Application in Strave.
2. Go to **Credentials** and select **Add workload**.
3. Pick your provider (Vercel, GitHub Actions, GitLab CI, or Google Cloud) and
   enter your project, repository, or service account claim values.
4. Keep the audience `https://strave.gg/api/auth`.

## 2. Configure `@strave/sdk` with `oidcWorkload` [#2-configure-stravesdk-with-oidcworkload]

`@strave/sdk` exchanges your platform OIDC JWT via RFC 7523 (`jwt-bearer`),
caches the resulting 15-minute Strave JWT access token in memory, and refreshes
it automatically before expiry:

```ts
import { createStraveClient } from "@strave/sdk";
import { getVercelOidcToken } from "@vercel/oidc";

export const strave = createStraveClient({
	oidcWorkload: {
		clientId: process.env.STRAVE_CLIENT_ID!,
		getAssertion: () =>
			getVercelOidcToken({ audience: "https://strave.gg/api/auth" }),
		scopes: ["event:read", "broadcast:manage"],
	},
});
```

## 3. Use with Effect v4 [#3-use-with-effect-v4]

Pass the same `oidcWorkload` config into `StraveClient.layer`:

```ts
import { StraveClient } from "@strave/sdk/effect";
import { getVercelOidcToken } from "@vercel/oidc";
import { Effect } from "effect";

const StraveLive = StraveClient.layer({
	oidcWorkload: {
		clientId: process.env.STRAVE_CLIENT_ID!,
		getAssertion: () =>
			getVercelOidcToken({ audience: "https://strave.gg/api/auth" }),
		scopes: ["event:read"],
	},
});

const program = Effect.gen(function* () {
	const strave = yield* StraveClient;
	return yield* strave.events.get("event_01K4ZK");
}).pipe(Effect.provide(StraveLive));
```

## When static API keys are rejected [#when-static-api-keys-are-rejected]

High-security routes such as
`POST /api/v2/replays/{matchId}/{mapIndex}/viewer-sessions` verify tokens with
strict JWKS JWT validation and reject `strave_sk_` API keys with `401
invalid_token`. Use `oidcWorkload` or an OAuth 2.1 flow for these routes.