import { Event } from "../../../../base/common/event.js"; import { IAuthenticationChallenge, IAuthorizationProtectedResourceMetadata, IAuthorizationServerMetadata } from "../../../../base/common/oauth.js"; import { URI } from "../../../../base/common/uri.js"; /** * Use this if you don't want the onDidChangeSessions event to fire in the extension host */ export declare const INTERNAL_AUTH_PROVIDER_PREFIX = "__"; /** * Setting that controls whether the profile image (avatar) of a signed-in account * is shown in account related UI. */ export declare const ACCOUNTS_AVATAR_SETTING = "workbench.accounts.showAvatar"; export interface AuthenticationSessionAccount { label: string; id: string; /** * An optional icon for the account. This is typically a URI to a profile image/avatar. */ icon?: URI; } export interface AuthenticationSession { id: string; accessToken: string; account: AuthenticationSessionAccount; scopes: ReadonlyArray; idToken?: string; expiresAfter?: number; /** The issuing OAuth server, not a REST API endpoint or resource audience. */ readonly authorizationServer?: URI; } export interface AuthenticationSessionsChangeEvent { added: ReadonlyArray | undefined; removed: ReadonlyArray | undefined; changed: ReadonlyArray | undefined; } export interface AuthenticationProviderInformation { id: string; label: string; authorizationServerGlobs?: ReadonlyArray; } /** * Options for creating an authentication session via the service. */ export interface IAuthenticationCreateSessionOptions extends IAuthenticationProviderSessionOptions { activateImmediate?: boolean; } export interface IAuthenticationWwwAuthenticateRequest { /** * The raw WWW-Authenticate header value that triggered this challenge. * This will be parsed by the authentication provider to extract the necessary * challenge information. */ readonly wwwAuthenticate: string; /** * Optional scopes for the session. If not provided, the authentication provider * may use default scopes or extract them from the challenge. */ readonly fallbackScopes?: readonly string[]; } export declare function isAuthenticationWwwAuthenticateRequest(obj: unknown): obj is IAuthenticationWwwAuthenticateRequest; /** * Represents constraints for authentication, including challenges and optional scopes. * This is used when creating or retrieving sessions that must satisfy specific authentication * requirements from WWW-Authenticate headers. */ export interface IAuthenticationConstraint { /** * Array of authentication challenges parsed from WWW-Authenticate headers. */ readonly challenges: readonly IAuthenticationChallenge[]; /** * Optional scopes for the session. If not provided, the authentication provider * may extract scopes from the challenges or use default scopes. */ readonly fallbackScopes?: readonly string[]; } /** * Options for getting authentication sessions via the service. */ export type IAuthenticationGetSessionsOptions = IAuthenticationProviderSessionOptions; export interface AllowedExtension { id: string; name: string; /** * If true or undefined, the extension is allowed to use the account * If false, the extension is not allowed to use the account * TODO: undefined shouldn't be a valid value, but it is for now */ allowed?: boolean; lastUsed?: number; trusted?: boolean; } export interface IAuthenticationProviderHostDelegate { /** Priority for this delegate, delegates are tested in descending priority order */ readonly priority: number; create(authorizationServer: URI, serverMetadata: IAuthorizationServerMetadata, resource: IAuthorizationProtectedResourceMetadata | undefined, clientId?: string, clientSecret?: string, providerId?: string): Promise; /** * Creates an XAA (enterprise-managed, ID-JAG) authentication provider for the given SSO issuer. * The returned string is the provider id. */ createXaa?(issuer: URI): Promise; } export declare function getDynamicAuthenticationProviderId(authorizationServer: URI, resource: IAuthorizationProtectedResourceMetadata | undefined): string; export declare function isAuthenticationSession(thing: unknown): thing is AuthenticationSession; /** * Options passed to the authentication provider when asking for sessions. */ export interface IAuthenticationProviderSessionOptions { /** * Whether the provider must avoid user interaction while resolving existing sessions. */ silent?: boolean; /** * The account that is being asked about. If this is passed in, the provider should * attempt to return the sessions that are only related to this account. */ account?: AuthenticationSessionAccount; /** * The authorization server that is being asked about. If this is passed in, the provider should * attempt to return sessions that are only related to this authorization server. */ authorizationServer?: URI; /** * The OAuth client identifier to use instead of the provider's default client. */ clientId?: string; /** * When specified, the authentication provider will request a token bound to this resource URI * (RFC 8707 resource indicator). */ resource?: string; /** * The audience for the requested access token. Primarily used for OAuth Identity Assertion * Authorization Grant (ID-JAG, defined in `draft-ietf-oauth-identity-assertion-authz-grant` using RFC 8693 token-exchange semantics) flows where the audience identifies the authorization server of the resource that * will redeem the assertion (typically the resource's authorization server URL). Providers that do not understand audience-bound tokens should * ignore this option. */ audience?: string; /** * Allows the authentication provider to take in additional parameters. * It is up to the provider to define what these parameters are and handle them. * This is useful for passing in additional information that is specific to the provider * and not part of the standard authentication flow. */ [key: string]: any; } /** * Prefix for {@link IAuthenticationProviderSessionOptions} keys that only the workbench may set. * Keys with this prefix are removed from every extension's request before it reaches a provider, * so a provider that receives one knows the workbench itself made the request. */ export declare const WORKBENCH_ONLY_SESSION_OPTION_PREFIX = "_workbench"; /** Returns a copy of `options` without the keys reserved for the workbench. */ export declare function withoutWorkbenchOnlySessionOptions(options: T): T; /** Builds a value-sensitive request key without splitting opaque provider scope strings. */ export declare function getAuthenticationSessionRequestKey(scopeListOrRequest: readonly string[] | IAuthenticationWwwAuthenticateRequest, options?: IAuthenticationProviderSessionOptions): string; /** * Represents an authentication provider. */ export interface IAuthenticationProvider { /** * The unique identifier of the authentication provider. */ readonly id: string; /** * The display label of the authentication provider. */ readonly label: string; /** * The resource server URI that this provider is responsible for, if any. * TODO@TylerLeonhardt: Rather than this being added to the provider, it should be passed in to * getSessions/createSession/etc... this way we can have providers that handle multiple resource servers. */ readonly resourceServer?: URI; /** * The resolved authorization servers. These can still contain globs, but should be concrete URIs */ readonly authorizationServers?: ReadonlyArray; /** * Indicates whether the authentication provider supports multiple accounts. */ readonly supportsMultipleAccounts: boolean; /** * Optional function to provide a custom confirmation message for authentication prompts. * If not implemented, the default confirmation messages will be used. * @param extensionName - The name of the extension requesting authentication. * @param recreatingSession - Whether this is recreating an existing session. * @returns A custom confirmation message or undefined to use the default message. */ readonly confirmation?: (extensionName: string, recreatingSession: boolean) => string | undefined; /** * An {@link Event} which fires when the array of sessions has changed, or data * within a session has changed. */ readonly onDidChangeSessions: Event; /** * Retrieves a list of authentication sessions. * @param scopes - An optional list of scopes. If provided, the sessions returned should match these permissions, otherwise all sessions should be returned. * @param options - Additional options for getting sessions. * @returns A promise that resolves to an array of authentication sessions. */ getSessions(scopes: string[] | undefined, options: IAuthenticationProviderSessionOptions): Promise; /** * Prompts the user to log in. * If login is successful, the `onDidChangeSessions` event should be fired. * If login fails, a rejected promise should be returned. * If the provider does not support multiple accounts, this method should not be called if there is already an existing session matching the provided scopes. * @param scopes - A list of scopes that the new session should be created with. * @param options - Additional options for creating the session. * @returns A promise that resolves to an authentication session. */ createSession(scopes: string[], options: IAuthenticationProviderSessionOptions): Promise; /** * Get existing sessions that match the given authentication constraints. * * @param constraint The authentication constraint containing challenges and optional scopes * @param options Options for the session request * @returns A thenable that resolves to an array of existing authentication sessions */ getSessionsFromChallenges?(constraint: IAuthenticationConstraint, options: IAuthenticationProviderSessionOptions): Promise; /** * Create a new session based on authentication constraints. * This is called when no existing session matches the constraint requirements. * * @param constraint The authentication constraint containing challenges and optional scopes * @param options Options for the session creation * @returns A thenable that resolves to a new authentication session */ createSessionFromChallenges?(constraint: IAuthenticationConstraint, options: IAuthenticationProviderSessionOptions): Promise; /** * Removes the session corresponding to the specified session ID. * If the removal is successful, the `onDidChangeSessions` event should be fired. * If a session cannot be removed, the provider should reject with an error message. * @param sessionId - The ID of the session to remove. */ removeSession(sessionId: string): Promise; }