From 3f223e26a2c0aab6abb1d017fcf56b81f4de94d9 Mon Sep 17 00:00:00 2001 From: Martin Machacek Date: Sun, 5 Jan 2025 19:16:38 +0100 Subject: [PATCH] New command: Revoke Sign-in Sessions --- .../commands/user/user-session-revoke.spec.ts | 20 ++----------------- .../commands/user/user-session-revoke.ts | 7 +------ 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/src/m365/entra/commands/user/user-session-revoke.spec.ts b/src/m365/entra/commands/user/user-session-revoke.spec.ts index fe8d663f72..64b8f28f30 100644 --- a/src/m365/entra/commands/user/user-session-revoke.spec.ts +++ b/src/m365/entra/commands/user/user-session-revoke.spec.ts @@ -17,7 +17,6 @@ import { cli } from '../../../../cli/cli.js'; describe(commands.USER_SESSION_REVOKE, () => { const userId = 'abcd1234-de71-4623-b4af-96380a352509'; const userName = 'john.doe@contoso.com'; - const userNameWithDollar = "$john.doe@contoso.com"; let log: string[]; let logger: Logger; @@ -119,7 +118,7 @@ describe(commands.USER_SESSION_REVOKE, () => { it('revokes all sign-in sessions for a user specified by userId without prompting for confirmation', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if (opts.url === `https://graph.microsoft.com/v1.0/users/${userId}/revokeSignInSessions`) { + if (opts.url === `https://graph.microsoft.com/v1.0/users('${userId}')/revokeSignInSessions`) { return { value: true }; @@ -134,7 +133,7 @@ describe(commands.USER_SESSION_REVOKE, () => { it('revokes all sign-in sessions for a user specified by UPN while prompting for confirmation', async () => { const postRequestStub = sinon.stub(request, 'post').callsFake(async (opts) => { - if (opts.url === `https://graph.microsoft.com/v1.0/users/${userName}/revokeSignInSessions`) { + if (opts.url === `https://graph.microsoft.com/v1.0/users('${userName}')/revokeSignInSessions`) { return { value: true }; @@ -150,21 +149,6 @@ describe(commands.USER_SESSION_REVOKE, () => { assert(postRequestStub.calledOnce); }); - it('revokes all sign-in sessions for a user specified by UPN which starts with $ without prompting for confirmation', async () => { - const postRequestStub = sinon.stub(request, 'post').callsFake(async (opts) => { - if (opts.url === `https://graph.microsoft.com/v1.0/users('${userNameWithDollar}')/revokeSignInSessions`) { - return { - value: true - }; - } - - throw 'Invalid request'; - }); - - await command.action(logger, { options: { userName: userNameWithDollar, force: true, verbose: true } }); - assert(postRequestStub.calledOnce); - }); - it('handles error when user specified by userId was not found', async () => { sinon.stub(request, 'post').rejects({ error: diff --git a/src/m365/entra/commands/user/user-session-revoke.ts b/src/m365/entra/commands/user/user-session-revoke.ts index 1add61372c..75b9751dad 100644 --- a/src/m365/entra/commands/user/user-session-revoke.ts +++ b/src/m365/entra/commands/user/user-session-revoke.ts @@ -51,13 +51,8 @@ class EntraUserSessionRevokeCommand extends GraphCommand { await logger.logToStderr(`Invalidating all the refresh tokens for user ${userIdentifier}...`); } - // user principal name can start with $ but it violates the OData URL convention, so it must be enclosed in parenthesis and single quotes - const requestUrl = userIdentifier!.startsWith('$') - ? `${this.resource}/v1.0/users('${userIdentifier}')/revokeSignInSessions` - : `${this.resource}/v1.0/users/${userIdentifier}/revokeSignInSessions`; - const requestOptions: CliRequestOptions = { - url: requestUrl, + url: `${this.resource}/v1.0/users('${userIdentifier}')/revokeSignInSessions`, headers: { accept: 'application/json;odata.metadata=none' },