Skip to main content
POST/gate/refresh

Refresh Session

Exchanges a refresh token for a new Gate access JWT and a new refresh token, extending the end user's session under the project's session policy.

Each refresh replaces the refresh token: store the returned refreshToken and refresh one call at a time per session.

Presenting a refresh token that was already exchanged revokes the session and returns K9O_SESSION_EXPIRED (401) with context.reason replay; the session's newer refresh token is refused from then on.

Parameters
projectSlug *path

The project's slug: the path segment after @.

It is unique within the org.

Request body
refreshToken *string

The refresh token from the sign-in or from the last refresh.

Each one works once.

Responses
HTTPK9O CodeDescription
200Success
401K9O_INVALID_CREDENTIALSThe refresh token is unknown, or the end user is locked.
401K9O_SESSION_EXPIREDThe session has ended and a fresh sign-in is required. `context.reason` says why: `inactive`, `max_length`, `revoked`, or `replay` (a refresh token that was already exchanged was presented again, and the session is now revoked).
Response body (200)
data *object

A new access token and a new refresh token for the same session.

The refresh token you sent no longer works.

accessToken *string

A signed JWT that authenticates the end user to this project's API.

Send it as Authorization: Bearer <accessToken>.

Its subject (sub) is the end user's id (eu_...), its audience (aud) is the project id (proj_...), and its issuer is the API origin of the region that holds the end user.

It lives for the project's end-user access token lifetime: 30 minutes by default, settable from 5 to 60 minutes. expiresAt is when it expires.

It cannot be revoked early: signing out or revoking sessions stops the next refresh, but a token already issued stays valid until expiresAt.

refreshToken *string

An opaque secret (43 base64url characters) that gets a new access token from POST /@{projectSlug}/gate/refresh.

Store it securely and never send it anywhere else.

It is single use: every refresh returns a new refresh token, and sending the one it replaced a second time ends the whole session.

It stops working when the session ends: on sign-out, a password reset, a revoke-all, or when the project's session limits are reached (by default 30 days without a refresh, or 90 days after sign-in, whichever comes first).

expiresAt *string <date-time>

When accessToken expires.

Refresh before this time to keep the end user signed in.

meta *any

Request metadata: cost, timing and the request and trace ids.

TypeScript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.gate.refreshToken({
  refreshToken: 'EXAMPLE-refresh-token-not-a-real-secret-000'
})

Showing example in TypeScript

Request example
{
  "refreshToken": "EXAMPLE-refresh-token-not-a-real-secret-000"
}
Response example (200)
{
  "data": {
    "accessToken": "string",
    "refreshToken": "string",
    "expiresAt": "string"
  }
}

More in Sign-in & Sessions