Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vscode-dts/vscode.proposed.authenticationChallenges.d.ts
3290 views
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
export interface AuthenticationWWWAuthenticateRequest {
21
/**
22
* The raw WWW-Authenticate header value that triggered this challenge.
23
* This will be parsed by the authentication provider to extract the necessary
24
* challenge information.
25
*/
26
readonly wwwAuthenticate: string;
27
28
/**
29
* @deprecated Use `wwwAuthenticate` instead.
30
*/
31
readonly challenge?: string;
32
33
/**
34
* Optional scopes for the session. If not provided, the authentication provider
35
* may use default scopes or extract them from the challenge.
36
*/
37
readonly scopes?: readonly string[];
38
}
39
40
export namespace authentication {
41
/**
42
* Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not
43
* registered, or if the user does not consent to sharing authentication information with
44
* the extension. If there are multiple sessions with the same scopes, the user will be shown a
45
* quickpick to select which account they would like to use.
46
*
47
* Currently, there are only two authentication providers that are contributed from built in extensions
48
* to the editor that implement GitHub and Microsoft authentication: their providerId's are 'github' and 'microsoft'.
49
* @param providerId The id of the provider to use
50
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider
51
* @param options The {@link AuthenticationGetSessionOptions} to use
52
* @returns A thenable that resolves to an authentication session
53
*/
54
export function getSession(providerId: string, scopeListOrRequest: ReadonlyArray<string> | AuthenticationWWWAuthenticateRequest, options: AuthenticationGetSessionOptions & { /** */createIfNone: true | AuthenticationGetSessionPresentationOptions }): Thenable<AuthenticationSession>;
55
56
/**
57
* Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not
58
* registered, or if the user does not consent to sharing authentication information with
59
* the extension. If there are multiple sessions with the same scopes, the user will be shown a
60
* quickpick to select which account they would like to use.
61
*
62
* Currently, there are only two authentication providers that are contributed from built in extensions
63
* to the editor that implement GitHub and Microsoft authentication: their providerId's are 'github' and 'microsoft'.
64
* @param providerId The id of the provider to use
65
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider
66
* @param options The {@link AuthenticationGetSessionOptions} to use
67
* @returns A thenable that resolves to an authentication session
68
*/
69
export function getSession(providerId: string, scopeListOrRequest: ReadonlyArray<string> | AuthenticationWWWAuthenticateRequest, options: AuthenticationGetSessionOptions & { /** literal-type defines return type */forceNewSession: true | AuthenticationGetSessionPresentationOptions | AuthenticationForceNewSessionOptions }): Thenable<AuthenticationSession>;
70
71
/**
72
* Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not
73
* registered, or if the user does not consent to sharing authentication information with
74
* the extension. If there are multiple sessions with the same scopes, the user will be shown a
75
* quickpick to select which account they would like to use.
76
*
77
* Currently, there are only two authentication providers that are contributed from built in extensions
78
* to the editor that implement GitHub and Microsoft authentication: their providerId's are 'github' and 'microsoft'.
79
* @param providerId The id of the provider to use
80
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider
81
* @param options The {@link AuthenticationGetSessionOptions} to use
82
* @returns A thenable that resolves to an authentication session if available, or undefined if there are no sessions
83
*/
84
export function getSession(providerId: string, scopeListOrRequest: ReadonlyArray<string> | AuthenticationWWWAuthenticateRequest, options?: AuthenticationGetSessionOptions): Thenable<AuthenticationSession | undefined>;
85
}
86
87
88
/**********
89
* "Extension providing auth" API
90
* NOTE: This doesn't need to be finalized with the above
91
*******/
92
93
/**
94
* Represents an authentication challenge from a WWW-Authenticate header.
95
* This is used to handle cases where additional authentication steps are required,
96
* such as when mandatory multi-factor authentication (MFA) is enforced.
97
*/
98
export interface AuthenticationChallenge {
99
/**
100
* The authentication scheme (e.g., 'Bearer').
101
*/
102
readonly scheme: string;
103
104
/**
105
* Parameters for the authentication challenge.
106
* For Bearer challenges, this may include 'claims', 'scope', 'realm', etc.
107
*/
108
readonly params: Record<string, string>;
109
}
110
111
/**
112
* Represents constraints for authentication, including challenges and optional scopes.
113
* This is used when creating or retrieving sessions that must satisfy specific authentication
114
* requirements from WWW-Authenticate headers.
115
*/
116
export interface AuthenticationConstraint {
117
/**
118
* Array of authentication challenges parsed from WWW-Authenticate headers.
119
*/
120
readonly challenges: readonly AuthenticationChallenge[];
121
122
/**
123
* Optional scopes for the session. If not provided, the authentication provider
124
* may extract scopes from the challenges or use default scopes.
125
*/
126
readonly scopes?: readonly string[];
127
}
128
129
/**
130
* An authentication provider that supports challenge-based authentication.
131
* This extends the base AuthenticationProvider with methods to handle authentication
132
* challenges from WWW-Authenticate headers.
133
*
134
* TODO: Enforce that both of these functions should be defined by creating a new AuthenticationProviderWithChallenges interface.
135
* But this can be done later since this part doesn't need finalization.
136
*/
137
export interface AuthenticationProvider {
138
/**
139
* Get existing sessions that match the given authentication constraints.
140
*
141
* @param constraint The authentication constraint containing challenges and optional scopes
142
* @param options Options for the session request
143
* @returns A thenable that resolves to an array of existing authentication sessions
144
*/
145
getSessionsFromChallenges?(constraint: AuthenticationConstraint, options: AuthenticationProviderSessionOptions): Thenable<readonly AuthenticationSession[]>;
146
147
/**
148
* Create a new session based on authentication constraints.
149
* This is called when no existing session matches the constraint requirements.
150
*
151
* @param constraint The authentication constraint containing challenges and optional scopes
152
* @param options Options for the session creation
153
* @returns A thenable that resolves to a new authentication session
154
*/
155
createSessionFromChallenges?(constraint: AuthenticationConstraint, options: AuthenticationProviderSessionOptions): Thenable<AuthenticationSession>;
156
}
157
158
export interface AuthenticationProviderOptions {
159
supportsChallenges?: boolean;
160
}
161
}
162
163