Log in to a Sitecore instance with Sitecore Command Line Interface

For advanced use of the Sitecore Command Line Interface (CLI) against a Sitecore Experience Manager (XM) Cloud instance, such as using specific authorities and audiences, you can use the sitecore login command.

Important

For regular operations against an XM Cloud instance, you use the commands provided by the Sitecore CLI XM Cloud plugin.

To log in to a Sitecore instance using sitecore login, the 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.

Note

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

Use an interactive user login (device code flow)

To log in with an interactive user login to a Sitecore instance, you must use the following:

  • The authority URL. The default authority URL is https://auth.sitecorecloud.io.

  • The audience URL: https://api.sitecorecloud.io.

  • The predefined client ID: Chi8EwfFnEejksk3Sed9hlalGiM9B2v7.

  • The URL of the Sitecore instance.

  • Your username.

  • Your password.

To log in:

  1. In the console, go to your Sitecore project folder.

  2. Log in with the following command:

    RequestResponse
    dotnet sitecore login --authority https://<authority-url> --cm https://<sitecore-instance> --audience https://<xm-cloud-audience-url> --client-id <client-id> --allow-write true
  3. The sitecore login command opens a login webpage 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 webpage.

    Important

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

Tip

After logging in with the device flow, you can switch to the client credentials (non-interactive) flow by running the command:

RequestResponse
dotnet sitecore login --client-id <client-id> --client-secret <client-secret> --client-credentials true

When switching to the non-interactive login flow, you must use the credentials generated when creating an authentication/automation client for your environment or organization.

Use a non-interactive client login (client credentials flow)

To use a non-interactive login flow with a Sitecore XM Cloud instance, you must have the following:

To log in:

  1. In the console, go to your Sitecore project folder.

  2. Log in with the following command:

    RequestResponse
    dotnet sitecore login --authority https://<authority-url> --cm http://<sitecore-instance> --audience https://<xm-cloud-audience-url> --allow-write true --client-credentials true --client-id <client-id> --client-secret <client-secret>
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>

When switching to the interactive login flow, you must use the predefined client ID Chi8EwfFnEejksk3Sed9hlalGiM9B2v7.

Do you have some feedback for us?

If you have suggestions for improving this article,