Log in to a Sitecore instance with Sitecore Command Line Interface
To log in to a Sitecore instance, Sitecore Command Line Interface (CLI) allows two flows of authentication and authorization:
-
An interactive user login, using a device code flow.
-
A non-interactive client login, using a client credentials flow. This is used by clients such as Continuous Integration servers.
Sitecore CLI requires the use of Sitecore Identity.
Use an interactive user login (device code flow)
To log in with an interactive user login to a Sitecore instance, you must have the following:
-
The URL of the Sitecore Identity Server.
-
The URL of the Sitecore instance.
-
Your username.
-
Your password.
To log in:
-
In PowerShell, go to your Sitecore project folder.
-
Log in with the following command:
RequestResponsedotnet sitecore login --authority https://<sitecore-identity-server> --cm https://<sitecore-instance> --allow-write true --client-id <client-id>
NoteThe default client ID is
Device
. -
The
sitecore login
command opens a login web page in your browser. Enter your username and password and click OK. -
The
sitecore login
command stores your login arguments in the.sitecore\user.json
file together with an access token. You are now logged in, and you can close the login web page.ImportantDo not commit the
.sitecore/user.json
file to source control as it contains privileged information.
After logging in with the device flow, you can switch to the client credentials flow by running the command:
dotnet sitecore login --client-id <client-id> --client-secret <client-secret> --client-credentials true
Use a non-interactive client login (client credentials flow)
To log in with a non-interactive client login to a Sitecore instance, you must have the following:
-
The URL of the Sitecore Identity Server.
-
The URL of the Sitecore instance.
-
The client ID.
-
The client secret.
To log in:
-
In PowerShell, go to your Sitecore project folder.
-
Log in with the following command:
RequestResponsedotnet sitecore login --authority https://<sitecore-identity-server> --cm http://<sitecore-instance> --allow-write true --client-credentials true --client-id <client-id> --client-secret <client-secret>
Run the dotnet sitecore login --help
command for more details on the login command.
After logging in with the client credentials flow, you can switch to the device flow by running the following command:
dotnet sitecore login --client-credentials false --client-id <client-id>
The default client ID is Device
.