CLI and APIs
Ask the person for a token
Your tool needs a token, and you do not want the person to copy one by hand. Ask for it with the device login: the person checks the request in the browser and creates the token, and your tool gets it.
2 min read
1. Start the request
The request needs no token:
curl -X POST -H "Content-Type: application/json" \
-d '{"client_name": "my-tool", "token": {"name": "my-tool", "repos": ["acme/app"], "actions": ["contents:read", "pulls:read", "pulls:create"], "ttl": 7200}}' \
https://source.tanstack.com/api/v1/login/device/code
The answer:
{
"device_code": "<secret>",
"user_code": "BCDF-GHJK",
"verification_uri": "https://source.tanstack.com/login/device",
"verification_uri_complete": "https://source.tanstack.com/settings/tokens/new?code=BCDF-GHJK",
"expires_in": 900,
"interval": 5
}
The fields of token are in the fields of the token request.
2. Show the person the link
Show the person verification_uri_complete. They can change the token there, then click Create token or Deny.

3. Poll for the token
Every interval seconds, poll with the device_code:
curl -X POST -H "Content-Type: application/json" \
-d '{"device_code": "<secret>"}' \
https://source.tanstack.com/api/v1/login/device/token
4. Read the answer of the poll
| Answer | What it means |
|---|---|
200 with {"access_token": "tsp_...", "token_type": "bearer"} | The token. Only the first poll after the approval gets it. |
400 with authorization_pending | The person did not answer yet. Poll again. |
400 with slow_down | You poll too fast. Wait 5 seconds more between polls. |
400 with access_denied or expired_token | The person clicked Deny, or 15 minutes passed. Start again. |
Done
Your tool has the token that the person created. It can differ from your request, because the person can change the repositories, the actions and the end time.
The fields of the token request
| Field | What it is |
|---|---|
name | The name of the token in the list of the person. |
repos | The repositories, as owner/name. At most 20. |
actions | The actions, for example contents:write or vault:read. The Advanced part of the token form lists them all. |
ttl | How long the token lives, in seconds. The default is 3600, and the most is 365 days. |