Skip to main content

Revoking a User's Sessions in Microsoft Entra ID After a Suspected Account Compromise

Suspect a compromised Entra ID account? Disable sign-in, revoke sessions with Revoke-MgUserSignInSession, and confirm signInSessionsValidFromDateTime and logs.

KBY Technologies11 min readFoundation12 min
Revoking a User's Sessions in Microsoft Entra ID After a Suspected Account Compromise

Advertising disclosure: this article includes partner links. KBY may earn a commission if you sign up or buy through one, at no extra cost to you. How we make money.

Before you begin

  • A non-production Microsoft Entra tenant and a cloud-only, role-free test user created for the lab.
  • An admin account in that tenant with the User Administrator role.
  • PowerShell with the Microsoft.Graph.Users and Microsoft.Graph.Users.Actions modules.

Underlined words are defined in the KBY Lexicon. Tap or click one to see what it means.

When an account may be compromised, two actions in do most of the work. Clearing Account enabled stops the user getting any new sign-in. Selecting Revoke sessions, or running Revoke-MgUserSignInSession, invalidates the refresh tokens and browser session cookies issued so far. Do both, in that order, then read the user’s accountEnabled and signInSessionsValidFromDateTime properties to prove they took effect.

The constraint to plan around is timing. An access token already issued stays valid until it expires, and an app’s own session cookie is outside Entra ID’s reach. So revocation works less like pulling a plug and more like cancelling a pass at reception. Nobody gets a new pass, but someone already inside keeps going until their pass runs out. Knowing which tokens are checked, and when, lets you explain that gap to whoever is waiting on the incident.

#By the end you will be able to

  • Explain how access tokens, refresh tokens and session cookies keep a user signed in to apps that trust Microsoft Entra ID.
  • Block new sign-ins and revoke existing sessions for one user, in the admin center or with Microsoft Graph PowerShell.
  • Prove the change with accountEnabled, signInSessionsValidFromDateTime, the sign-in logs and the audit log.
  • Predict which access survives revocation for a while, and why.
  • Choose the right role and permissions, and reverse the change cleanly.

#Before you start: a test user in a lab tenant

  • A non-production Microsoft Entra tenant, such as a developer or trial tenant, and a cloud-only test user you created for the lab. Never practise on a colleague’s account, even with their agreement.
  • An admin account in that tenant with the User Administrator role. It can disable and enable users and invalidate refresh tokens. If the test user holds an admin role, Microsoft asks for Privileged Authentication Administrator instead, so keep the test user role-free.
  • PowerShell with the Microsoft Graph PowerShell SDK modules Microsoft.Graph.Users and Microsoft.Graph.Users.Actions.
  • A second browser, or a private window, where you can sign in as the test user.

#How a signed-in user stays signed in

Revocation only makes sense once you can see what it cancels. Microsoft Entra ID is the token issuer: it checks who the user is and its policies, then hands out tokens. The apps, such as or a line-of-business web app, are the resource side. They trust those tokens and decide what to show. The boundary between issuer and app is where most surprises after revocation come from.

#
Access tokens, refresh tokens and session cookies

An access token is what an app presents to an API. Microsoft gives it a random default lifetime between 60 and 90 minutes, 75 on average. In tenants without , clients such as Teams and Microsoft 365 get two hours. A refresh token lets the app get a new access token without asking for the password again. Each time it is used, Entra ID re-evaluates the user, and that check is the moment revocation can bite.

Browser apps mostly use session cookies instead. The user gets two: one from Entra ID and one from the app itself. Once the app has issued its own cookie, it controls access by its own rules. It might not send the user back to Entra ID for as long as that cookie is valid. Entra ID cannot revoke a cookie the app issued; only the app can.

Black and white close-up of rusty padlocks on a fence symbolizing security and love.
Photo by Virooshan Theva on Pexels

#
What revoking sessions changes, and what it leaves alone

Revoke sessions resets one property on the user, signInSessionsValidFromDateTime, to the current time. Any refresh token or Entra session cookie issued before that time is now invalid. When an app next tries to use one, it gets an error and must send the user to sign in again. Microsoft notes a small delay of a few minutes before tokens are revoked.

Revocation alone does not stop someone with the password from signing in again. That is why the account is disabled first. Revocation also leaves two things running for a while. An access token already issued works until it expires, and an app’s own session cookie lasts as long as the app allows. External guest users are not covered either, because they sign in through their home tenant.

Some services close that gap faster. With continuous access evaluation (CAE), Exchange Online, SharePoint Online and Teams subscribe to critical events from Entra ID. These events include the account being disabled, a password reset and an admin revoking all refresh tokens. Microsoft aims for near real time, but documents that up to 15 minutes can pass. CAE needs no Conditional Access policy, though it does not support guest accounts.

Rendering diagram...

The flowchart shows the order Microsoft documents. A user synced from on-premises Active Directory is disabled there first, with the password reset twice. Then the Entra steps follow for every user, and the checks come last.

#
Who is allowed to do it

Two built-in roles matter here. Helpdesk Administrator can invalidate refresh tokens and reset passwords, but cannot disable accounts. User Administrator can do both. Each is a privileged role, and which users it can act on depends on the roles those users hold. For scripts, the least-privileged Graph permission for revocation is User.RevokeSessions.All. Update-MgUser lists User.EnableDisableAccount.All for changing accountEnabled.

#An example in practice: a reported phishing click

Picture a service desk ticket at 10:05. A user reports typing their password into a page that looked like the Microsoft sign-in screen. The analyst opens Entra ID then Users then All users, selects the user, and under Account status selects Edit. In Properties they clear Account enabled and select Save. Back on the user’s Overview page, they select Revoke sessions.

The order matters. Disabling first means the attacker cannot sign in again with the stolen password once the old tokens die. A few minutes later, an app that tries to refresh with an old token is refused. The error can be AADSTS50173, which says the grant was revoked and names the user’s TokensValidFrom date. A fresh sign-in attempt meets AADSTS50057, the code for a disabled account.

What the analyst tells the incident lead matters as much. Outlook and Teams should lose access within minutes through CAE. A web app with its own long session cookie may not. The next jobs are a password reset, a look at the sign-in logs, and a word with app owners about their own sessions.

Note that the user was disabled, not deleted. Deleting adds nothing here, and a deleted user has to be restored within the 30-day window before anyone can work with it again.

#Try it on a test account

The outcome you want is to block and revoke one test user, prove both changes from the directory, and then put the account back exactly as it was. Only two commands change state, and each has a direct reversal. Sign in as the test user in a private window first, so there is a live session to revoke.

  1. Connect with the lab’s three permissions, consenting when prompted:
    1Connect-MgGraph -Scopes "User.Read.All","User.EnableDisableAccount.All","User.RevokeSessions.All"
  2. Find the test user and confirm it is the right one:
    1$User = Get-MgUser -Search UserPrincipalName:'lab.user@yourlabtenant.onmicrosoft.com' -ConsistencyLevel eventual
    2$User | Format-List Id, DisplayName, UserPrincipalName

    Expected evidence: exactly one user, with your lab display name and UPN. Stop if more than one user, or anyone else, comes back.

  3. Record the baseline. Graph does not return these properties by default, so select them:
    1Get-MgUser -UserId $User.Id -Property "id,displayName,accountEnabled,onPremisesSyncEnabled,signInSessionsValidFromDateTime" |
    2    Format-List DisplayName, AccountEnabled, OnPremisesSyncEnabled, SignInSessionsValidFromDateTime

    Expected evidence: AccountEnabled is True and OnPremisesSyncEnabled is empty or False. Write down the SignInSessionsValidFromDateTime value. Stop if OnPremisesSyncEnabled is True, because a synced user is managed in Active Directory.

  4. Block new sign-ins. This changes state; the reversal is step 8:
    1Update-MgUser -UserId $User.Id -AccountEnabled:$false
  5. Revoke the existing sessions. Add -WhatIf first if you want to see what would run:
    1Revoke-MgUserSignInSession -UserId $User.Id

    A successful call returns no error. Nothing undoes revocation itself, but its only effect is that the user must sign in again.

  6. Run the read from step 3 again. Expected evidence: AccountEnabled is False, and SignInSessionsValidFromDateTime is later than your baseline, close to the time you ran step 5.
  7. Wait a few minutes, then try a fresh sign-in as the test user in a new private window. Expected evidence: the attempt is refused as a disabled account. The first window may keep working until its app next asks Entra ID for a token, which is the gap described earlier.
  8. Clean up by enabling the account again:
    1Update-MgUser -UserId $User.Id -AccountEnabled:$true

    Run the read once more and confirm AccountEnabled is True. The test user can then sign in normally.

Following along? Tap a step’s number to tick it off.

You pass when the directory shows both changes and the refused sign-in appears in the logs. The account must also be enabled again at the end. In the portal, the same cleanup is Account status > Edit, then tick Account enabled and select Save.

A woman in a dark room uses a laptop, illuminated by its screen, with server equipment in the background.
Photo by Christina Morillo on Pexels

#How to check the account is really locked out

The read-back in step 6 is the strongest evidence, because it comes straight from the user object. accountEnabled set to False proves new sign-ins are blocked. A signInSessionsValidFromDateTime later than the baseline proves the revocation ran, since only revokeSignInSessions resets it. Neither proves that every app has noticed yet, and you should say so when you report.

The logs give you the user’s side of the story. In the sign-in logs, filter on the test user and look for the refused attempt from step 7. The method is the same one used to find why a user’s sign-in failed in the Entra sign-in logs. In the audit log, the UserManagement category should show a Disable account activity, and an entry named Update StsRefreshTokenValidFrom Timestamp for the revocation. After cleanup you should also see Enable account.

If an app still works after the revocation, check how it signs users in before calling it a failure. A background app may now report that no session exists, much like AADSTS50058 for a silent sign-in with no session. That is the revocation working, not breaking.

#Where it goes wrong

  • Revoking without disabling. The old tokens die, but anyone with the password can sign straight back in. Disable first, then revoke, and reset the password once the account is contained.
  • Calling it done the moment the button is pressed. Existing access tokens run until they expire, and Microsoft notes a delay of a few minutes. Report what is blocked now and what will lapse.
  • Forgetting apps with their own sessions. Entra ID cannot end an app’s own cookie. Ask the app owner, or rely on the app’s provisioning to remove the user.
  • Changing a synced user only in Entra ID. For a user synced from Active Directory, Microsoft says to disable the user there. Editing Account enabled in Entra ID for a synced user is advised only in an emergency.
  • Expecting it to cover guests. Revocation does not apply to external users, and CAE does not support guest accounts. Their home tenant controls their sessions, so remove their access to your resources instead.
  • Using a broader role than needed. Global Administrator is not required. Helpdesk Administrator can revoke, and User Administrator can also disable.

#What to remember

  • Disable the account first, then revoke sessions; revocation alone does not stop a fresh sign-in.
  • Revocation resets signInSessionsValidFromDateTime, which invalidates every earlier refresh token and Entra session cookie.
  • Access tokens already issued keep working until they expire, and app-issued cookies are outside Entra ID’s control.
  • Exchange Online, SharePoint Online and Teams react through CAE within minutes, documented as up to 15.
  • Prove the change from the user object and the logs, and reverse a lab change by setting AccountEnabled back to True.

#Handling a real compromised account

In production, the same two actions start the response rather than finish it. Microsoft’s documented sequence for a hybrid user begins in Active Directory: disable the account there and reset the password twice, using random values. The Entra steps follow. Disabling the user’s registered devices needs the Cloud Device Administrator role at minimum. A managed device can also be wiped through Intune, but that is a separate decision for the incident lead, because wiped data cannot be recovered.

Keep the change small and recorded. Act on one named user, note the time you revoked sessions, and keep the baseline you read before changing anything. Re-enabling is the rollback for a disabled account. Do it only once the password has been reset and whoever owns the incident agrees the account is safe. Anything beyond that goes to someone with the right role and the authority to decide. That includes removing devices, wiping data or acting on an admin account.

About this page

Credited to

Dates

Published

Sources

This page lists no external sources.

Corrections

No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.

Reader Interaction

Comments

Add a thoughtful note on Revoking a User's Sessions in Microsoft Entra ID After a Suspected Account Compromise. Comments are checked for spam and held for moderation before appearing.

Loading comments...

More from KBY that goes with this article.

Discover more

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

Build practical engineering skills.

Receive new lessons, learning paths, practical exercises and early-career guidance.