import type * as vscode from "vscode"; import { Emitter, Event } from "../../../base/common/event.js"; import { MainThreadAuthenticationShape, ExtHostAuthenticationShape } from "./extHost.protocol.js"; import { Proxied } from "../../services/extensions/common/proxyIdentifier.js"; import { Disposable } from "./extHostTypes.js"; import { IExtensionDescription } from "../../../platform/extensions/common/extensions.js"; import { IAuthenticationGetSessionsOptions, IAuthenticationProviderSessionOptions } from "../../services/authentication/common/authentication.js"; import { IExtHostRpcService } from "./extHostRpcService.js"; import { URI, UriComponents } from "../../../base/common/uri.js"; import { IAuthorizationProtectedResourceMetadata, IAuthorizationServerMetadata, IAuthorizationTokenResponse } from "../../../base/common/oauth.js"; import { IExtHostWindow } from "./extHostWindow.js"; import { IExtHostInitDataService } from "./extHostInitDataService.js"; import { ILogger } from "../../../platform/log/common/log.js"; import { ILoggerService } from "../../../platform/log/common/log.service.js"; import { ILogService } from "../../../platform/log/common/log.service.js"; import { IExtHostUrlsService } from "./extHostUrls.js"; import { IExtHostProgress } from "./extHostProgress.js"; export interface IExtHostAuthentication extends ExtHostAuthentication { } export declare const IExtHostAuthentication: import("../../../platform/instantiation/common/instantiation.js").ServiceIdentifier; /** * The account icon is a {@link vscode.Uri} that does not survive being sent over the RPC boundary, * so it needs to be revived when an account is received from the main thread. */ export declare function reviveAccountIcon(account: T): T & { readonly icon?: vscode.Uri; }; export declare class ExtHostAuthentication implements ExtHostAuthenticationShape { private readonly _initData; private readonly _extHostWindow; private readonly _extHostUrls; private readonly _extHostProgress; private readonly _extHostLoggerService; private readonly _logService; _serviceBrand: undefined; protected readonly _dynamicAuthProviderCtor: typeof DynamicAuthProvider; protected readonly _xaaAuthProviderCtor: typeof DynamicAuthProvider; private _proxy; private _authenticationProviders; private _providerOperations; private _onDidChangeSessions; private _getSessionTaskSingler; private _onDidDynamicAuthProviderTokensChange; constructor(extHostRpc: IExtHostRpcService, _initData: IExtHostInitDataService, _extHostWindow: IExtHostWindow, _extHostUrls: IExtHostUrlsService, _extHostProgress: IExtHostProgress, _extHostLoggerService: ILoggerService, _logService: ILogService); /** * This sets up an event that will fire when the auth sessions change with a built-in filter for the extensionId * if a session change only affects a specific extension. * @param extensionId The extension that is interested in the event. * @returns An event with a built-in filter for the extensionId */ getExtensionScopedSessionsEvent(extensionId: string): Event; getSession(requestingExtension: IExtensionDescription, providerId: string, scopesOrRequest: readonly string[] | vscode.AuthenticationWwwAuthenticateRequest, options: vscode.AuthenticationGetSessionOptions & ({ createIfNone: true; } | { forceNewSession: true; } | { forceNewSession: vscode.AuthenticationForceNewSessionOptions; })): Promise; getSession(requestingExtension: IExtensionDescription, providerId: string, scopesOrRequest: readonly string[] | vscode.AuthenticationWwwAuthenticateRequest, options: vscode.AuthenticationGetSessionOptions & { forceNewSession: true; }): Promise; getSession(requestingExtension: IExtensionDescription, providerId: string, scopesOrRequest: readonly string[] | vscode.AuthenticationWwwAuthenticateRequest, options: vscode.AuthenticationGetSessionOptions & { forceNewSession: vscode.AuthenticationForceNewSessionOptions; }): Promise; getSession(requestingExtension: IExtensionDescription, providerId: string, scopesOrRequest: readonly string[] | vscode.AuthenticationWwwAuthenticateRequest, options: vscode.AuthenticationGetSessionOptions): Promise; getAccounts(providerId: string): Promise<({ label: string; id: string; icon?: { scheme: string; authority?: string; path?: string; query?: string; fragment?: string; } | undefined; } & { readonly icon?: vscode.Uri; })[]>; registerAuthenticationProvider(id: string, label: string, provider: vscode.AuthenticationProvider, options?: vscode.AuthenticationProviderOptions): vscode.Disposable; $createSession(providerId: string, scopes: string[], options: vscode.AuthenticationProviderSessionOptions): Promise; $removeSession(providerId: string, sessionId: string): Promise; $getSessions(providerId: string, scopes: ReadonlyArray | undefined, options: IAuthenticationGetSessionsOptions): Promise>; $getSessionsFromChallenges(providerId: string, constraint: vscode.AuthenticationConstraint, options: vscode.AuthenticationProviderSessionOptions): Promise>; $createSessionFromChallenges(providerId: string, constraint: vscode.AuthenticationConstraint, options: vscode.AuthenticationProviderSessionOptions): Promise; $onDidChangeAuthenticationSessions(id: string, label: string, extensionIdFilter?: string[]): Promise; $onDidUnregisterAuthenticationProvider(id: string): Promise; $registerDynamicAuthProvider(authorizationServerComponents: UriComponents, serverMetadata: IAuthorizationServerMetadata, resourceMetadata: IAuthorizationProtectedResourceMetadata | undefined, clientId: string | undefined, clientSecret: string | undefined, initialTokens: IAuthorizationToken[] | undefined, providerId?: string): Promise; $registerXaaAuthProvider(issuerComponents: UriComponents, serverMetadata: IAuthorizationServerMetadata, clientId: string | undefined, clientSecret: string | undefined, initialTokens: IAuthorizationToken[] | undefined): Promise; $onDidChangeDynamicAuthProviderTokens(authProviderId: string, clientId: string, tokens: IAuthorizationToken[]): Promise; } export declare class DynamicAuthProvider implements vscode.AuthenticationProvider { protected readonly _extHostWindow: IExtHostWindow; protected readonly _extHostUrls: IExtHostUrlsService; protected readonly _initData: IExtHostInitDataService; private readonly _extHostProgress; protected readonly _proxy: Proxied; readonly authorizationServer: URI; protected readonly _serverMetadata: IAuthorizationServerMetadata; protected readonly _resourceMetadata: IAuthorizationProtectedResourceMetadata | undefined; protected _clientId: string; protected _clientSecret: string | undefined; private readonly _fetch; id: string; readonly label: string; private _onDidChangeSessions; readonly onDidChangeSessions: Event; private readonly _onDidChangeClientId; readonly onDidChangeClientId: Event; private readonly _tokenStore; protected readonly _createFlows: Array<{ label: string; handler: (scopes: string[], progress: vscode.Progress<{ message: string; }>, token: vscode.CancellationToken) => Promise; }>; protected readonly _logger: ILogger; protected readonly _isMicrosoftAuth: boolean; private readonly _disposable; constructor(_extHostWindow: IExtHostWindow, _extHostUrls: IExtHostUrlsService, _initData: IExtHostInitDataService, _extHostProgress: IExtHostProgress, loggerService: ILoggerService, _proxy: Proxied, authorizationServer: URI, _serverMetadata: IAuthorizationServerMetadata, _resourceMetadata: IAuthorizationProtectedResourceMetadata | undefined, _clientId: string, _clientSecret: string | undefined, onDidDynamicAuthProviderTokensChange: Emitter<{ authProviderId: string; clientId: string; tokens: IAuthorizationToken[]; }>, initialTokens: IAuthorizationToken[], providerId?: string, _fetch?: typeof fetch); get clientId(): string; get clientSecret(): string | undefined; /** * The RFC 8707 resource indicator to send in requests. Omitted for Microsoft auth. */ protected get _resourceIndicator(): string | undefined; /** * The scopes to send to the server, adding `offline_access` when the server advertises it. * Empty scopes are left empty so servers can still apply their default scopes. */ protected _getRequestScopes(scopes: readonly string[]): string[]; getSessions(scopes: readonly string[] | undefined, options: IAuthenticationProviderSessionOptions): Promise; createSession(scopes: string[], _options: vscode.AuthenticationProviderSessionOptions): Promise; removeSession(sessionId: string): Promise; dispose(): void; private _createWithUrlHandler; protected generateRandomString(length: number): string; protected generateCodeChallenge(codeVerifier: string): Promise; private waitForAuthorizationCode; protected exchangeCodeForToken(code: string, codeVerifier: string, redirectUri: string): Promise; protected exchangeRefreshTokenForToken(refreshToken: string, scopes: readonly string[], allowClientRegistration: boolean): Promise; protected _generateNewClientId(): Promise; } export type IAuthorizationToken = IAuthorizationTokenResponse & { /** * The time when the token was created, in milliseconds since the epoch. */ created_at: number; }; export declare class TokenStore implements Disposable { private readonly _persistence; private readonly _logger; private readonly _tokensObservable; private readonly _sessionsObservable; private readonly _onDidChangeSessions; readonly onDidChangeSessions: Event; private readonly _disposable; constructor(_persistence: { onDidChange: Event; set: (tokens: IAuthorizationToken[]) => void; }, initialTokens: IAuthorizationToken[], _logger: ILogger); get tokens(): IAuthorizationToken[]; get sessions(): vscode.AuthenticationSession[]; dispose(): void; update({ added, removed }: { added: IAuthorizationToken[]; removed: IAuthorizationToken[]; }): void; private _registerChangeEventAutorun; private _getSessionFromToken; }