The OAuth client entry
For: a developer of a third-party app that signs a person in to an authtempo OAuth provider.
What it does: this page lists the options and the calls of createOAuthClient, the answers, and every export of the entry. The export check holds this page to packages/client/src/oauth/index.ts.
Before you start
Section titled “Before you start”- Read Be the OAuth and OIDC provider for MCP clients for the provider side.
Options
Section titled “Options”createOAuthClient(options) answers an OAuthClient. The type of the options is OAuthClientOptions. A wrong option throws at construction.
| Option | Default | What it does |
|---|---|---|
issuer |
required | baseURL plus basePath of the provider. An http or https URL with no query, fragment, or user info. |
clientId |
required | A cl_ id of registerOAuthClient, or the URL of the client’s metadata document. |
redirectUri |
required | A redirect URI of the client, exactly. |
resource |
required | The resource of the access token: an entry of oauth.resources. |
scopes |
required | One or more scopes. offline_access asks for a refresh token. |
fetch |
globalThis.fetch |
The fetch of every call. |
crypto |
webCrypto() |
The PKCE seam, a PkceCrypto. Hermes needs expoCrypto of @authtempo/handoff/expo. |
pending |
memoryPendingStore() |
Where a sign-in waits for its redirect, a PendingStore. A single-page app passes browserPendingStore(). |
clock |
the system clock | Tests inject one. |
Warning: the client accepts an http: issuer on any host. It then sends the code, the verifier, and the tokens over plain HTTP. Use https: outside local development.
| Call | Route | Value |
|---|---|---|
authorizeURL() |
GET /oauth/authorize (built, not fetched) |
The URL to open, with PKCE S256, state, scope, and resource |
handleRedirect(url) |
POST /oauth/token |
OAuthTokens: accessToken, tokenType, expiresAt, scopes, refreshToken, idToken |
refresh(refreshToken, { scopes }) |
POST /oauth/token |
OAuthTokens. The scopes input is optional and narrows the grant. |
revoke(token) |
POST /oauth/revoke |
{ revoked: true } |
userinfo(accessToken) |
GET /oauth/userinfo |
The claims by scope |
registerOAuthClient({ issuer, clientName, redirectUris, initialAccessToken? }) |
POST /oauth/register |
{ clientId, redirectUris }. initialAccessToken goes as the bearer when the server sets oauth.registration.initialAccessTokenHash. Without it, such a server answers invalid_token. |
OAUTH_CALLS is the table of these routes and of the metadata document.
continueAuthorizeURL({ baseURL, basePath?, requestId }) builds <baseURL><basePath>/oauth/authorize?request_id=<requestId> and fetches nothing. The app’s own sign-in route (oauth.signInURL) sends the browser there after the sign-in. basePath is /auth by default. An id that is not an oq_ id throws a TypeError.
The answers
Section titled “The answers”Every call answers an OAuthResult: { ok: true, value } or an OAuthFailure of { ok: false, code, status }. The code is an OAuthClientCode: a code of the OAuth table, network, unexpected, cancelled, or redirect_mismatch.
handleRedirectanswersredirect_mismatchwhen thestatematches no sign-in of this client, or whenissis not the issuer.- It also answers
redirect_mismatchwhen the URL is not onredirectUri. - A sign-in waits at most
PENDING_TTL_MS, 10 minutes. A later redirect answersredirect_mismatch. - The
errorof a redirect, such asaccess_denied, comes with status 0. A code outside the OAuth table answersunexpected. - A 200 answer of the wrong shape answers
unexpected. Nothing throws for an answer. - The client does not verify the ID token. Call
userinfo, or verify the access token with the verify package.
A single-page app
Section titled “A single-page app”- A page on another origin needs that origin in a redirect URI of its client.
- The token request is a form post with no other header, so the browser sends no preflight.
- The register, revoke, and userinfo endpoints have no CORS for another origin.
- Keep the pending sign-in in
sessionStoragewithbrowserPendingStore(). TheStorageLiketype is the part ofsessionStoragethat it calls. - Each new sign-in removes the pending sign-ins that are older than 10 minutes.
Exports
Section titled “Exports”| Export | What it is |
|---|---|
createOAuthClient, registerOAuthClient |
The client and the registration. |
memoryPendingStore, browserPendingStore, PENDING_TTL_MS |
The pending stores and the wait limit. A PendingSignIn is one record. |
makePkce, webCrypto, base64Url |
PKCE S256 and its codec. |
parseReturnedUrl |
The parser of a URL that a redirect brought back, which answers a Returned. It does not use URL, which Hermes lacks in part. |
OAUTH_CALLS |
The route table of the entry. |
continueAuthorizeURL |
The way back from the app’s own sign-in route to the held authorize request. |
| Area | Types |
|---|---|
| The client | OAuthClient, OAuthClientOptions, OAuthTokens |
| The pending sign-in | PendingSignIn, PendingStore, StorageLike |
| PKCE and the redirect | PkceCrypto, Returned |
| The answers | OAuthClientCode, OAuthFailure, OAuthResult |