Identity & SSOvendor:microsoftEmail OTPUnwrapped Magic LinkCarrier SMS DIDCloud KMS TOTP

Automate Microsoft 365 & Azure Entra ID 2FA Codes in Playwright & Stagehand

Automate Microsoft Entra ID, Azure, and M365 6–8 digit single-use security codes, SMS challenges, and TOTP authenticator flows.

Curated Stage 4 Extractor Profile (vendor:microsoft)

Matches 6–8 digit Microsoft security, verification, and single-use codes across `microsoft.com`, `accountprotection.microsoft.com`, `live.com`, and `office.com`, while disqualifying Azure invoices and M365 renewal receipts.

Matched Sender Domains
microsoft.comaccountprotection.microsoft.comlive.comoffice.com
Login URL example: https://login.microsoftonline.com/
Filtered Non-Auth Noise
  • Azure monthly invoice alerts
  • Microsoft 365 subscription renewal emails

1. 60-Second Gmail & Outlook Auto-Forwarding Filter

Don't want to change your existing account email on Microsoft 365 & Entra ID? Keep your corporate inbox on Microsoft 365 & Entra ID and forward only verification emails to <identity-slug>@in.sentryrelay.com. Sentry Relay's Stage 2 unwrapper preserves the original Microsoft 365 & Entra ID sender header automatically (full setup guide).

# Paste into Gmail -> Settings -> Filters -> Create a new filter ("Has the words")
from:(microsoft.com OR accountprotection.microsoft.com OR live.com OR office.com) ("security code" OR "verification code" OR "single-use code")

# Action: Forward it to -> <your-identity-slug>@in.sentryrelay.com

2. Copy-Paste Microsoft 365 & Entra ID 2FA Automation Snippets

Choose your browser automation stack below. All snippets resolve codes in <200ms with Upstash Redis 15-second lookback protection so arrived-before-wait race conditions never fail a run.

import { test, expect } from '@playwright/test';
import { SentryRelay } from '@sentryrelay/sdk';

const relay = new SentryRelay({ apiKey: process.env.SENTRY_RELAY_API_KEY! });

test('Microsoft Entra ID / M365 login with Email security code or TOTP', async ({ page }) => {
  await page.goto('https://login.microsoftonline.com/');
  await page.fill('input[type="email"]', process.env.M365_EMAIL!);
  await page.click('input[type="submit"]');

  // If passwordless single-use email code is prompted
  const otcInput = page.locator('input[name="otc"]');
  if (await otcInput.isVisible({ timeout: 5000 }).catch(() => false)) {
    const auth = await relay.wait('m365-bot', {
      sender: 'microsoft',
      timeout: 35,
    });
    await otcInput.fill(auth.event!.otpCode!);
    await page.click('input[type="submit"]');
  }

  await expect(page).toHaveURL(/office\.com|portal\.azure\.com|microsoft/);
});

3. Microsoft 365 & Entra ID Production Gotchas

Frequently Asked Questions

Does Sentry Relay extract Microsoft 7-digit and 8-digit codes?
Yes. The vendor:microsoft rule specifically matches 6-, 7-, and 8-digit security and single-use codes.
Can Microsoft 365 forward emails to Sentry Relay?
Yes. Use Outlook Web Mail Rules (Settings -> Mail -> Rules) or Exchange transport rules to forward verification emails to your Identity's @in.sentryrelay.com address.
Will Azure invoice emails interfere with OTP detection?
No. Azure invoices and Microsoft 365 renewal alerts are disqualified before extraction.
Provision an Isolated Identity for Microsoft 365 & Entra ID

Start free in 3 minutes with @in.sentryrelay.com email + Simulated SMS, or attach a dedicated US carrier Telnyx SMS DID starting on Builder ($29/mo) and Growth/Pro ($79/mo).