Skip to content

Commit

Permalink
SSO Login fixes - Manual clicking replaced by automation (#2340)
Browse files Browse the repository at this point in the history
- Manual clicking replaced by automation
  • Loading branch information
krazziekay authored Aug 14, 2023
1 parent 28bdf07 commit 266b322
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions spa/src/pages/ConfigSteps/OrgsContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,20 +43,28 @@ const OrganizationsList = ({
organizations,
loaderForOrgClicked,
setLoaderForOrgClicked,
clearGitHubToken,
resetCallback,
connectingOrg,
}: {
organizations: Array<GitHubInstallationType>;
// 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<GitHubInstallationType | undefined>(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
Expand All @@ -66,7 +75,7 @@ const OrganizationsList = ({
Make sure you can <StyledLink onClick={() => popup(accessUrl)}>access this organization</StyledLink>.
</Paragraph>
<Paragraph>
After confirming, please <StyledLink onClick={clearGitHubToken}>reset the token</StyledLink>.
After confirming, please <StyledLink onClick={resetToken}>reset the token</StyledLink>.
</Paragraph>
</>;
}
Expand Down
2 changes: 1 addition & 1 deletion spa/src/pages/ConfigSteps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)} />
}
<AddOrganizationContainer>
Expand Down

0 comments on commit 266b322

Please sign in to comment.