Log in to a Sitecore instance with Sitecore Command Line Interface

Current version: 10.4

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.

Important

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:

  1. In PowerShell, go to your Sitecore project folder.

  2. Log in with the following command:

    RequestResponse
    dotnet sitecore login --authority https://<sitecore-identity-server> --cm https://<sitecore-instance> --allow-write true --client-id <client-id>
    Note

    The default client ID is Device.

  3. The sitecore login command opens a login web page in your browser. Enter your username and password and click OK.

  4. 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.

    Important

    Do not commit the .sitecore/user.json file to source control as it contains privileged information.

Tip

After logging in with the device flow, you can switch to the client credentials flow by running the command:

RequestResponse
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:

  1. In PowerShell, go to your Sitecore project folder.

  2. Log in with the following command:

    RequestResponse
    dotnet 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>
Note

Run the dotnet sitecore login --help command for more details on the login command.

Tip

After logging in with the client credentials flow, you can switch to the device flow by running the following command:

RequestResponse
dotnet sitecore login  --client-credentials false --client-id <client-id>

The default client ID is Device.

Do you have some feedback for us?

If you have suggestions for improving this article,