fix: never navigate in authProcedure when called from Sign In link flow (skipNavigation param)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
4b6adaad8d
commit
f27233f308
2 changed files with 19 additions and 18 deletions
|
|
@ -32,30 +32,29 @@ export class AuthProcedure {
|
||||||
*
|
*
|
||||||
* @returns true if authentication was successful, false otherwise
|
* @returns true if authentication was successful, false otherwise
|
||||||
*/
|
*/
|
||||||
async authenticateWithMicrosoft(email: string, password: string): Promise<boolean> {
|
async authenticateWithMicrosoft(email: string, password: string, skipNavigation = false): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
this._logger.info(`Authenticating as ${email}...`);
|
this._logger.info(`Authenticating as ${email}...`);
|
||||||
|
|
||||||
// Only navigate to login page if not already there.
|
if (skipNavigation) {
|
||||||
// When called after clicking "Sign in" on Teams pre-join page,
|
// When called after clicking "Sign in" on Teams pre-join page,
|
||||||
// the browser is already on login.microsoftonline.com WITH a return URL
|
// the browser is navigating to login.microsoftonline.com WITH a return URL
|
||||||
// embedded by Teams. Navigating again would destroy that return URL!
|
// embedded by Teams. We must NOT navigate ourselves - just wait for the
|
||||||
const currentUrl = this._page.url();
|
// email input to appear on whatever page we're redirected to.
|
||||||
if (!currentUrl.includes('login.microsoftonline.com')) {
|
const currentUrl = this._page.url();
|
||||||
this._logger.info('Not on login page yet, navigating to Microsoft login...');
|
this._logger.info(`Skipping navigation (preserving return URL). Current URL: ${currentUrl.substring(0, 80)}`);
|
||||||
|
} else {
|
||||||
|
this._logger.info('Navigating to Microsoft login...');
|
||||||
await this._page.goto(_LOGIN_URL, {
|
await this._page.goto(_LOGIN_URL, {
|
||||||
waitUntil: 'domcontentloaded',
|
waitUntil: 'domcontentloaded',
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
this._logger.info('Already on Microsoft login page - skipping navigation to preserve return URL');
|
|
||||||
await this._page.waitForLoadState('domcontentloaded', { timeout: 15000 });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for email input
|
// Wait for email input (may take time if page is still redirecting)
|
||||||
const emailInput = await this._page.waitForSelector(
|
const emailInput = await this._page.waitForSelector(
|
||||||
'input[type="email"], input[name="loginfmt"]',
|
'input[type="email"], input[name="loginfmt"]',
|
||||||
{ timeout: 10000 }
|
{ timeout: 20000 }
|
||||||
);
|
);
|
||||||
if (!emailInput) {
|
if (!emailInput) {
|
||||||
this._logger.error('Could not find email input field');
|
this._logger.error('Could not find email input field');
|
||||||
|
|
|
||||||
|
|
@ -200,15 +200,17 @@ export class BotOrchestrator {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signInClicked) {
|
if (signInClicked) {
|
||||||
// Wait for Microsoft login page to load
|
// Clicking "Sign in" on the Teams pre-join page triggers a redirect chain
|
||||||
await this._page!.waitForTimeout(3000);
|
// to login.microsoftonline.com WITH a return URL embedded by Teams.
|
||||||
|
// We must NOT navigate to login.microsoftonline.com ourselves - that would
|
||||||
// Perform Microsoft login (email, password, stay signed in)
|
// destroy the return URL. Instead, pass skipNavigation=true and let
|
||||||
|
// authenticateWithMicrosoft wait for the email input to appear.
|
||||||
const { AuthProcedure } = await import('./authProcedure');
|
const { AuthProcedure } = await import('./authProcedure');
|
||||||
const authProcedure = new AuthProcedure(this._page!, this._logger);
|
const authProcedure = new AuthProcedure(this._page!, this._logger);
|
||||||
const authSuccess = await authProcedure.authenticateWithMicrosoft(
|
const authSuccess = await authProcedure.authenticateWithMicrosoft(
|
||||||
this._options.botAccountEmail!,
|
this._options.botAccountEmail!,
|
||||||
this._options.botAccountPassword!
|
this._options.botAccountPassword!,
|
||||||
|
true // skipNavigation: preserve Teams return URL
|
||||||
);
|
);
|
||||||
|
|
||||||
if (authSuccess) {
|
if (authSuccess) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue