33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { authentication , env , window } from 'vscode' ;
6+ import { env , window } from 'vscode' ;
77import { TaskSingler } from '../../../util/common/taskSingler' ;
88import { ConfigKey , IConfigurationService } from '../../configuration/common/configurationService' ;
99import { ICAPIClientService } from '../../endpoint/common/capiClient' ;
@@ -16,12 +16,10 @@ import { ITelemetryService } from '../../telemetry/common/telemetry';
1616import { CopilotToken , ExtendedTokenInfo , TokenErrorNotificationId , TokenInfoOrError } from '../common/copilotToken' ;
1717import { nowSeconds } from '../common/copilotTokenManager' ;
1818import { BaseCopilotTokenManager } from '../node/copilotTokenManager' ;
19- import { authProviderId , GITHUB_SCOPE_ALIGNED } from '../common/authentication' ;
2019import { getAnyAuthSession } from './session' ;
2120
2221//Flag if we've shown message about broken oauth token.
2322let shown401Message = false ;
24- let oauthRetryAttempted = false ;
2523
2624export class NotSignedUpError extends Error { }
2725export class SubscriptionExpiredError extends Error { }
@@ -88,26 +86,9 @@ export class VSCodeCopilotTokenManager extends BaseCopilotTokenManager {
8886 this . _logService . info ( `Copilot Chat: ${ this . _envService . getVersion ( ) } , VS Code: ${ this . _envService . vscodeVersion } ` ) ;
8987 }
9088
91- if ( tokenResult . kind === 'failure' && tokenResult . reason === 'NotAuthorized' && ! tokenResult . notification_id && ! oauthRetryAttempted ) {
92- oauthRetryAttempted = true ;
93- this . _logService . info ( 'Copilot token exchange failed with the current session token, requesting a new OAuth session' ) ;
94- try {
95- const providerId = authProviderId ( this . configurationService ) ;
96- const newSession = await authentication . getSession ( providerId , GITHUB_SCOPE_ALIGNED , {
97- forceNewSession : { detail : 'Copilot requires OAuth sign-in to function. Your current workspace token cannot be used for AI features.' }
98- } ) ;
99- if ( newSession ) {
100- this . _logService . info ( `Got new OAuth session for ${ newSession . account . label } , retrying token exchange` ) ;
101- const retryResult = await this . authFromGitHubToken ( newSession . accessToken , newSession . account . label ) ;
102- if ( retryResult . kind === 'success' ) {
103- this . _logService . info ( `Got Copilot token for ${ newSession . account . label } on retry` ) ;
104- this . _logService . info ( `Copilot Chat: ${ this . _envService . getVersion ( ) } , VS Code: ${ this . _envService . vscodeVersion } ` ) ;
105- }
106- return retryResult ;
107- }
108- } catch ( e ) {
109- this . _logService . info ( `OAuth re-authentication was cancelled or failed: ${ e } ` ) ;
110- }
89+ if ( tokenResult . kind === 'failure' && tokenResult . reason === 'NotAuthorized' && ! tokenResult . notification_id ) {
90+ this . _logService . info ( 'Copilot token exchange failed (workspace token cannot be exchanged for Copilot token), triggering sign-in flow' ) ;
91+ return { kind : 'failure' , reason : 'GitHubLoginFailed' } ;
11192 }
11293
11394 return tokenResult ;
0 commit comments