diff --git a/components/dashboard/public/login-success/index.html b/components/dashboard/public/flow-result/index.html
similarity index 52%
rename from components/dashboard/public/login-success/index.html
rename to components/dashboard/public/flow-result/index.html
index 0e3dbf00f6541a..9e135a0cf822fd 100644
--- a/components/dashboard/public/login-success/index.html
+++ b/components/dashboard/public/flow-result/index.html
@@ -8,9 +8,14 @@
- Login successful
+ Done
diff --git a/components/dashboard/src/Login.tsx b/components/dashboard/src/Login.tsx
index d3926b900584c2..0efca69e5fce77 100644
--- a/components/dashboard/src/Login.tsx
+++ b/components/dashboard/src/Login.tsx
@@ -50,13 +50,12 @@ export function Login() {
const listener = (event: MessageEvent) => {
// todo: check event.origin
- if (event.data === "auth-success") {
+ if (event.data === "success") {
if (event.source && "close" in event.source && event.source.close) {
console.log(`try to close window`);
event.source.close();
- } else {
- // todo: not here, but add a button to the /login-success page to close, if this should not work as expected
}
+
(async () => {
await getGitpodService().reconnect();
setUser(await getGitpodService().server.getLoggedInUser());
@@ -139,7 +138,7 @@ export function Login() {
}
function getLoginUrl(host: string) {
- const returnTo = gitpodHostUrl.with({ pathname: 'login-success' }).toString();
+ const returnTo = gitpodHostUrl.with({ pathname: 'flow-result', search: 'message=success' }).toString();
return gitpodHostUrl.withApi({
pathname: '/login',
search: `host=${host}&returnTo=${encodeURIComponent(returnTo)}`
diff --git a/components/dashboard/src/prebuilds/InstallGitHubApp.tsx b/components/dashboard/src/prebuilds/InstallGitHubApp.tsx
index ca7ba69c517112..587defefe0762f 100644
--- a/components/dashboard/src/prebuilds/InstallGitHubApp.tsx
+++ b/components/dashboard/src/prebuilds/InstallGitHubApp.tsx
@@ -10,12 +10,13 @@ import { Deferred } from "@gitpod/gitpod-protocol/lib/util/deferred";
import { getGitpodService, gitpodHostUrl } from "../service/service";
import { useState } from "react";
import info from "../images/info.svg";
+import { openAuthorizeWindow } from "../provider-utils";
async function registerApp(installationId: string, setModal: (modal: 'done' | string | undefined) => void) {
try {
await getGitpodService().server.registerGithubApp(installationId);
- const returnTo = encodeURIComponent(gitpodHostUrl.with({ pathname: `login-success` }).toString());
+ const returnTo = encodeURIComponent(gitpodHostUrl.with({ pathname: 'flow-result', search: 'message=success' }).toString());
const url = gitpodHostUrl.withApi({
pathname: '/authorize',
search: `returnTo=${returnTo}&host=github.com&scopes=repo`
@@ -23,22 +24,19 @@ async function registerApp(installationId: string, setModal: (modal: 'done' | st
window.open(url, "gitpod-login");
const result = new Deferred(1000 * 60 * 10 /* 10 min */);
- result.promise.catch(e => setModal('error'));
- const listener = (event: MessageEvent) => {
- // todo: check event.origin
- if (event.data === "auth-success") {
- if (event.source && "close" in event.source && event.source.close) {
- console.log(`try to close window`);
- event.source.close();
- } else {
- // todo: not here, but add a button to the /login-success page to close, if this should not work as expected
- }
- window.removeEventListener("message", listener);
+
+ openAuthorizeWindow({
+ host: "github.com",
+ scopes: ["repo"],
+ onSuccess: () => {
setModal('done');
result.resolve();
+ },
+ onError: (error) => {
+ setModal(error);
}
- };
- window.addEventListener("message", listener);
+ })
+
return result.promise;
} catch (e) {
setModal(e.message);
diff --git a/components/dashboard/src/provider-utils.tsx b/components/dashboard/src/provider-utils.tsx
index c4ecbc4415cbb9..309bffe67481d4 100644
--- a/components/dashboard/src/provider-utils.tsx
+++ b/components/dashboard/src/provider-utils.tsx
@@ -36,14 +36,14 @@ function simplifyProviderName(host: string) {
}
}
-async function openAuthorizeWindow({ host, scopes, onSuccess, onError }: { host: string, scopes?: string[], onSuccess?: () => void, onError?: (error?: string) => void }) {
- const returnTo = gitpodHostUrl.with({ pathname: 'login-success' }).toString();
+async function openAuthorizeWindow({ host, scopes, onSuccess, onError }: { host: string, scopes?: string[], onSuccess?: (payload?: string) => void, onError?: (error?: string) => void }) {
+ const returnTo = gitpodHostUrl.with({ pathname: 'flow-result', search: 'message=success' }).toString();
const url = gitpodHostUrl.withApi({
pathname: '/authorize',
search: `returnTo=${encodeURIComponent(returnTo)}&host=${host}&override=true&scopes=${(scopes || []).join(',')}`
}).toString();
- const newWindow = window.open(url, "gitpod-connect");
+ const newWindow = window.open(url, "gitpod-auth-window");
if (!newWindow) {
console.log(`Failed to open the authorize window for ${host}`);
onError && onError("failed");
@@ -53,17 +53,24 @@ async function openAuthorizeWindow({ host, scopes, onSuccess, onError }: { host:
const eventListener = (event: MessageEvent) => {
// todo: check event.origin
- if (event.data === "auth-success") {
+ const killAuthWindow = () => {
window.removeEventListener("message", eventListener);
-
+
if (event.source && "close" in event.source && event.source.close) {
- console.log(`Authorization OK. Closing child window.`);
+ console.log(`Received Auth Window Result. Closing Window.`);
event.source.close();
- } else {
- // todo: add a button to the /login-success page to close, if this should not work as expected
}
+ }
+
+ if (typeof event.data === "string" && event.data.startsWith("success")) {
+ killAuthWindow();
onSuccess && onSuccess();
}
+ if (typeof event.data === "string" && event.data.startsWith("error:")) {
+ const errorText = atob(event.data.substring("error:".length));
+ killAuthWindow();
+ onError && onError(errorText);
+ }
};
window.addEventListener("message", eventListener);
}
diff --git a/components/dashboard/src/settings/Integrations.tsx b/components/dashboard/src/settings/Integrations.tsx
index f0820d7dbf0b27..ffcd32e37c272e 100644
--- a/components/dashboard/src/settings/Integrations.tsx
+++ b/components/dashboard/src/settings/Integrations.tsx
@@ -5,6 +5,7 @@
*/
import { AuthProviderEntry, AuthProviderInfo } from "@gitpod/gitpod-protocol";
+import { SelectAccountPayload } from "@gitpod/gitpod-protocol/lib/auth";
import React, { useContext, useEffect, useState } from "react";
import ContextMenu, { ContextMenuEntry } from "../components/ContextMenu";
import { getGitpodService, gitpodHostUrl } from "../service/service";
@@ -17,6 +18,7 @@ import { openAuthorizeWindow } from "../provider-utils";
import CheckBox from '../components/CheckBox';
import { PageWithSubMenu } from "../components/PageWithSubMenu";
import settingsMenu from "./settings-menu";
+import { SelectAccountModal } from "./SelectAccountModal";
export default function Integrations() {
@@ -38,6 +40,7 @@ function GitProviders() {
const [allScopes, setAllScopes] = useState