Skip to content

Browser sessions

The API also accepts a session cookie, issued when you sign in through a browser — the web portal, or the Sign in button on /reference. It's an alternative to a bearer token, not an addition to one.

Name session_id
Flags HttpOnly, SameSite=Lax, Secure, Path=/
Bound to The browser that created it

Two consequences worth knowing:

  • HttpOnly means JavaScript cannot read it. A single-page app on the same origin doesn't need to: the browser attaches the cookie to every same-origin request automatically. There's nothing for your code to store or send.
  • The session is bound to the browser that created it. A cookie replayed from a different client is rejected and the session is dropped, so copying one out of a browser to use in a script doesn't work — and would fail closed rather than silently.

Sessions are shorter lived than device tokens and renew themselves while you're active, so a browser signed in and left alone will eventually need to sign in again.

The header always wins

If a request carries both an Authorization header and a session cookie, the header is used and the cookie is ignored. It's only consulted when no header is present — so an explicit token always overrides whatever the browser happens to be carrying.

Starting a session

Sign in through the portal or the Sign in button on /reference. Either one takes you through the usual sign-in page and, once you're through, the browser holds a session.

To start one from your own page, send the browser to:

https://api.taigacloud.tech/v2/oauth2/okta/login

This has to be a page navigation (a link or a redirect), not a fetch: the user signs in on a page of its own. When they're done, the browser lands on the portal. If it already has a valid session, it goes straight there.

Ending a session

Signing out is two steps, made from the browser that holds the session.

1. End the session with the API.

const res = await fetch('/v2/oauth2/logout', { method: 'POST' })
const { logout_url } = await res.json()

The cookie is cleared and the session can no longer be used.

2. Send the browser to logout_url.

window.location.assign(logout_url)

This completes the sign-out. Skip it, and the next sign-in may go through without asking for credentials.

Signing out ends this browser's session only. Device tokens issued to the same user on other clients stay valid. To withdraw those, see Devices and tokens.

For API clients, use a bearer token. The cookie exists for browsers: it cannot be obtained without a browser sign-in, cannot be moved between clients, and is not renewable from a script.