Log in to an instance with the Sitecore CLI

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

Important

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

XM Cloud is now SitecoreAI

Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.

For logging in to an instance using sitecore cloud 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 cloud login --help command for details on the cloud login command.

Use an interactive user login (device code flow)

To log in with an interactive user login to an SitecoreAI 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 SitecoreAI instance.

  • Your username.

  • Your password.

To log in:

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

  2. Log in with the following command:

    RequestResponse
    dotnet sitecore cloud login --authority https://<AUTHORITY_URL> --cm https://<SITECOREAI_INSTANCE> --audience https://<SITECOREAI_AUDIENCE_URL> --client-id <CLIENT_ID> --allow-write true
    XM Cloud is now SitecoreAI

    Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.

    The sitecore cloud login command opens a login page in your browser.

  3. On the login page, enter your username and password and click OK.

    The sitecore cloud 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, if you want to switch to the client credentials (non-interactive) flow, run the following command:

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

When switching to the non-interactive login flow, 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 SitecoreAI instance, you need the following:

To log in:

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

  2. Log in with the following command:

    RequestResponse
    dotnet sitecore cloud login --authority https://<AUTHORITY_URL> --cm http://<SITECOREAI_INSTANCE> --audience https://<SITECOREAI_AUDIENCE_URL> --allow-write true --client-credentials true --client-id <CLIENT_ID> --client-secret <CLIENT_SECRET>
XM Cloud is now SitecoreAI

Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.

Tip

After logging in with the client credentials flow, if you want to switch to the device flow, run the following command:

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

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

Do you have some feedback for us?

If you have suggestions for improving this article,