@@ -25,7 +25,7 @@ export declare namespace apiUtils {
2525 */
2626 export function getAzureExtensionApi < T extends AzureExtensionApi > ( context : vscode . ExtensionContext , extensionId : string , apiVersionRange : string , options ?: GetApiOptions ) : Promise < T > ;
2727 /**
28- * Get extension exports for the extension with the given id. Activates extension first if needed .
28+ * Activates an extension and returns its exports .
2929 *
3030 * @returns `undefined` if the extension is not installed
3131 */
@@ -124,19 +124,28 @@ export declare interface AzureAuthentication {
124124 /**
125125 * Gets a VS Code authentication session for an Azure subscription.
126126 *
127- * @param scopes - The scopes for which the authentication is needed. Use AuthenticationWwwAuthenticateRequest for supporting challenge requests.
128- * Note: use of AuthenticationWwwAuthenticateRequest requires VS Code v1.104
127+ * @param scopeListOrRequest - The scopes for which the authentication is needed. Use AuthenticationWwwAuthenticateRequest for supporting challenge requests.
128+ * Note: use of AuthenticationWwwAuthenticateRequest requires VS Code v1.105.0
129129 *
130130 * @returns A VS Code authentication session or undefined, if none could be obtained.
131131 */
132- getSessionWithScopes ( scopes : string [ ] | vscode . AuthenticationWwwAuthenticateRequest ) : vscode . ProviderResult < vscode . AuthenticationSession > ;
132+ getSessionWithScopes ( scopeListOrRequest : string [ ] | vscode . AuthenticationWwwAuthenticateRequest ) : vscode . ProviderResult < vscode . AuthenticationSession > ;
133133}
134134
135135export declare interface AzureExtensionApi {
136136 /**
137137 * The API version for this extension. It should be versioned separately from the extension and ideally remains backwards compatible.
138138 */
139139 apiVersion : string ;
140+ /**
141+ * Optional endpoint which Azure client extensions should implement in order to receive an Azure Resources API session.
142+ * See: https://github.com/microsoft/vscode-azureresourcegroups/blob/main/api/src/auth/README.md
143+ *
144+ * @param azureResourcesCredential - The credential to use when requesting the Azure Resources API
145+ * @param clientCredential - The client verification credential initially generated by the client and passed to the Azure Resources API when requesting a new session.
146+ * This credential is used to verify that the real Azure Resources extension is the one providing back the session credential.
147+ */
148+ receiveAzureResourcesApiSession ?( azureResourcesCredential : string , clientCredential : string ) : void | Promise < void > ;
140149}
141150
142151/**
@@ -202,13 +211,101 @@ export declare interface AzureResourceModel extends ResourceModelBase {
202211 readonly viewProperties ?: ViewPropertiesModel ;
203212}
204213
214+ export declare interface AzureResourcesApiRequestContext {
215+ clientExtensionId : string ;
216+ azureResourcesApiVersions : string [ ] ;
217+ /**
218+ * Callback invoked when Azure Resource APIs are successfully obtained through the authentication handshake.
219+ *
220+ * @param azureResourcesApis - Array of APIs corresponding to the requested versions. APIs are returned in the same
221+ * order as provided in this request context. If a requested version is not
222+ * available or does not match, `undefined` will be returned at that position.
223+ */
224+ onDidReceiveAzureResourcesApis : ( azureResourcesApis : ( AzureResourcesExtensionApi | AzureExtensionApi | undefined ) [ ] ) => void | Promise < void > ;
225+ /**
226+ * Optional callback invoked when an error occurs during the Azure Resources API handshake process.
227+ *
228+ * @param error - The error that occurred during the handshake, containing an error code and message.
229+ */
230+ onApiRequestError ?: ( error : AzureResourcesApiRequestError ) => void | Promise < void > ;
231+ }
232+
233+ export declare type AzureResourcesApiRequestError = Omit < typeof AzureResourcesApiRequestErrors [ keyof typeof AzureResourcesApiRequestErrors ] , 'message' > & {
234+ message : string ;
235+ } ;
236+
237+ /**
238+ * List of errors that could occur during the authentication handshake between client extension and Azure Resources host extension.
239+ */
240+ export declare const AzureResourcesApiRequestErrors : {
241+ /**
242+ * An error occurred while the client extension was creating its verification credential for the Azure Resources host extension.
243+ */
244+ readonly CLIENT_FAILED_CREATE_CREDENTIAL : {
245+ readonly code : "ERR_CLIENT_FAILED_CREATE_CREDENTIAL" ;
246+ } ;
247+ /**
248+ * An error occurred while the Azure Resources host extension was trying to create an API session.
249+ */
250+ readonly HOST_CREATE_SESSION_FAILED : {
251+ readonly code : "ERR_HOST_CREATE_SESSION_FAILED" ;
252+ } ;
253+ /**
254+ * An error occurred because the client's receiver method was provided incomplete or missing credentials.
255+ */
256+ readonly CLIENT_RECEIVED_INSUFFICIENT_CREDENTIALS : {
257+ readonly code : "ERR_CLIENT_RECEIVED_INSUFFICIENT_CREDENTIALS" ;
258+ readonly message : "Insufficient credentials were provided back to the client." ;
259+ } ;
260+ /**
261+ * The client's receiver method was provided a client credential that failed verification.
262+ *
263+ * This may occur when:
264+ * - An untrusted extension pretends to be the Azure Resources host extension and tries to pass a fake credential
265+ * - There is a faulty behavior in the client's verification process
266+ */
267+ readonly CLIENT_CREDENTIAL_FAILED_VERIFICATION : {
268+ readonly code : "ERR_CLIENT_CREDENTIAL_FAILED_VERIFICATION" ;
269+ } ;
270+ /**
271+ * An error occurred while asking the Azure Resources host extension to provision the specified APIs.
272+ *
273+ * This may occur when:
274+ * - The Azure Resources extension cannot verify the issued credential that was passed back
275+ * - The requesting extension is not on the Azure Resources allow list
276+ * - The host extension encounters an internal error during API provisioning
277+ */
278+ readonly HOST_API_PROVISIONING_FAILED : {
279+ readonly code : "ERR_HOST_API_PROVISIONING_FAILED" ;
280+ } ;
281+ } ;
282+
283+ export declare type AzureResourcesApiRequestPrep < T extends AzureExtensionApi > = {
284+ /**
285+ * The modified client extension API. Ensures the required handshake receiver method has been added.
286+ */
287+ clientApi : T & Required < Pick < T , 'receiveAzureResourcesApiSession' > > ;
288+ /**
289+ * Initiates the authentication handshake required to obtain the Azure Resources API.
290+ */
291+ requestResourcesApis : ( ) => void ;
292+ } ;
293+
205294/**
206295 * The current (v2) Azure Resources extension API.
207296 */
208297export declare interface AzureResourcesExtensionApi extends AzureExtensionApi {
209298 resources : ResourcesApi ;
210299}
211300
301+ /**
302+ * The authentication layer (v4) protecting the core Azure Resources extension API.
303+ */
304+ export declare interface AzureResourcesExtensionAuthApi extends AzureExtensionApi {
305+ getAzureResourcesApi ( clientExtensionId : string , azureResourcesCredential : string , azureResourcesApiVersions : string [ ] ) : Promise < ( AzureExtensionApi | undefined ) [ ] > ;
306+ createAzureResourcesApiSession ( clientExtensionId : string , clientExtensionVersion : string , clientExtensionCredential : string ) : Promise < void > ;
307+ }
308+
212309/**
213310 * Represents a type of resource as designated by Azure.
214311 */
@@ -300,10 +397,23 @@ export declare function getAzExtResourceType(resource: {
300397 kind ?: string ;
301398} ) : AzExtResourceType | undefined ;
302399
400+ /**
401+ * @deprecated The Azure Resources core API should be accessed through the new auth layer.
402+ * See: https://github.com/microsoft/vscode-azureresourcegroups/blob/main/api/src/auth/README.md
403+ * */
303404export declare function getAzureResourcesExtensionApi ( extensionContext : vscode . ExtensionContext , apiVersionRange : '2.0.0' , options ?: GetApiOptions ) : Promise < AzureResourcesExtensionApi > ;
304405
305406export declare function isWrapper ( maybeWrapper : unknown ) : maybeWrapper is Wrapper ;
306407
408+ /**
409+ * Prepares a client extension for the Azure Resources authentication handshake.
410+ *
411+ * @param context - Prerequisite configuration and handlers to prepare the request
412+ * @param clientExtensionApi - The base extension API to be modified
413+ * @returns The modified client extension API (with the required receiver method added), and a method to initiate the handshake
414+ */
415+ export declare function prepareAzureResourcesApiRequest < T extends AzureExtensionApi > ( context : AzureResourcesApiRequestContext , clientExtensionApi : T ) : AzureResourcesApiRequestPrep < T > ;
416+
307417/**
308418 * Represents the base type for all Azure and workspace resources.
309419 */
@@ -495,4 +605,4 @@ export declare interface Wrapper {
495605 unwrap < T > ( ) : T ;
496606}
497607
498- export { } ;
608+ export { }
0 commit comments