|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +declare module 'vscode' { |
| 7 | + |
| 8 | + // https://github.com/microsoft/vscode/issues/260156 |
| 9 | + |
| 10 | + /********** |
| 11 | + * "Extension asking for auth" API |
| 12 | + *******/ |
| 13 | + |
| 14 | + /** |
| 15 | + * Represents parameters for creating a session based on a WWW-Authenticate header value. |
| 16 | + * This is used when an API returns a 401 with a WWW-Authenticate header indicating |
| 17 | + * that additional authentication is required. The details of which will be passed down |
| 18 | + * to the authentication provider to create a session. |
| 19 | + * |
| 20 | + * @note The authorization provider must support handling challenges and specifically |
| 21 | + * the challenges in this WWW-Authenticate value. |
| 22 | + * @note For more information on WWW-Authenticate please see https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/WWW-Authenticate |
| 23 | + */ |
| 24 | + export interface AuthenticationWwwAuthenticateRequest { |
| 25 | + /** |
| 26 | + * The raw WWW-Authenticate header value that triggered this challenge. |
| 27 | + * This will be parsed by the authentication provider to extract the necessary |
| 28 | + * challenge information. |
| 29 | + */ |
| 30 | + readonly wwwAuthenticate: string; |
| 31 | + |
| 32 | + /** |
| 33 | + * The fallback scopes to use if no scopes are found in the WWW-Authenticate header. |
| 34 | + */ |
| 35 | + readonly fallbackScopes?: readonly string[]; |
| 36 | + |
| 37 | + /** |
| 38 | + * @deprecated Use `fallbackScopes` instead. |
| 39 | + */ |
| 40 | + readonly scopes?: readonly string[]; |
| 41 | + } |
| 42 | + |
| 43 | + export namespace authentication { |
| 44 | + /** |
| 45 | + * Get an authentication session matching the desired scopes or satisfying the WWW-Authenticate request. Rejects if |
| 46 | + * a provider with providerId is not registered, or if the user does not consent to sharing authentication information |
| 47 | + * with the extension. If there are multiple sessions with the same scopes, the user will be shown a quickpick to |
| 48 | + * select which account they would like to use. |
| 49 | + * |
| 50 | + * Built-in auth providers include: |
| 51 | + * * 'github' - For GitHub.com |
| 52 | + * * 'microsoft' For both personal & organizational Microsoft accounts |
| 53 | + * * (less common) 'github-enterprise' - for alternative GitHub hostings, GHE.com, GitHub Enterprise Server |
| 54 | + * * (less common) 'microsoft-sovereign-cloud' - for alternative Microsoft clouds |
| 55 | + * |
| 56 | + * @param providerId The id of the provider to use |
| 57 | + * @param scopeListOrRequest A scope list of permissions requested or a WWW-Authenticate request. These are dependent on the authentication provider. |
| 58 | + * @param options The {@link AuthenticationGetSessionOptions} to use |
| 59 | + * @returns A thenable that resolves to an authentication session |
| 60 | + */ |
| 61 | + export function getSession(providerId: string, scopeListOrRequest: ReadonlyArray<string> | AuthenticationWwwAuthenticateRequest, options: AuthenticationGetSessionOptions & { /** */createIfNone: true | AuthenticationGetSessionPresentationOptions }): Thenable<AuthenticationSession>; |
| 62 | + |
| 63 | + /** |
| 64 | + * Get an authentication session matching the desired scopes or request. Rejects if a provider with providerId is not |
| 65 | + * registered, or if the user does not consent to sharing authentication information with the extension. If there |
| 66 | + * are multiple sessions with the same scopes, the user will be shown a quickpick to select which account they would like to use. |
| 67 | + * |
| 68 | + * Built-in auth providers include: |
| 69 | + * * 'github' - For GitHub.com |
| 70 | + * * 'microsoft' For both personal & organizational Microsoft accounts |
| 71 | + * * (less common) 'github-enterprise' - for alternative GitHub hostings, GHE.com, GitHub Enterprise Server |
| 72 | + * * (less common) 'microsoft-sovereign-cloud' - for alternative Microsoft clouds |
| 73 | + * |
| 74 | + * @param providerId The id of the provider to use |
| 75 | + * @param scopeListOrRequest A scope list of permissions requested or a WWW-Authenticate request. These are dependent on the authentication provider. |
| 76 | + * @param options The {@link AuthenticationGetSessionOptions} to use |
| 77 | + * @returns A thenable that resolves to an authentication session |
| 78 | + */ |
| 79 | + export function getSession(providerId: string, scopeListOrRequest: ReadonlyArray<string> | AuthenticationWwwAuthenticateRequest, options: AuthenticationGetSessionOptions & { /** literal-type defines return type */forceNewSession: true | AuthenticationGetSessionPresentationOptions | AuthenticationForceNewSessionOptions }): Thenable<AuthenticationSession>; |
| 80 | + |
| 81 | + /** |
| 82 | + * Get an authentication session matching the desired scopes or request. Rejects if a provider with providerId is not |
| 83 | + * registered, or if the user does not consent to sharing authentication information with the extension. If there |
| 84 | + * are multiple sessions with the same scopes, the user will be shown a quickpick to select which account they would like to use. |
| 85 | + * |
| 86 | + * Built-in auth providers include: |
| 87 | + * * 'github' - For GitHub.com |
| 88 | + * * 'microsoft' For both personal & organizational Microsoft accounts |
| 89 | + * * (less common) 'github-enterprise' - for alternative GitHub hostings, GHE.com, GitHub Enterprise Server |
| 90 | + * * (less common) 'microsoft-sovereign-cloud' - for alternative Microsoft clouds |
| 91 | + * |
| 92 | + * @param providerId The id of the provider to use |
| 93 | + * @param scopeListOrRequest A scope list of permissions requested or a WWW-Authenticate request. These are dependent on the authentication provider. |
| 94 | + * @param options The {@link AuthenticationGetSessionOptions} to use |
| 95 | + * @returns A thenable that resolves to an authentication session or undefined if a silent flow was used and no session was found |
| 96 | + */ |
| 97 | + export function getSession(providerId: string, scopeListOrRequest: ReadonlyArray<string> | AuthenticationWwwAuthenticateRequest, options?: AuthenticationGetSessionOptions): Thenable<AuthenticationSession | undefined>; |
| 98 | + } |
| 99 | + |
| 100 | + |
| 101 | + /********** |
| 102 | + * "Extension providing auth" API |
| 103 | + * NOTE: This doesn't need to be finalized with the above |
| 104 | + *******/ |
| 105 | + |
| 106 | + /** |
| 107 | + * Represents an authentication challenge from a WWW-Authenticate header. |
| 108 | + * This is used to handle cases where additional authentication steps are required, |
| 109 | + * such as when mandatory multi-factor authentication (MFA) is enforced. |
| 110 | + * |
| 111 | + * @note For more information on WWW-Authenticate please see https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/WWW-Authenticate |
| 112 | + */ |
| 113 | + export interface AuthenticationChallenge { |
| 114 | + /** |
| 115 | + * The authentication scheme (e.g., 'Bearer'). |
| 116 | + */ |
| 117 | + readonly scheme: string; |
| 118 | + |
| 119 | + /** |
| 120 | + * Parameters for the authentication challenge. |
| 121 | + * For Bearer challenges, this may include 'claims', 'scope', 'realm', etc. |
| 122 | + */ |
| 123 | + readonly params: Record<string, string>; |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Represents constraints for authentication, including challenges and optional scopes. |
| 128 | + * This is used when creating or retrieving sessions that must satisfy specific authentication |
| 129 | + * requirements from WWW-Authenticate headers. |
| 130 | + * |
| 131 | + * @note For more information on WWW-Authenticate please see https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/WWW-Authenticate |
| 132 | + */ |
| 133 | + export interface AuthenticationConstraint { |
| 134 | + /** |
| 135 | + * Array of authentication challenges parsed from WWW-Authenticate headers. |
| 136 | + */ |
| 137 | + readonly challenges: readonly AuthenticationChallenge[]; |
| 138 | + |
| 139 | + /** |
| 140 | + * Optional scopes for the session. If not provided, the authentication provider |
| 141 | + * may extract scopes from the challenges or use default scopes. |
| 142 | + */ |
| 143 | + readonly fallbackScopes?: readonly string[]; |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * An authentication provider that supports challenge-based authentication. |
| 148 | + * This extends the base AuthenticationProvider with methods to handle authentication |
| 149 | + * challenges from WWW-Authenticate headers. |
| 150 | + * |
| 151 | + * TODO: Enforce that both of these functions should be defined by creating a new AuthenticationProviderWithChallenges interface. |
| 152 | + * But this can be done later since this part doesn't need finalization. |
| 153 | + */ |
| 154 | + export interface AuthenticationProvider { |
| 155 | + /** |
| 156 | + * Get existing sessions that match the given authentication constraints. |
| 157 | + * |
| 158 | + * @param constraint The authentication constraint containing challenges and optional scopes |
| 159 | + * @param options Options for the session request |
| 160 | + * @returns A thenable that resolves to an array of existing authentication sessions |
| 161 | + */ |
| 162 | + getSessionsFromChallenges?(constraint: AuthenticationConstraint, options: AuthenticationProviderSessionOptions): Thenable<readonly AuthenticationSession[]>; |
| 163 | + |
| 164 | + /** |
| 165 | + * Create a new session based on authentication constraints. |
| 166 | + * This is called when no existing session matches the constraint requirements. |
| 167 | + * |
| 168 | + * @param constraint The authentication constraint containing challenges and optional scopes |
| 169 | + * @param options Options for the session creation |
| 170 | + * @returns A thenable that resolves to a new authentication session |
| 171 | + */ |
| 172 | + createSessionFromChallenges?(constraint: AuthenticationConstraint, options: AuthenticationProviderSessionOptions): Thenable<AuthenticationSession>; |
| 173 | + } |
| 174 | + |
| 175 | + export interface AuthenticationProviderOptions { |
| 176 | + supportsChallenges?: boolean; |
| 177 | + } |
| 178 | +} |
0 commit comments