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.
- Go to
https://api.sanity.io/v1/auth/login/github?type=token&origin=http://localhost
Exchangegithub
forgoogle
if you prefer that. You don't need anything actually running on localhost. - Pick out the value of the
sid
parameter in the return url trying to redirect to localhost. - Load
https://api.sanity.io/v1/auth/fetch?sid=xxxx
using thesid
value from above. - Get the
token
property from the result. - 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"
}