CLI and APIs
Log in from a script, a CI job or an agent
A script or a CI job has no browser, so it cannot run the browser login of src. Give it a token in SRC_TOKEN, or let your agent ask for a token that you approve.
2 min read
1. Make a token
Make a personal access token in Settings, Tokens. Make an access token shows the form.
2. Give the token to the job
Give the token to the job as the variable SRC_TOKEN.
3. Run src
Run src with no login step:
src issue list -R acme/app
srcsendsSRC_TOKENonly to its default host. SetSRC_HOST(for examplelocalhost:5173) to use another forge.srcnever readsGH_TOKENorGITHUB_TOKEN, so your GitHub token never goes to the forge.- A token that is limited to repositories cannot do account-level work, such as
src repo create. It can still log in withsrc auth login --with-token, andsrc auth statuschecks it.
Done
Your script or your job runs src with its token, and needs no browser. To get only the fields that your script needs, as JSON or as text, see Get JSON and text out of src.
Ask for a token from the terminal
Your agent needs a token, and you do not want to give it your own. src token create asks for a token that works only on some repositories, with some actions, until its end time. You approve it in the browser.
TOKEN=$(src token create -R acme/app --write --expires 2h)
It needs no login, so an agent can run it. gh has no such command.
| Flag | What it does |
|---|---|
-R, --repo | A repository that the token works on. Required. Repeat it for more repositories, all on one host. |
--read | Asks for the read actions. This is the default without --write or --action. |
--write | Asks for the read and write actions. |
--action | Adds one action, for example vault:read. Repeat it for more. Without --read or --write, the token gets only these actions. |
--expires | How long the token lives: 30m, 2h, 7d, at most 365d. The default is 1h. |
--namesets the name of the token. The default issrc token onand the name of your computer.- The token goes to stdout only. The code and the URL go to stderr.
See Let your agent ask for a token for the approval in the browser.