Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

feat(cli): stop exposing API keys in whoami command (#2896)

Musthaq Ahamadac6a6c11d335
diff --git a/ts/packages/cli/src/commands/whoami.cmd.ts b/ts/packages/cli/src/commands/whoami.cmd.ts
index f5d9ec78b..48ede82ca 100644
--- a/ts/packages/cli/src/commands/whoami.cmd.ts
+++ b/ts/packages/cli/src/commands/whoami.cmd.ts
@@ -2,14 +2,14 @@ import { Command } from '@effect/cli';
import { Effect, Option } from 'effect';
import { ComposioUserContext } from 'src/services/user-context';
import { TerminalUI } from 'src/services/terminal-ui';
-import { redact } from 'src/ui/redact';
/**
* CLI command to display your account information.
+ * Never prints or exposes API keys.
*
* @example
* ```bash
- * composio whoami <command>
+ * composio whoami
* ```
*/
export const whoamiCmd = Command.make('whoami', {}).pipe(
@@ -22,25 +22,28 @@ export const whoamiCmd = Command.make('whoami', {}).pipe(
yield* ctx.data.apiKey.pipe(
Option.match({
onNone: () => ui.log.warn('You are not logged in yet. Please run `composio login`.'),
- onSome: apiKey =>
+ onSome: () =>
Effect.gen(function* () {
- const redactedApiKey = redact({ value: apiKey, prefix: 'ak_' });
const defaultOrgId = Option.getOrUndefined(ctx.data.orgId);
const defaultProjectId = Option.getOrUndefined(ctx.data.projectId);
const testUserId = Option.getOrUndefined(ctx.data.testUserId);
yield* ui.note(
[
- `Global User API Key: ${redactedApiKey}`,
`Default Org ID: ${defaultOrgId ?? 'not set'}`,
`Default Project ID: ${defaultProjectId ?? 'not set'}`,
`Test User ID: ${testUserId ?? 'not set'}`,
].join('\n'),
'Global User Context'
);
+ yield* ui.log.step(
+ [
+ 'To switch orgs:\n> composio orgs switch',
+ 'To get API keys:\n> composio init (in your project)',
+ ].join('\n\n')
+ );
yield* ui.output(
JSON.stringify({
- global_user_api_key: apiKey,
default_org_id: defaultOrgId ?? null,
default_project_id: defaultProjectId ?? null,
test_user_id: testUserId ?? null,
diff --git a/ts/packages/cli/test/src/commands/whoami.cmd.test.ts b/ts/packages/cli/test/src/commands/whoami.cmd.test.ts
index b746dd4d6..6dac1043e 100644
--- a/ts/packages/cli/test/src/commands/whoami.cmd.test.ts
+++ b/ts/packages/cli/test/src/commands/whoami.cmd.test.ts
@@ -16,8 +16,8 @@ describe('CLI: composio whoami', () => {
const lines = yield* MockConsole.getLines();
const output = lines.join('\n');
- expect(output).toContain(`api_key_from_test_config_provider`);
- expect(output).toContain(`"global_user_api_key":"api_key_from_test_config_provider"`);
+ expect(output).not.toContain(`api_key_from_test_config_provider`);
+ expect(output).not.toContain(`global_user_api_key`);
expect(output).toContain(`"default_org_id":null`);
expect(output).toContain(`"default_project_id":null`);
expect(output).toContain(`"test_user_id":null`);
@@ -33,8 +33,8 @@ describe('CLI: composio whoami', () => {
const lines = yield* MockConsole.getLines();
const output = lines.join('\n');
- expect(output).toContain(`api_key_from_test_fixture`);
- expect(output).toContain(`"global_user_api_key":"api_key_from_test_fixture"`);
+ expect(output).not.toContain(`api_key_from_test_fixture`);
+ expect(output).not.toContain(`global_user_api_key`);
expect(output).toContain(`"default_org_id":null`);
expect(output).toContain(`"default_project_id":null`);
expect(output).toContain(`"test_user_id":null`);