bitwarden / directory-connector

A tool for syncing a directory (AD, LDAP, Azure, G Suite, Okta) to an organization.
https://bitwarden.com
GNU General Public License v3.0
249 stars 84 forks source link

Fix warning when attempting a double login in the cli #468

Closed addisonbeck closed 5 months ago

addisonbeck commented 5 months ago

Fix warning when attempting a double login in the cli

Type of change

Objective

When a user tries to login on the CLI without logging out from the previous session, a text should be displayed with the client_id from the active session. For some reason, the output displays an undefined string as part of the client_id.

Code changes

There is a method called exitIfAuthed() that handles this behavior:

async exitIfAuthed() {
    const authed = await this.stateService.getIsAuthenticated();
    if (authed) {
    const type = await this.stateService.getEntityType();
    const id = await this.stateService.getEntityId();
    this.processResponse(
        Response.error("You are already logged in as " + type + "." + id + "."),
        true,
      );
    }
}

stateService.getEntityType() is returning undefined because it is not set anywhere. This call isn't necessary at all. All authentication in Directory Connector is done with organization-based API keys. This means the entity type is always "organization". The best solution here would be to remove the unused StateService methods and use a static string instead of the broken type variable.

Screenshots

The changes in this PR result in the following error message being displayed:

Screenshot 2024-03-18 at 2 34 28 PM

References

bitwarden-bot commented 5 months ago

Logo Checkmarx One – Scan Summary & Detailsac4b1900-df16-429d-8269-71a5f352b591

No New Or Fixed Issues Found