Skip to content

Commit

Permalink
[signing] Sigin: Offer manual fallback in case the extension can't op…
Browse files Browse the repository at this point in the history
…en a browser (#119)

Tool: gitpod/catfood.gitpod.cloud
  • Loading branch information
geropl authored Jan 29, 2025
1 parent 08488a5 commit 2ffe187
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/authentication/gitpodServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ async function getUserInfo(token: string, serviceUrl: string, logger: ILogServic
};
}

const ACTION_COPY = 'Copy to clipboard';
const ACTION_CANCEL = 'Cancel';

export default class GitpodServer extends Disposable {

public static AUTH_COMPLETE_PATH = '/complete-gitpod-auth';
Expand Down Expand Up @@ -76,8 +79,16 @@ export default class GitpodServer extends Disposable {
location: vscode.ProgressLocation.Window,
title: `Signing in to ${this._serviceUrl}...`,
}, async () => {
await vscode.env.openExternal(uri as any);
// this._logger.trace(">> URL ", uri);
const success = await vscode.env.openExternal(uri as any);
if (!success) {
// Handle the case where the extension can't open a browser window
const action = await vscode.window.showWarningMessage('There was a problem opening the login URL in your browser. Please copy it into your browser manually.', ACTION_COPY, ACTION_CANCEL);
if (action === ACTION_COPY) {
await vscode.env.clipboard.writeText(uri);
} else if (action === ACTION_CANCEL) {
throw new Error('Signin cancelled by user');
}
}

// Register a single listener for the URI callback, in case the user starts the login process multiple times
// before completing it.
Expand Down

0 comments on commit 2ffe187

Please sign in to comment.