Structured Content 2022: Join our conference to explore fresh perspectives on content and digital experiences →

Authenticating the CLI when running remotely

As the authentication process for the CLI relies on you interacting with the API through a browser, this can be a problem when running the CLI on a remote server. However if you follow this recipe, you will be able to successfully authenticate the remote installed CLI.

  1. Go to https://api.sanity.io/v1/auth/login/github?type=token&origin=http://localhost

    Exchange github for google if you prefer that. You don't need anything actually running on localhost.
  2. Pick out the value of the sid parameter in the return url trying to redirect to localhost.
  3. Load https://api.sanity.io/v1/auth/fetch?sid=xxxx using the sid value from above.
  4. Get the token property from the result.
  5. Create the file ~/.config/sanity/config.json on the remote server in the home directory for the user running the CLI.

    Set the file contents to the following, and replace "yyyy" with the token value from above:
{
  "authToken": "yyyy",
  "authType": "normal"
}

Was this article helpful?