File tree Expand file tree Collapse file tree
code/extensions/che-github-authentication/src Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments