Skip to content
Source
Sign inSign up

Log in from scripts and CI

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
  • src sends SRC_TOKEN only to its default host. Set SRC_HOST (for example localhost:5173) to use another forge.
  • src never reads GH_TOKEN or GITHUB_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 with src auth login --with-token, and src auth status checks 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.

FlagWhat it does
-R, --repoA repository that the token works on. Required. Repeat it for more repositories, all on one host.
--readAsks for the read actions. This is the default without --write or --action.
--writeAsks for the read and write actions.
--actionAdds one action, for example vault:read. Repeat it for more. Without --read or --write, the token gets only these actions.
--expiresHow long the token lives: 30m, 2h, 7d, at most 365d. The default is 1h.
  • --name sets the name of the token. The default is src token on and 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.