From 266b322e8f4d00f1430ce194b591b7b558f96eb0 Mon Sep 17 00:00:00 2001 From: kAy Date: Mon, 14 Aug 2023 12:06:50 +1000 Subject: [PATCH] SSO Login fixes - Manual clicking replaced by automation (#2340) - Manual clicking replaced by automation --- .../pages/ConfigSteps/OrgsContainer/index.tsx | 17 +++++++++++++---- spa/src/pages/ConfigSteps/index.tsx | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/spa/src/pages/ConfigSteps/OrgsContainer/index.tsx b/spa/src/pages/ConfigSteps/OrgsContainer/index.tsx index 71f04929c4..d1b5871bc2 100644 --- a/spa/src/pages/ConfigSteps/OrgsContainer/index.tsx +++ b/spa/src/pages/ConfigSteps/OrgsContainer/index.tsx @@ -5,6 +5,7 @@ import { token } from "@atlaskit/tokens"; import { useState } from "react"; import WarningIcon from "@atlaskit/icon/glyph/warning"; import { popup } from "../../../utils"; +import OauthManager from "../../../services/oauth-manager"; type OrgDivType = { key: number; @@ -42,20 +43,28 @@ const OrganizationsList = ({ organizations, loaderForOrgClicked, setLoaderForOrgClicked, - clearGitHubToken, + resetCallback, connectingOrg, }: { organizations: Array; // Passing down the states and methods from the parent component loaderForOrgClicked: boolean; setLoaderForOrgClicked: (args: boolean) => void; - clearGitHubToken: () => void; + resetCallback: (args: boolean) => void; connectingOrg: (org: GitHubInstallationType) => void; }) => { const [clickedOrg, setClickedOrg] = useState(undefined); const canConnect = (org: GitHubInstallationType) => !org.requiresSsoLogin && !org.isIPBlocked && org.isAdmin; - // TODO: Automate the login after clearing the GitHub Token + // This method clears the tokens and then re-authenticates + const resetToken = async () => { + await OauthManager.clear(); + // This resets the token validity check in the parent component and resets the UI + resetCallback(false); + // Restart the whole auth flow + await OauthManager.authenticateInGitHub(() => {}); + }; + const errorMessage = (org: GitHubInstallationType) => { if (org.requiresSsoLogin) { // TODO: Update this to support GHE @@ -66,7 +75,7 @@ const OrganizationsList = ({ Make sure you can popup(accessUrl)}>access this organization. - After confirming, please reset the token. + After confirming, please reset the token. ; } diff --git a/spa/src/pages/ConfigSteps/index.tsx b/spa/src/pages/ConfigSteps/index.tsx index fedb60627e..d47f2e8d2d 100644 --- a/spa/src/pages/ConfigSteps/index.tsx +++ b/spa/src/pages/ConfigSteps/index.tsx @@ -291,7 +291,7 @@ const ConfigSteps = () => { organizations={organizations} loaderForOrgClicked={loaderForOrgClicked} setLoaderForOrgClicked={setLoaderForOrgClicked} - clearGitHubToken={clearGitHubToken} + resetCallback={setIsLoggedIn} connectingOrg={(org) => doCreateConnection(org.id, "manual", org.account?.login)} /> }