hardis:auth:logout
Description
Command Behavior
Revokes, in the Salesforce org, the session that the CI/CD job opened with hardis:auth:login.
Each JWT login (External Client App or Connected App) opens a new OAuth session for the integration user. Salesforce keeps it alive until it times out, so a pipeline that runs often can reach a concurrent sessions limit (for example a login flow that blocks a user above 10 sessions).
Run this command as the last step of the job to end the session right away:
- Only the access token stored for
--target-orgis revoked. Other sessions of the same user (other jobs, other pipelines) are not touched. - By default the local SF CLI auth of the org is removed too. Use
--no-remove-localto keep it. - By default a failure only prints a warning so it never breaks a successful deployment. Use
--fail-on-errorto make it fail the job.
Run it even when the deployment fails, since a failed job still holds a session: in GitLab put it in after_script, in GitHub Actions use if: always(). A later job that logs in again opens a new session and needs its own logout step.
Technical explanations
- The sfdx-hardis prerun authentication hook is skipped for this command: logging in again would open a new session. Without
--target-org, the default org set byhardis:auth:loginis used. - Reads the access token stored by the login step for the target org.
- Calls
POST <instanceUrl>/services/oauth2/revokewithtoken=<accessToken>, which ends the matching session in the org. - Calls
AuthRemover.removeAuth(username)from@salesforce/coreto remove the local auth file.
Parameters
| Name | Type | Description | Default | Required | Options |
|---|---|---|---|---|---|
| debug -d |
boolean | Activate debug mode (more logs) | |||
| fail-on-error | boolean | Fail the command if the session cannot be revoked (by default only a warning is shown) | |||
| flags-dir | option | Import flag values from a directory. | |||
| json | boolean | Format output as json. | |||
| remove-local | boolean | Also remove the local SF CLI auth of the org after the session is revoked | |||
| target-org -o |
option | Username or alias of the target org. Not required if the target-org configuration variable is already set. |
true | ||
| websocket | option | Websocket host:port for VsCode SFDX Hardis UI integration |
Examples
$ sf hardis:auth:logout
$ sf hardis:auth:logout --target-org my-org-alias
$ sf hardis:auth:logout --target-org my-org-alias --no-remove-local --fail-on-error