Get or refresh the agent token
const url = 'https://api.trybage.com/v1/token';const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"client_assertion":"eyJhbGciOiJFZERTQSIsInR5cCI6ImNsaWVudC1hc3NlcnRpb24rand0In0...","grant_type":"urn:openid:params:grant-type:ciba","auth_req_id":"req_3f9c2b1a","refresh_token":"rt_Xk2…"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.trybage.com/v1/token \ --header 'Content-Type: application/json' \ --data '{ "client_assertion": "eyJhbGciOiJFZERTQSIsInR5cCI6ImNsaWVudC1hc3NlcnRpb24rand0In0...", "grant_type": "urn:openid:params:grant-type:ciba", "auth_req_id": "req_3f9c2b1a", "refresh_token": "rt_Xk2…" }'With grant_type urn:openid:params:grant-type:ciba: call every interval seconds after bc-authorize (or once,
after Bage calls back in ping mode). While the person decides, the answer is 400 authorization_pending. Each
approved request gives one agent token (15 minutes), a refresh token and the person’s account link.
With grant_type refresh_token: a new agent token and a new refresh token for the same sign-in, without asking
the person. Refresh tokens work once each; using one twice ends the sign-in. An “Allow once” sign-in can be
refreshed for 8 hours after the person approved, an “Always” one until it goes 30 days unused. The person revoking
the agent, or the website cutting it off, ends it too.
Request Bodyrequired
Section titled “Request Bodyrequired”object
A one-time JWT signed with the agent’s private key (RFC 7523). See the description at the top.
With the CIBA grant type.
With the refresh_token grant type.
Responses
Section titled “Responses”The person approved.
object
A JWT (typ: agent+jwt, EdDSA). Send it to the website in the agent-token header, and sign each request with Web Bot Auth.
Exchange it at /v1/token for the next agent token. Single use. Absent once the sign-in can’t be extended.
Seconds until the refresh token stops working.
Only on sign-in. This agent’s stable handle for the person; use it as login_hint next time instead of their email.
Example
{ "token_type": "agent", "expires_in": 900, "scope": "browse cart", "refresh_expires_in": 28800, "account_link": "lnk_9QbV2xS7kq4mWd1e"}authorization_pending (keep polling), access_denied (the person said no), expired_token (nobody answered in 5 minutes), invalid_grant (unknown or already used request, or a refresh token that is unknown, used, expired or ended), unsupported_grant_type.
object
Example
{ "error": "authorization_pending"}invalid_client
object
Example
{ "error": "authorization_pending"}