Skip to content

Commit aadc990

Browse files
fix
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
1 parent 480b872 commit aadc990

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

  • code/extensions/che-github-authentication/src

code/extensions/che-github-authentication/src/github.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,20 @@ export class GitHubAuthProvider implements vscode.AuthenticationProvider {
216216
}
217217

218218
private async resolveToken(sortedScopes: string[]): Promise<string> {
219+
const token = await this.getTokenIfSufficient(sortedScopes);
220+
if (!token) {
221+
return await this.getDeviceAuthentication().runInteractiveFlow(sortedScopes);
222+
}
223+
return token;
224+
}
225+
226+
private async getTokenIfSufficient(sortedScopes: string[]): Promise<string | undefined> {
219227
try {
220228
const token = await this.githubService.getToken();
221229
const existingScopes = await this.githubService.getTokenScopes(token);
222230
if (!hasAllScopes(existingScopes, sortedScopes)) {
223231
this.logger.info('GitHubAuthProvider: token lacks required scopes, starting device flow');
224-
return await this.getDeviceAuthentication().runInteractiveFlow(sortedScopes);
232+
return undefined;
225233
}
226234

227235
const isDeviceAuth = await this.githubService.isDeviceAuthToken();
@@ -232,7 +240,7 @@ export class GitHubAuthProvider implements vscode.AuthenticationProvider {
232240
);
233241
if (hasExistingSession) {
234242
this.logger.info('GitHubAuthProvider: PAT session already exists for requested scopes, starting device auth flow');
235-
return await this.getDeviceAuthentication().runInteractiveFlow(sortedScopes);
243+
return undefined;
236244
}
237245
}
238246

@@ -243,7 +251,7 @@ export class GitHubAuthProvider implements vscode.AuthenticationProvider {
243251
} else {
244252
this.logger.info('GitHubAuthProvider: no token available, starting device flow');
245253
}
246-
return await this.getDeviceAuthentication().runInteractiveFlow(sortedScopes);
254+
return undefined;
247255
}
248256
}
249257

0 commit comments

Comments
 (0)