Skip to content

Commit

Permalink
New command: Revoke Sign-in Sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinM85 committed Jan 5, 2025
1 parent ef2b822 commit 3f223e2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
20 changes: 2 additions & 18 deletions src/m365/entra/commands/user/user-session-revoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
};
Expand All @@ -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
};
Expand All @@ -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:
Expand Down
7 changes: 1 addition & 6 deletions src/m365/entra/commands/user/user-session-revoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
Expand Down

0 comments on commit 3f223e2

Please sign in to comment.