Skip to content

Commit 4e15a24

Browse files
author
Rachel Macfarlane
committed
Support directly entering PAT for github auth as well as entering url
1 parent d318d06 commit 4e15a24

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

extensions/github-authentication/src/githubServer.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class UriEventHandler extends vscode.EventEmitter<vscode.Uri> implements vscode.
2323

2424
export const uriHandler = new UriEventHandler;
2525

26+
const onDidManuallyProvideToken = new vscode.EventEmitter<string>();
27+
2628
const exchangeCodeForToken: (state: string) => PromiseAdapter<vscode.Uri, string> =
2729
(state) => async (uri, resolve, reject) => {
2830
Logger.info('Exchanging code for token...');
@@ -84,7 +86,10 @@ export class GitHubServer {
8486

8587
vscode.env.openExternal(uri);
8688

87-
return promiseFromEvent(uriHandler.event, exchangeCodeForToken(state)).finally(() => {
89+
return Promise.race([
90+
promiseFromEvent(uriHandler.event, exchangeCodeForToken(state)),
91+
promiseFromEvent<string, string>(onDidManuallyProvideToken.event)
92+
]).finally(() => {
8893
this.updateStatusBarItem(false);
8994
});
9095
}
@@ -111,8 +116,9 @@ export class GitHubServer {
111116
if (!uri.scheme || uri.scheme === 'file') { throw new Error; }
112117
uriHandler.handleUri(uri);
113118
} catch (e) {
114-
Logger.error(e);
115-
vscode.window.showErrorMessage(localize('unexpectedInput', "The input did not matched the expected format"));
119+
// If it doesn't look like a URI, treat it as a token.
120+
Logger.info('Treating input as token');
121+
onDidManuallyProvideToken.fire(uriOrToken);
116122
}
117123
}
118124

0 commit comments

Comments
 (0)