Skip to content

Commit 25e3680

Browse files
authored
Unable to authenticate using Github Enterprise (#6644)
Fixes #6426
1 parent c506da9 commit 25e3680

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,7 @@
15801580
},
15811581
{
15821582
"view": "github:login",
1583-
"when": "ReposManagerStateContext == NeedsAuthentication && !github:hasGitHubRemotes && gitOpenRepositoryCount",
1583+
"when": "(ReposManagerStateContext == NeedsAuthentication) && ((!github:hasGitHubRemotes && gitOpenRepositoryCount) || config.github-enterprise.uri)",
15841584
"contents": "%welcome.github.loginWithEnterprise.contents%"
15851585
},
15861586
{

src/github/credentials.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { AuthProvider } from '../common/authentication';
1313
import { Disposable } from '../common/lifecycle';
1414
import Logger from '../common/logger';
1515
import * as PersistentState from '../common/persistentState';
16+
import { GITHUB_ENTERPRISE, URI } from '../common/settingKeys';
1617
import { ITelemetry } from '../common/telemetry';
1718
import { agent } from '../env/node/net';
1819
import { IAccount } from './interface';
@@ -213,8 +214,18 @@ export class CredentialStore extends Disposable {
213214
private async doCreate(options: vscode.AuthenticationGetSessionOptions, additionalScopes: boolean = false): Promise<AuthResult> {
214215
const github = await this.initialize(AuthProvider.github, options, additionalScopes ? SCOPES_WITH_ADDITIONAL : undefined, additionalScopes);
215216
let enterprise: AuthResult | undefined;
217+
const initializeEnterprise = () => this.initialize(AuthProvider.githubEnterprise, options, additionalScopes ? SCOPES_WITH_ADDITIONAL : undefined, additionalScopes);
216218
if (hasEnterpriseUri()) {
217-
enterprise = await this.initialize(AuthProvider.githubEnterprise, options, additionalScopes ? SCOPES_WITH_ADDITIONAL : undefined, additionalScopes);
219+
enterprise = await initializeEnterprise();
220+
} else {
221+
// Listen for changes to the enterprise URI and try again if it changes.
222+
const disposable = vscode.workspace.onDidChangeConfiguration(async e => {
223+
if (e.affectsConfiguration(`${GITHUB_ENTERPRISE}.${URI}`) && hasEnterpriseUri()) {
224+
enterprise = await initializeEnterprise();
225+
disposable.dispose();
226+
}
227+
});
228+
this.context.subscriptions.push(disposable);
218229
}
219230
return {
220231
canceled: github.canceled || !!(enterprise && enterprise.canceled)

0 commit comments

Comments
 (0)