Skip to content

Commit e0eb882

Browse files
Fix on Copilot side-s
1 parent 9be7f34 commit e0eb882

2 files changed

Lines changed: 5 additions & 36 deletions

File tree

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
[
2-
{
3-
"from": "import { env, window } from 'vscode';",
4-
"by": "import { authentication, env, window } from 'vscode';"
5-
},
6-
{
7-
"from": "import { getAnyAuthSession } from './session';",
8-
"by": "import { authProviderId, GITHUB_SCOPE_ALIGNED } from '../common/authentication';\nimport { getAnyAuthSession } from './session';"
9-
},
10-
{
11-
"from": "let shown401Message = false;",
12-
"by": "let shown401Message = false;\nlet oauthRetryAttempted = false;"
13-
},
142
{
153
"from": "\t\t\tif (tokenResult.kind === 'success') {\n\t\t\t\tthis._logService.info(`Got Copilot token for ${session.account.label}`);\n\t\t\t\tthis._logService.info(`Copilot Chat: ${this._envService.getVersion()}, VS Code: ${this._envService.vscodeVersion}`);\n\t\t\t}\n\t\t\treturn tokenResult;",
16-
"by": "\t\t\tif (tokenResult.kind === 'success') {\n\t\t\t\tthis._logService.info(`Got Copilot token for ${session.account.label}`);\n\t\t\t\tthis._logService.info(`Copilot Chat: ${this._envService.getVersion()}, VS Code: ${this._envService.vscodeVersion}`);\n\t\t\t}\n\n\t\t\tif (tokenResult.kind === 'failure' && tokenResult.reason === 'NotAuthorized' && !tokenResult.notification_id && !oauthRetryAttempted) {\n\t\t\t\toauthRetryAttempted = true;\n\t\t\t\tthis._logService.info('Copilot token exchange failed with the current session token, requesting a new OAuth session');\n\t\t\t\ttry {\n\t\t\t\t\tconst providerId = authProviderId(this.configurationService);\n\t\t\t\t\tconst newSession = await authentication.getSession(providerId, GITHUB_SCOPE_ALIGNED, {\n\t\t\t\t\t\tforceNewSession: { detail: 'Copilot requires OAuth sign-in to function. Your current workspace token cannot be used for AI features.' }\n\t\t\t\t\t});\n\t\t\t\t\tif (newSession) {\n\t\t\t\t\t\tthis._logService.info(`Got new OAuth session for ${newSession.account.label}, retrying token exchange`);\n\t\t\t\t\t\tconst retryResult = await this.authFromGitHubToken(newSession.accessToken, newSession.account.label);\n\t\t\t\t\t\tif (retryResult.kind === 'success') {\n\t\t\t\t\t\t\tthis._logService.info(`Got Copilot token for ${newSession.account.label} on retry`);\n\t\t\t\t\t\t\tthis._logService.info(`Copilot Chat: ${this._envService.getVersion()}, VS Code: ${this._envService.vscodeVersion}`);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn retryResult;\n\t\t\t\t\t}\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthis._logService.info(`OAuth re-authentication was cancelled or failed: ${e}`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn tokenResult;"
4+
"by": "\t\t\tif (tokenResult.kind === 'success') {\n\t\t\t\tthis._logService.info(`Got Copilot token for ${session.account.label}`);\n\t\t\t\tthis._logService.info(`Copilot Chat: ${this._envService.getVersion()}, VS Code: ${this._envService.vscodeVersion}`);\n\t\t\t}\n\n\t\t\tif (tokenResult.kind === 'failure' && tokenResult.reason === 'NotAuthorized' && !tokenResult.notification_id) {\n\t\t\t\tthis._logService.info('Copilot token exchange failed (workspace token cannot be exchanged for Copilot token), triggering sign-in flow');\n\t\t\t\treturn { kind: 'failure', reason: 'GitHubLoginFailed' };\n\t\t\t}\n\n\t\t\treturn tokenResult;"
175
}
186
]

code/extensions/copilot/src/platform/authentication/vscode-node/copilotTokenManager.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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';
77
import { TaskSingler } from '../../../util/common/taskSingler';
88
import { ConfigKey, IConfigurationService } from '../../configuration/common/configurationService';
99
import { ICAPIClientService } from '../../endpoint/common/capiClient';
@@ -16,12 +16,10 @@ import { ITelemetryService } from '../../telemetry/common/telemetry';
1616
import { CopilotToken, ExtendedTokenInfo, TokenErrorNotificationId, TokenInfoOrError } from '../common/copilotToken';
1717
import { nowSeconds } from '../common/copilotTokenManager';
1818
import { BaseCopilotTokenManager } from '../node/copilotTokenManager';
19-
import { authProviderId, GITHUB_SCOPE_ALIGNED } from '../common/authentication';
2019
import { getAnyAuthSession } from './session';
2120

2221
//Flag if we've shown message about broken oauth token.
2322
let shown401Message = false;
24-
let oauthRetryAttempted = false;
2523

2624
export class NotSignedUpError extends Error { }
2725
export 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

Comments
 (0)