src/vs/platform/agentHost/node/agentHostAuthenticationService.ts
121 LOC · 111 covered · 10 uncovered · 36 ranges · 917 concepts · 16 introducers · 483 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
agentService.ts ×122
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type { ILogService } from '../../log/common/log.js';
import type { AuthenticateParams, AuthenticateResult, IAgent, IAgentHostAuthTokenRequest } from '../common/agentService.js';
interface IStoredAuthToken {
readonly resource: string;
readonly scopes: readonly string[];
readonly token: string;
}
export class AgentHostAuthenticationService {
private readonly _tokens = new Map<string, IStoredAuthToken>();
constructor(
) { }
async authenticate(params: AuthenticateParams, providers: Iterable<IAgent>): Promise<AuthenticateResult> {
this._logService.trace(`[AgentHostAuthenticationService] authenticate called: resource=${params.resource}`);
agentHostAuthenticationService.ts ×4
const providerList = [...providers];
// Multiple providers may share the same protected resource (e.g.
// both Copilot CLI and Claude consume the GitHub Copilot token).
// Fan out to every matching provider in parallel; the request is
// considered authenticated if at least one accepts. Provider
// failures are isolated -- one provider rejecting (e.g. proxy
// server bind failure) MUST NOT prevent another provider from
// accepting the same token.
const matching = providerList.filter(
p => p.getProtectedResources().some(r => r.resource === params.resource),
);
const settled = await Promise.allSettled(
matching.map(p => p.authenticate(params.resource, params.token)),
);
let authenticated = false;
for (let i = 0; i < settled.length; i++) {
if (result.status === 'fulfilled') {
result.reason,
`[AgentHostAuthenticationService] Provider '${matching[i].id}' authenticate threw for resource=${params.resource}`,
);
}
const sessionResourceHandlers = providerList.filter(p => p.handleAuthenticationToken);
agentHostAuthenticationService.ts ×4
const sessionResourceSettled = await Promise.allSettled(
sessionResourceHandlers.map(p => p.handleAuthenticationToken ? p.handleAuthenticationToken(params) : Promise.resolve(false)),
);
for (let i = 0; i < sessionResourceSettled.length; i++) {
const result = sessionResourceSettled[i];
if (result.status === 'fulfilled') {
authenticated ||= result.value;
} else {
this._logService.error(
result.reason,
`[AgentHostAuthenticationService] Provider '${sessionResourceHandlers[i].id}' handleAuthenticationToken threw for resource=${params.resource}`,
);
}
}
this._tokens.set(this._key(params.resource, scopes), { resource: params.resource, scopes, token: params.token });
}
}
getAuthToken(request: IAgentHostAuthTokenRequest): string | undefined {
const exact = this._tokens.get(this._key(request.resource, scopes));
if (exact) {
}
}
const requested = new Set(scopes);
let best: IStoredAuthToken | undefined;
for (const candidate of this._tokens.values()) {
if (candidate.resource !== request.resource || candidate.scopes.length === 0) {
agentHostAuthenticationService.ts ×3
}
continue;
}
if (!best || candidate.scopes.length < best.scopes.length) {
agentHostAuthenticationService.ts ×3
}
}
// Compatibility for clients that resolved the right token before scopes
// were forwarded through the authenticate command.
return this._tokens.get(this._key(request.resource, []))?.token;
private _containsAll(scopes: readonly string[], requested: ReadonlySet<string>): boolean {
if (!scopes.includes(scope)) {
return false;
}
}
return true;
}
private _key(resource: string, scopes: readonly string[]): string {
}
private _normalizeScopes(scopes: readonly string[] | undefined): readonly string[] {
}