Skip to content

Commit

Permalink
Improve authentication on Skiff/Google
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathansampson committed Jul 31, 2023
1 parent a3dc409 commit 70bc851
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/tests/google/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum PageType {
LOGIN,
LOGIN_CAPTCHA,
ACCOUNT_CHOOSER,
MY_ACCOUNT,
CALENDAR,
WORKSPACE,
}
Expand All @@ -18,6 +19,10 @@ export async function getPageType(page: Page): Promise<PageType | undefined> {
return PageType.CALENDAR;
}

if (page.url().startsWith(`https://myaccount.google.com/`)) {
return PageType.MY_ACCOUNT;
}

// We're being presented with the Workspace info page
if (page.url().startsWith(`https://workspace.google.com/`)) {
return PageType.WORKSPACE;
Expand Down Expand Up @@ -100,6 +105,19 @@ async function authenticateUserLoginCaptcha(page: Page): Promise<void> {
.then((button) => button?.click());
}

async function confirmRecoveryPhoneNumber(page: Page): Promise<void> {
/**
* TODO (Sampson): In some cases the user will be asked
* to verify via receiving a test or phone call to their
* account-recovery phone number. In addition to these
* options the user may also be presented with an option
* to simplify verify the recovery number by entering it
* into a text field. We should handle this case, using
* the number from the .env file.
*/
throw new Error("Not implemented");
}

async function authenticateUserWorkspace(page: Page): Promise<void> {
console.log("google:authenticateUserWorkspace");

Expand Down Expand Up @@ -154,6 +172,21 @@ async function authenticateUserAccountChooser(page: Page): Promise<void> {
.then((button) => button?.click());
}

async function tryContinueFromMyAccount(page: Page): Promise<void> {
console.log("google:tryContinueFromMyAccount");

page
.goto("https://calendar.google.com/calendar/")
.then(() => {
console.log("google:tryContinueFromMyAccount: success");
authenticateUser(page);
})
.catch(() => {
console.log("google:tryContinueFromMyAccount: failure");
authenticateUser(page);
});
}

export async function authenticateUser(page: Page): Promise<void> {
console.log("google:authenticateUser");

Expand Down Expand Up @@ -181,6 +214,9 @@ export async function authenticateUser(page: Page): Promise<void> {
case PageType.WORKSPACE:
await authenticateUserWorkspace(page);
break;
case PageType.MY_ACCOUNT:
await tryContinueFromMyAccount(page);
break;
case PageType.CALENDAR:
// We are already logged in
break;
Expand Down
5 changes: 5 additions & 0 deletions src/tests/skiff/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export async function authenticateUser(page: Page): Promise<void> {

await page.goto(auth.AUTH_URL);

// If we're already logged in, we can skip the rest
if (page.url() === auth.AUTH_URL) {
return;
}

if (!auth.USERNAME || !auth.PASSWORD) {
throw new Error("USERNAME or PASSWORD not found");
}
Expand Down

0 comments on commit 70bc851

Please sign in to comment.