Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 85 additions & 8 deletions src/browser/auth/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type LoginState =
| 'LOGIN_PASSWORDLESS'
| 'GET_A_CODE'
| 'GET_A_CODE_2'
| 'OTP_CODE_ENTRY'
| 'UNKNOWN'
| 'CHROMEWEBDATA_ERROR'

Expand Down Expand Up @@ -56,6 +57,9 @@ export class Login {
totpInputOld: 'form[name="OneTimeCodeViewForm"]',
identityBanner: '[data-testid="identityBanner"]',
viewFooter: '[data-testid="viewFooter"] >> [role="button"]',
otherWaysToSignIn: '[data-testid="viewFooter"] span[role="button"]',
otpCodeEntry: '[data-testid="codeEntry"]',
backButton: '#back-button',
bingProfile: '#id_n',
requestToken: 'input[name="__RequestVerificationToken"]',
requestTokenMeta: 'meta[name="__RequestVerificationToken"]'
Expand Down Expand Up @@ -183,7 +187,8 @@ export class Login {
[this.selectors.emailIconOld, 'SIGN_IN_ANOTHER_WAY_EMAIL'],
[this.selectors.passwordlessCheck, 'LOGIN_PASSWORDLESS'],
[this.selectors.totpInput, '2FA_TOTP'],
[this.selectors.totpInputOld, '2FA_TOTP']
[this.selectors.totpInputOld, '2FA_TOTP'],
[this.selectors.otpCodeEntry, 'OTP_CODE_ENTRY']
]

const results = await Promise.all(
Expand Down Expand Up @@ -243,8 +248,11 @@ export class Login {
'KMSI_PROMPT',
'PASSWORD_INPUT',
'EMAIL_INPUT',
'SIGN_IN_ANOTHER_WAY', // Prefer password option over email code
'SIGN_IN_ANOTHER_WAY_EMAIL',
'SIGN_IN_ANOTHER_WAY',
'OTP_CODE_ENTRY',
'GET_A_CODE',
'GET_A_CODE_2',
'LOGIN_PASSWORDLESS',
'2FA_TOTP'
]
Expand Down Expand Up @@ -308,12 +316,56 @@ export class Login {
}

case 'GET_A_CODE': {
this.bot.logger.info(this.bot.isMobile, 'LOGIN', 'Attempting to bypass "Get code" via footer')
await this.bot.browser.utils.ghostClick(page, this.selectors.viewFooter)
await page.waitForLoadState('networkidle', { timeout: 5000 }).catch(() => {
this.bot.logger.debug(this.bot.isMobile, 'LOGIN', 'Network idle timeout after footer click')
})
this.bot.logger.info(this.bot.isMobile, 'LOGIN', 'Footer clicked, proceeding')
this.bot.logger.info(this.bot.isMobile, 'LOGIN', 'Attempting to bypass "Get code" page')

// Try to find "Other ways to sign in" link
const otherWaysLink = await page
.waitForSelector(this.selectors.otherWaysToSignIn, { state: 'visible', timeout: 3000 })
.catch(() => null)

if (otherWaysLink) {
this.bot.logger.info(this.bot.isMobile, 'LOGIN', 'Found "Other ways to sign in" link')
await this.bot.browser.utils.ghostClick(page, this.selectors.otherWaysToSignIn)
await page.waitForLoadState('networkidle', { timeout: 5000 }).catch(() => {
this.bot.logger.debug(
this.bot.isMobile,
'LOGIN',
'Network idle timeout after clicking other ways'
)
})
this.bot.logger.info(this.bot.isMobile, 'LOGIN', '"Other ways to sign in" clicked')
return true
}

// Fallback: try the generic viewFooter selector
const footerLink = await page
.waitForSelector(this.selectors.viewFooter, { state: 'visible', timeout: 2000 })
.catch(() => null)

if (footerLink) {
await this.bot.browser.utils.ghostClick(page, this.selectors.viewFooter)
await page.waitForLoadState('networkidle', { timeout: 5000 }).catch(() => {
this.bot.logger.debug(this.bot.isMobile, 'LOGIN', 'Network idle timeout after footer click')
})
this.bot.logger.info(this.bot.isMobile, 'LOGIN', 'Footer link clicked')
return true
}

// If no links found, try clicking back button
const backBtn = await page
.waitForSelector(this.selectors.backButton, { state: 'visible', timeout: 2000 })
.catch(() => null)

if (backBtn) {
this.bot.logger.info(this.bot.isMobile, 'LOGIN', 'No sign in options found, clicking back button')
await this.bot.browser.utils.ghostClick(page, this.selectors.backButton)
await page.waitForLoadState('networkidle', { timeout: 5000 }).catch(() => {
this.bot.logger.debug(this.bot.isMobile, 'LOGIN', 'Network idle timeout after back button')
})
return true
}

this.bot.logger.warn(this.bot.isMobile, 'LOGIN', 'Could not find way to bypass Get Code page')
return true
}

Expand Down Expand Up @@ -447,6 +499,31 @@ export class Login {
return true
}

case 'OTP_CODE_ENTRY': {
this.bot.logger.info(
this.bot.isMobile,
'LOGIN',
'OTP code entry page detected, clicking back to find password option'
)
const backButton = await page
.waitForSelector(this.selectors.backButton, { state: 'visible', timeout: 2000 })
.catch(() => null)
if (backButton) {
await this.bot.browser.utils.ghostClick(page, this.selectors.backButton)
await page.waitForLoadState('networkidle', { timeout: 5000 }).catch(() => {
this.bot.logger.debug(
this.bot.isMobile,
'LOGIN',
'Network idle timeout after back button click'
)
})
this.bot.logger.info(this.bot.isMobile, 'LOGIN', 'Navigated back from OTP entry page')
} else {
this.bot.logger.warn(this.bot.isMobile, 'LOGIN', 'Back button not found on OTP page')
}
return true
}

case 'UNKNOWN': {
const url = new URL(page.url())
this.bot.logger.warn(
Expand Down
32 changes: 32 additions & 0 deletions src/browser/auth/methods/MobileAccessLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,40 @@ export class MobileAccessLogin {
private scope = 'service::prod.rewardsplatform.microsoft.com::MBI_SSL'
private maxTimeout = 180_000 // 3min

// Selectors for handling Passkey prompt during OAuth
private readonly selectors = {
secondaryButton: 'button[data-testid="secondaryButton"]',
passKeyError: '[data-testid="registrationImg"]',
passKeyVideo: '[data-testid="biometricVideo"]'
} as const

constructor(
private bot: MicrosoftRewardsBot,
private page: Page
) {}

private async checkSelector(selector: string): Promise<boolean> {
return this.page
.waitForSelector(selector, { state: 'visible', timeout: 200 })
.then(() => true)
.catch(() => false)
}

private async handlePasskeyPrompt(): Promise<void> {
try {
// Handle Passkey prompt - click secondary button to skip
const hasPasskeyError = await this.checkSelector(this.selectors.passKeyError)
const hasPasskeyVideo = await this.checkSelector(this.selectors.passKeyVideo)
if (hasPasskeyError || hasPasskeyVideo) {
this.bot.logger.info(this.bot.isMobile, 'LOGIN-APP', 'Found Passkey prompt on OAuth page, skipping')
await this.bot.browser.utils.ghostClick(this.page, this.selectors.secondaryButton)
await this.page.waitForLoadState('networkidle', { timeout: 5000 }).catch(() => {})
}
} catch {
// Ignore errors in prompt handling
}
}

async get(email: string): Promise<string> {
try {
const authorizeUrl = new URL(this.authUrl)
Expand Down Expand Up @@ -72,6 +101,9 @@ export class MobileAccessLogin {
break
}
}

// Handle Passkey prompt if it appears
await this.handlePasskeyPrompt()
} catch (err) {
this.bot.logger.debug(
this.bot.isMobile,
Expand Down