@caido/server-auth 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +400 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +273 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +273 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +393 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +36 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Represents an authentication request from the device code flow.
|
|
4
|
+
* Contains the information needed for the user to authorize the device.
|
|
5
|
+
*/
|
|
6
|
+
interface AuthenticationRequest {
|
|
7
|
+
/** Unique identifier for this authentication request */
|
|
8
|
+
id: string;
|
|
9
|
+
/** The code the user must enter to authorize */
|
|
10
|
+
userCode: string;
|
|
11
|
+
/** The URL where the user should go to authorize */
|
|
12
|
+
verificationUrl: string;
|
|
13
|
+
/** When this request expires */
|
|
14
|
+
expiresAt: Date;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Represents an authentication token obtained after successful authorization.
|
|
18
|
+
*/
|
|
19
|
+
interface AuthenticationToken {
|
|
20
|
+
/** The access token for API requests */
|
|
21
|
+
accessToken: string;
|
|
22
|
+
/** The refresh token to obtain new access tokens */
|
|
23
|
+
refreshToken: string;
|
|
24
|
+
/** When the access token expires */
|
|
25
|
+
expiresAt: Date;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Scope information returned from device information endpoint.
|
|
29
|
+
*/
|
|
30
|
+
interface DeviceScope {
|
|
31
|
+
/** The scope identifier */
|
|
32
|
+
name: string;
|
|
33
|
+
/** Human-readable description of the scope */
|
|
34
|
+
description?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Device information response from the API.
|
|
38
|
+
*/
|
|
39
|
+
interface DeviceInformation {
|
|
40
|
+
/** The user code associated with this device request */
|
|
41
|
+
userCode: string;
|
|
42
|
+
/** List of scopes requested by the device */
|
|
43
|
+
scopes: DeviceScope[];
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/approvers/types.d.ts
|
|
47
|
+
/**
|
|
48
|
+
* Interface for authentication approval strategies.
|
|
49
|
+
* Implementations handle how the device code flow is approved.
|
|
50
|
+
*/
|
|
51
|
+
interface AuthApprover {
|
|
52
|
+
/**
|
|
53
|
+
* Approve the authentication request.
|
|
54
|
+
* This method is called after the authentication flow is started and should
|
|
55
|
+
* trigger the approval process (e.g., showing a URL to the user or auto-approving via PAT).
|
|
56
|
+
*
|
|
57
|
+
* @param request - The authentication request containing the user code and verification URL
|
|
58
|
+
*/
|
|
59
|
+
approve(request: AuthenticationRequest): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/client.d.ts
|
|
63
|
+
/**
|
|
64
|
+
* Client for authenticating with a Caido instance.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* import { CaidoAuth, BrowserApprover } from "@caido/auth";
|
|
69
|
+
*
|
|
70
|
+
* const auth = new CaidoAuth(
|
|
71
|
+
* "http://localhost:8080",
|
|
72
|
+
* new BrowserApprover((request) => {
|
|
73
|
+
* console.log(`Visit ${request.verificationUrl}`);
|
|
74
|
+
* })
|
|
75
|
+
* );
|
|
76
|
+
*
|
|
77
|
+
* const token = await auth.startAuthenticationFlow();
|
|
78
|
+
* console.log("Access token:", token.accessToken);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare class CaidoAuth {
|
|
82
|
+
private readonly instanceUrl;
|
|
83
|
+
private readonly graphqlUrl;
|
|
84
|
+
private readonly websocketUrl;
|
|
85
|
+
private readonly approver;
|
|
86
|
+
private readonly client;
|
|
87
|
+
/**
|
|
88
|
+
* Create a new CaidoAuth client.
|
|
89
|
+
*
|
|
90
|
+
* @param instanceUrl - Base URL of the Caido instance (e.g., "http://localhost:8080")
|
|
91
|
+
* @param approver - The approver to use for the authentication flow
|
|
92
|
+
*/
|
|
93
|
+
constructor(instanceUrl: string, approver: AuthApprover);
|
|
94
|
+
/**
|
|
95
|
+
* Convert HTTP(S) URL to WS(S) URL for subscriptions.
|
|
96
|
+
*/
|
|
97
|
+
private getWebsocketUrl;
|
|
98
|
+
/**
|
|
99
|
+
* Start the device code authentication flow.
|
|
100
|
+
*
|
|
101
|
+
* This method:
|
|
102
|
+
* 1. Initiates the authentication flow via GraphQL mutation
|
|
103
|
+
* 2. Calls the approver with the authentication request
|
|
104
|
+
* 3. Waits for the user to authorize via WebSocket subscription
|
|
105
|
+
* 4. Returns the authentication token once approved
|
|
106
|
+
*
|
|
107
|
+
* @returns The authentication token
|
|
108
|
+
* @throws {AuthenticationFlowError} If the flow fails to start
|
|
109
|
+
* @throws {AuthenticationError} If token retrieval fails
|
|
110
|
+
*/
|
|
111
|
+
startAuthenticationFlow(): Promise<AuthenticationToken>;
|
|
112
|
+
/**
|
|
113
|
+
* Subscribe and wait for the authentication token.
|
|
114
|
+
*
|
|
115
|
+
* @param requestId - The authentication request ID
|
|
116
|
+
* @returns The authentication token once the user authorizes
|
|
117
|
+
* @throws {AuthenticationError} If subscription fails or returns an error
|
|
118
|
+
*/
|
|
119
|
+
private waitForToken;
|
|
120
|
+
/**
|
|
121
|
+
* Refresh an access token using a refresh token.
|
|
122
|
+
*
|
|
123
|
+
* @param refreshToken - The refresh token from a previous authentication
|
|
124
|
+
* @returns New authentication token with updated access and refresh tokens
|
|
125
|
+
* @throws {TokenRefreshError} If the refresh fails
|
|
126
|
+
*/
|
|
127
|
+
refreshToken(refreshToken: string): Promise<AuthenticationToken>;
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/errors.d.ts
|
|
131
|
+
/**
|
|
132
|
+
* Base error class for authentication-related errors.
|
|
133
|
+
*/
|
|
134
|
+
declare class AuthenticationError extends Error {
|
|
135
|
+
constructor(message: string);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Error thrown when the authentication flow fails to start.
|
|
139
|
+
*/
|
|
140
|
+
declare class AuthenticationFlowError extends AuthenticationError {
|
|
141
|
+
/** Error code from the API */
|
|
142
|
+
readonly code: string;
|
|
143
|
+
constructor(code: string, message: string);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Error thrown when token refresh fails.
|
|
147
|
+
*/
|
|
148
|
+
declare class TokenRefreshError extends AuthenticationError {
|
|
149
|
+
/** Error code from the API */
|
|
150
|
+
readonly code: string;
|
|
151
|
+
constructor(code: string, message: string);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Error thrown when device approval fails.
|
|
155
|
+
*/
|
|
156
|
+
declare class DeviceApprovalError extends AuthenticationError {
|
|
157
|
+
/** HTTP status code if available */
|
|
158
|
+
readonly statusCode: number | undefined;
|
|
159
|
+
constructor(message: string, statusCode?: number);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Error thrown when fetching device information fails.
|
|
163
|
+
*/
|
|
164
|
+
declare class DeviceInformationError extends AuthenticationError {
|
|
165
|
+
/** HTTP status code if available */
|
|
166
|
+
readonly statusCode: number | undefined;
|
|
167
|
+
constructor(message: string, statusCode?: number);
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/approvers/browser.d.ts
|
|
171
|
+
/**
|
|
172
|
+
* Callback function that receives the authentication request details.
|
|
173
|
+
* Used to display the verification URL and user code to the user.
|
|
174
|
+
*/
|
|
175
|
+
type OnRequestCallback = (request: AuthenticationRequest) => Promise<void> | void;
|
|
176
|
+
/**
|
|
177
|
+
* Browser-based approver that delegates to a callback function.
|
|
178
|
+
* The callback should display the verification URL and user code to the user,
|
|
179
|
+
* who then manually approves the request in their browser.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const approver = new BrowserApprover((request) => {
|
|
184
|
+
* console.log(`Visit ${request.verificationUrl}`);
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
declare class BrowserApprover implements AuthApprover {
|
|
189
|
+
private readonly onRequest;
|
|
190
|
+
/**
|
|
191
|
+
* Create a new BrowserApprover.
|
|
192
|
+
*
|
|
193
|
+
* @param onRequest - Callback function that will be called with the authentication request
|
|
194
|
+
*/
|
|
195
|
+
constructor(onRequest: OnRequestCallback);
|
|
196
|
+
/**
|
|
197
|
+
* Approve the authentication request by calling the callback.
|
|
198
|
+
* The actual approval happens when the user visits the URL and enters the code.
|
|
199
|
+
*
|
|
200
|
+
* @param request - The authentication request
|
|
201
|
+
*/
|
|
202
|
+
approve(request: AuthenticationRequest): Promise<void>;
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/approvers/pat.d.ts
|
|
206
|
+
/**
|
|
207
|
+
* Options for the PATApprover.
|
|
208
|
+
*/
|
|
209
|
+
interface PATApproverOptions {
|
|
210
|
+
/** The Personal Access Token to use for approval */
|
|
211
|
+
pat: string;
|
|
212
|
+
/** If provided, only approve these scopes. Others will be filtered out. */
|
|
213
|
+
allowedScopes?: string[];
|
|
214
|
+
/** The API URL to use. Defaults to "https://api.caido.io" */
|
|
215
|
+
apiUrl?: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* PAT-based approver that automatically approves device code requests.
|
|
219
|
+
* Uses a Personal Access Token to call the Caido API directly.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* // Approve all scopes
|
|
224
|
+
* const approver = new PATApprover({ pat: "caido_xxxxx" });
|
|
225
|
+
*
|
|
226
|
+
* // Approve only specific scopes
|
|
227
|
+
* const limitedApprover = new PATApprover({
|
|
228
|
+
* pat: "caido_xxxxx",
|
|
229
|
+
* allowedScopes: ["read:projects", "write:requests"],
|
|
230
|
+
* });
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
declare class PATApprover implements AuthApprover {
|
|
234
|
+
private readonly pat;
|
|
235
|
+
private readonly allowedScopes;
|
|
236
|
+
private readonly apiUrl;
|
|
237
|
+
/**
|
|
238
|
+
* Create a new PATApprover.
|
|
239
|
+
*
|
|
240
|
+
* @param options - Configuration options for the approver
|
|
241
|
+
*/
|
|
242
|
+
constructor(options: PATApproverOptions);
|
|
243
|
+
/**
|
|
244
|
+
* Approve the authentication request using the PAT.
|
|
245
|
+
* First fetches device information to get available scopes,
|
|
246
|
+
* then filters scopes if allowedScopes is set,
|
|
247
|
+
* and finally approves the device.
|
|
248
|
+
*
|
|
249
|
+
* @param request - The authentication request
|
|
250
|
+
* @throws {DeviceInformationError} If fetching device information fails
|
|
251
|
+
* @throws {DeviceApprovalError} If approving the device fails
|
|
252
|
+
*/
|
|
253
|
+
approve(request: AuthenticationRequest): Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* Fetch device information from the API.
|
|
256
|
+
*
|
|
257
|
+
* @param userCode - The user code from the authentication request
|
|
258
|
+
* @returns The device information including available scopes
|
|
259
|
+
* @throws {DeviceInformationError} If the request fails
|
|
260
|
+
*/
|
|
261
|
+
private getDeviceInformation;
|
|
262
|
+
/**
|
|
263
|
+
* Approve the device with the specified scopes.
|
|
264
|
+
*
|
|
265
|
+
* @param userCode - The user code from the authentication request
|
|
266
|
+
* @param scopes - The scopes to approve
|
|
267
|
+
* @throws {DeviceApprovalError} If the request fails
|
|
268
|
+
*/
|
|
269
|
+
private approveDevice;
|
|
270
|
+
}
|
|
271
|
+
//#endregion
|
|
272
|
+
export { type AuthApprover, AuthenticationError, AuthenticationFlowError, type AuthenticationRequest, type AuthenticationToken, BrowserApprover, CaidoAuth, DeviceApprovalError, type DeviceInformation, DeviceInformationError, type DeviceScope, type OnRequestCallback, PATApprover, type PATApproverOptions, TokenRefreshError };
|
|
273
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/approvers/types.ts","../src/client.ts","../src/errors.ts","../src/approvers/browser.ts","../src/approvers/pat.ts"],"mappings":";;AAIA;;;UAAiB,qBAAA;;EAEf,EAAA;;EAEA,QAAA;;EAEA,eAAA;EAEW;EAAX,SAAA,EAAW,IAAA;AAAA;;;;UAMI,mBAAA;;EAEf,WAAA;;EAEA,YAAA;EAQF;EANE,SAAA,EAAW,IAAA;AAAA;;;AAgBb;UAViB,WAAA;;EAEf,IAAA;;EAEA,WAAA;AAAA;;;;UAMe,iBAAA;;EAEf,QAAA;ECpCe;EDsCf,MAAA,EAAQ,WAAA;AAAA;;;AAxCV;;;;AAAA,UCEiB,YAAA;;;;;;;ADYjB;ECJE,OAAA,CAAQ,OAAA,EAAS,qBAAA,GAAwB,OAAA;AAAA;;;;;;;;;;;;;ADI3C;;;;;;;;cEsBa,SAAA;EAAA,iBACM,WAAA;EAAA,iBACA,UAAA;EAAA,iBACA,YAAA;EAAA,iBACA,QAAA;EAAA,iBACA,MAAA;EFXjB;AAMF;;;;;EEaE,WAAA,CAAY,WAAA,UAAqB,QAAA,EAAU,YAAA;;;;UAenC,eAAA;;;AD9DV;;;;;;;;;;;ECiFE,uBAAA,CAAA,GAAiC,OAAA,CAAQ,mBAAA;;AA/C3C;;;;;;UAqGgB,YAAA;;;;;;;;EAwEd,YAAA,CAAmB,YAAA,WAAuB,OAAA,CAAQ,mBAAA;AAAA;;;;AFjNpD;;cGDa,mBAAA,SAA4B,KAAA;EACvC,WAAA,CAAY,OAAA;AAAA;;;;cASD,uBAAA,SAAgC,mBAAA;;WAElC,IAAA;EAET,WAAA,CAAY,IAAA,UAAc,OAAA;AAAA;;;;cAUf,iBAAA,SAA0B,mBAAA;;WAE5B,IAAA;EAET,WAAA,CAAY,IAAA,UAAc,OAAA;AAAA;AHD5B;;;AAAA,cGWa,mBAAA,SAA4B,mBAAA;EHPvC;EAAA,SGSS,UAAA;EAET,WAAA,CAAY,OAAA,UAAiB,UAAA;AAAA;;;;cAUlB,sBAAA,SAA+B,mBAAA;;WAEjC,UAAA;EAET,WAAA,CAAY,OAAA,UAAiB,UAAA;AAAA;;;;;;;KCnDnB,iBAAA,IACV,OAAA,EAAS,qBAAA,KACN,OAAA;;;;;;AJQL;;;;;;;cIMa,eAAA,YAA2B,YAAA;EAAA,iBACrB,SAAA;EJDN;AAMb;;;;EIEE,WAAA,CAAY,SAAA,EAAW,iBAAA;EJQzB;;;;;;EIEE,OAAA,CAAc,OAAA,EAAS,qBAAA,GAAwB,OAAA;AAAA;;;;;;UChChC,kBAAA;;EAEf,GAAA;;EAEA,aAAA;;EAEA,MAAA;AAAA;;;;;;;;;;ALcF;;;;;AAUA;;cKLa,WAAA,YAAuB,YAAA;EAAA,iBACjB,GAAA;EAAA,iBACA,aAAA;EAAA,iBACA,MAAA;;;;;;EAOjB,WAAA,CAAY,OAAA,EAAS,kBAAA;EJvCvB;;;;;;;;;;EIuDE,OAAA,CAAc,OAAA,EAAS,qBAAA,GAAwB,OAAA;;;AHrBjD;;;;;UG4CgB,oBAAA;;;;;;;;UAmCA,aAAA;AAAA"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Represents an authentication request from the device code flow.
|
|
4
|
+
* Contains the information needed for the user to authorize the device.
|
|
5
|
+
*/
|
|
6
|
+
interface AuthenticationRequest {
|
|
7
|
+
/** Unique identifier for this authentication request */
|
|
8
|
+
id: string;
|
|
9
|
+
/** The code the user must enter to authorize */
|
|
10
|
+
userCode: string;
|
|
11
|
+
/** The URL where the user should go to authorize */
|
|
12
|
+
verificationUrl: string;
|
|
13
|
+
/** When this request expires */
|
|
14
|
+
expiresAt: Date;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Represents an authentication token obtained after successful authorization.
|
|
18
|
+
*/
|
|
19
|
+
interface AuthenticationToken {
|
|
20
|
+
/** The access token for API requests */
|
|
21
|
+
accessToken: string;
|
|
22
|
+
/** The refresh token to obtain new access tokens */
|
|
23
|
+
refreshToken: string;
|
|
24
|
+
/** When the access token expires */
|
|
25
|
+
expiresAt: Date;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Scope information returned from device information endpoint.
|
|
29
|
+
*/
|
|
30
|
+
interface DeviceScope {
|
|
31
|
+
/** The scope identifier */
|
|
32
|
+
name: string;
|
|
33
|
+
/** Human-readable description of the scope */
|
|
34
|
+
description?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Device information response from the API.
|
|
38
|
+
*/
|
|
39
|
+
interface DeviceInformation {
|
|
40
|
+
/** The user code associated with this device request */
|
|
41
|
+
userCode: string;
|
|
42
|
+
/** List of scopes requested by the device */
|
|
43
|
+
scopes: DeviceScope[];
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/approvers/types.d.ts
|
|
47
|
+
/**
|
|
48
|
+
* Interface for authentication approval strategies.
|
|
49
|
+
* Implementations handle how the device code flow is approved.
|
|
50
|
+
*/
|
|
51
|
+
interface AuthApprover {
|
|
52
|
+
/**
|
|
53
|
+
* Approve the authentication request.
|
|
54
|
+
* This method is called after the authentication flow is started and should
|
|
55
|
+
* trigger the approval process (e.g., showing a URL to the user or auto-approving via PAT).
|
|
56
|
+
*
|
|
57
|
+
* @param request - The authentication request containing the user code and verification URL
|
|
58
|
+
*/
|
|
59
|
+
approve(request: AuthenticationRequest): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/client.d.ts
|
|
63
|
+
/**
|
|
64
|
+
* Client for authenticating with a Caido instance.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* import { CaidoAuth, BrowserApprover } from "@caido/auth";
|
|
69
|
+
*
|
|
70
|
+
* const auth = new CaidoAuth(
|
|
71
|
+
* "http://localhost:8080",
|
|
72
|
+
* new BrowserApprover((request) => {
|
|
73
|
+
* console.log(`Visit ${request.verificationUrl}`);
|
|
74
|
+
* })
|
|
75
|
+
* );
|
|
76
|
+
*
|
|
77
|
+
* const token = await auth.startAuthenticationFlow();
|
|
78
|
+
* console.log("Access token:", token.accessToken);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare class CaidoAuth {
|
|
82
|
+
private readonly instanceUrl;
|
|
83
|
+
private readonly graphqlUrl;
|
|
84
|
+
private readonly websocketUrl;
|
|
85
|
+
private readonly approver;
|
|
86
|
+
private readonly client;
|
|
87
|
+
/**
|
|
88
|
+
* Create a new CaidoAuth client.
|
|
89
|
+
*
|
|
90
|
+
* @param instanceUrl - Base URL of the Caido instance (e.g., "http://localhost:8080")
|
|
91
|
+
* @param approver - The approver to use for the authentication flow
|
|
92
|
+
*/
|
|
93
|
+
constructor(instanceUrl: string, approver: AuthApprover);
|
|
94
|
+
/**
|
|
95
|
+
* Convert HTTP(S) URL to WS(S) URL for subscriptions.
|
|
96
|
+
*/
|
|
97
|
+
private getWebsocketUrl;
|
|
98
|
+
/**
|
|
99
|
+
* Start the device code authentication flow.
|
|
100
|
+
*
|
|
101
|
+
* This method:
|
|
102
|
+
* 1. Initiates the authentication flow via GraphQL mutation
|
|
103
|
+
* 2. Calls the approver with the authentication request
|
|
104
|
+
* 3. Waits for the user to authorize via WebSocket subscription
|
|
105
|
+
* 4. Returns the authentication token once approved
|
|
106
|
+
*
|
|
107
|
+
* @returns The authentication token
|
|
108
|
+
* @throws {AuthenticationFlowError} If the flow fails to start
|
|
109
|
+
* @throws {AuthenticationError} If token retrieval fails
|
|
110
|
+
*/
|
|
111
|
+
startAuthenticationFlow(): Promise<AuthenticationToken>;
|
|
112
|
+
/**
|
|
113
|
+
* Subscribe and wait for the authentication token.
|
|
114
|
+
*
|
|
115
|
+
* @param requestId - The authentication request ID
|
|
116
|
+
* @returns The authentication token once the user authorizes
|
|
117
|
+
* @throws {AuthenticationError} If subscription fails or returns an error
|
|
118
|
+
*/
|
|
119
|
+
private waitForToken;
|
|
120
|
+
/**
|
|
121
|
+
* Refresh an access token using a refresh token.
|
|
122
|
+
*
|
|
123
|
+
* @param refreshToken - The refresh token from a previous authentication
|
|
124
|
+
* @returns New authentication token with updated access and refresh tokens
|
|
125
|
+
* @throws {TokenRefreshError} If the refresh fails
|
|
126
|
+
*/
|
|
127
|
+
refreshToken(refreshToken: string): Promise<AuthenticationToken>;
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/errors.d.ts
|
|
131
|
+
/**
|
|
132
|
+
* Base error class for authentication-related errors.
|
|
133
|
+
*/
|
|
134
|
+
declare class AuthenticationError extends Error {
|
|
135
|
+
constructor(message: string);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Error thrown when the authentication flow fails to start.
|
|
139
|
+
*/
|
|
140
|
+
declare class AuthenticationFlowError extends AuthenticationError {
|
|
141
|
+
/** Error code from the API */
|
|
142
|
+
readonly code: string;
|
|
143
|
+
constructor(code: string, message: string);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Error thrown when token refresh fails.
|
|
147
|
+
*/
|
|
148
|
+
declare class TokenRefreshError extends AuthenticationError {
|
|
149
|
+
/** Error code from the API */
|
|
150
|
+
readonly code: string;
|
|
151
|
+
constructor(code: string, message: string);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Error thrown when device approval fails.
|
|
155
|
+
*/
|
|
156
|
+
declare class DeviceApprovalError extends AuthenticationError {
|
|
157
|
+
/** HTTP status code if available */
|
|
158
|
+
readonly statusCode: number | undefined;
|
|
159
|
+
constructor(message: string, statusCode?: number);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Error thrown when fetching device information fails.
|
|
163
|
+
*/
|
|
164
|
+
declare class DeviceInformationError extends AuthenticationError {
|
|
165
|
+
/** HTTP status code if available */
|
|
166
|
+
readonly statusCode: number | undefined;
|
|
167
|
+
constructor(message: string, statusCode?: number);
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/approvers/browser.d.ts
|
|
171
|
+
/**
|
|
172
|
+
* Callback function that receives the authentication request details.
|
|
173
|
+
* Used to display the verification URL and user code to the user.
|
|
174
|
+
*/
|
|
175
|
+
type OnRequestCallback = (request: AuthenticationRequest) => Promise<void> | void;
|
|
176
|
+
/**
|
|
177
|
+
* Browser-based approver that delegates to a callback function.
|
|
178
|
+
* The callback should display the verification URL and user code to the user,
|
|
179
|
+
* who then manually approves the request in their browser.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const approver = new BrowserApprover((request) => {
|
|
184
|
+
* console.log(`Visit ${request.verificationUrl}`);
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
declare class BrowserApprover implements AuthApprover {
|
|
189
|
+
private readonly onRequest;
|
|
190
|
+
/**
|
|
191
|
+
* Create a new BrowserApprover.
|
|
192
|
+
*
|
|
193
|
+
* @param onRequest - Callback function that will be called with the authentication request
|
|
194
|
+
*/
|
|
195
|
+
constructor(onRequest: OnRequestCallback);
|
|
196
|
+
/**
|
|
197
|
+
* Approve the authentication request by calling the callback.
|
|
198
|
+
* The actual approval happens when the user visits the URL and enters the code.
|
|
199
|
+
*
|
|
200
|
+
* @param request - The authentication request
|
|
201
|
+
*/
|
|
202
|
+
approve(request: AuthenticationRequest): Promise<void>;
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/approvers/pat.d.ts
|
|
206
|
+
/**
|
|
207
|
+
* Options for the PATApprover.
|
|
208
|
+
*/
|
|
209
|
+
interface PATApproverOptions {
|
|
210
|
+
/** The Personal Access Token to use for approval */
|
|
211
|
+
pat: string;
|
|
212
|
+
/** If provided, only approve these scopes. Others will be filtered out. */
|
|
213
|
+
allowedScopes?: string[];
|
|
214
|
+
/** The API URL to use. Defaults to "https://api.caido.io" */
|
|
215
|
+
apiUrl?: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* PAT-based approver that automatically approves device code requests.
|
|
219
|
+
* Uses a Personal Access Token to call the Caido API directly.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* // Approve all scopes
|
|
224
|
+
* const approver = new PATApprover({ pat: "caido_xxxxx" });
|
|
225
|
+
*
|
|
226
|
+
* // Approve only specific scopes
|
|
227
|
+
* const limitedApprover = new PATApprover({
|
|
228
|
+
* pat: "caido_xxxxx",
|
|
229
|
+
* allowedScopes: ["read:projects", "write:requests"],
|
|
230
|
+
* });
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
declare class PATApprover implements AuthApprover {
|
|
234
|
+
private readonly pat;
|
|
235
|
+
private readonly allowedScopes;
|
|
236
|
+
private readonly apiUrl;
|
|
237
|
+
/**
|
|
238
|
+
* Create a new PATApprover.
|
|
239
|
+
*
|
|
240
|
+
* @param options - Configuration options for the approver
|
|
241
|
+
*/
|
|
242
|
+
constructor(options: PATApproverOptions);
|
|
243
|
+
/**
|
|
244
|
+
* Approve the authentication request using the PAT.
|
|
245
|
+
* First fetches device information to get available scopes,
|
|
246
|
+
* then filters scopes if allowedScopes is set,
|
|
247
|
+
* and finally approves the device.
|
|
248
|
+
*
|
|
249
|
+
* @param request - The authentication request
|
|
250
|
+
* @throws {DeviceInformationError} If fetching device information fails
|
|
251
|
+
* @throws {DeviceApprovalError} If approving the device fails
|
|
252
|
+
*/
|
|
253
|
+
approve(request: AuthenticationRequest): Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* Fetch device information from the API.
|
|
256
|
+
*
|
|
257
|
+
* @param userCode - The user code from the authentication request
|
|
258
|
+
* @returns The device information including available scopes
|
|
259
|
+
* @throws {DeviceInformationError} If the request fails
|
|
260
|
+
*/
|
|
261
|
+
private getDeviceInformation;
|
|
262
|
+
/**
|
|
263
|
+
* Approve the device with the specified scopes.
|
|
264
|
+
*
|
|
265
|
+
* @param userCode - The user code from the authentication request
|
|
266
|
+
* @param scopes - The scopes to approve
|
|
267
|
+
* @throws {DeviceApprovalError} If the request fails
|
|
268
|
+
*/
|
|
269
|
+
private approveDevice;
|
|
270
|
+
}
|
|
271
|
+
//#endregion
|
|
272
|
+
export { type AuthApprover, AuthenticationError, AuthenticationFlowError, type AuthenticationRequest, type AuthenticationToken, BrowserApprover, CaidoAuth, DeviceApprovalError, type DeviceInformation, DeviceInformationError, type DeviceScope, type OnRequestCallback, PATApprover, type PATApproverOptions, TokenRefreshError };
|
|
273
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/approvers/types.ts","../src/client.ts","../src/errors.ts","../src/approvers/browser.ts","../src/approvers/pat.ts"],"mappings":";;AAIA;;;UAAiB,qBAAA;;EAEf,EAAA;;EAEA,QAAA;;EAEA,eAAA;EAEW;EAAX,SAAA,EAAW,IAAA;AAAA;;;;UAMI,mBAAA;;EAEf,WAAA;;EAEA,YAAA;EAQF;EANE,SAAA,EAAW,IAAA;AAAA;;;AAgBb;UAViB,WAAA;;EAEf,IAAA;;EAEA,WAAA;AAAA;;;;UAMe,iBAAA;;EAEf,QAAA;ECpCe;EDsCf,MAAA,EAAQ,WAAA;AAAA;;;AAxCV;;;;AAAA,UCEiB,YAAA;;;;;;;ADYjB;ECJE,OAAA,CAAQ,OAAA,EAAS,qBAAA,GAAwB,OAAA;AAAA;;;;;;;;;;;;;ADI3C;;;;;;;;cEsBa,SAAA;EAAA,iBACM,WAAA;EAAA,iBACA,UAAA;EAAA,iBACA,YAAA;EAAA,iBACA,QAAA;EAAA,iBACA,MAAA;EFXjB;AAMF;;;;;EEaE,WAAA,CAAY,WAAA,UAAqB,QAAA,EAAU,YAAA;;;;UAenC,eAAA;;;AD9DV;;;;;;;;;;;ECiFE,uBAAA,CAAA,GAAiC,OAAA,CAAQ,mBAAA;;AA/C3C;;;;;;UAqGgB,YAAA;;;;;;;;EAwEd,YAAA,CAAmB,YAAA,WAAuB,OAAA,CAAQ,mBAAA;AAAA;;;;AFjNpD;;cGDa,mBAAA,SAA4B,KAAA;EACvC,WAAA,CAAY,OAAA;AAAA;;;;cASD,uBAAA,SAAgC,mBAAA;;WAElC,IAAA;EAET,WAAA,CAAY,IAAA,UAAc,OAAA;AAAA;;;;cAUf,iBAAA,SAA0B,mBAAA;;WAE5B,IAAA;EAET,WAAA,CAAY,IAAA,UAAc,OAAA;AAAA;AHD5B;;;AAAA,cGWa,mBAAA,SAA4B,mBAAA;EHPvC;EAAA,SGSS,UAAA;EAET,WAAA,CAAY,OAAA,UAAiB,UAAA;AAAA;;;;cAUlB,sBAAA,SAA+B,mBAAA;;WAEjC,UAAA;EAET,WAAA,CAAY,OAAA,UAAiB,UAAA;AAAA;;;;;;;KCnDnB,iBAAA,IACV,OAAA,EAAS,qBAAA,KACN,OAAA;;;;;;AJQL;;;;;;;cIMa,eAAA,YAA2B,YAAA;EAAA,iBACrB,SAAA;EJDN;AAMb;;;;EIEE,WAAA,CAAY,SAAA,EAAW,iBAAA;EJQzB;;;;;;EIEE,OAAA,CAAc,OAAA,EAAS,qBAAA,GAAwB,OAAA;AAAA;;;;;;UChChC,kBAAA;;EAEf,GAAA;;EAEA,aAAA;;EAEA,MAAA;AAAA;;;;;;;;;;ALcF;;;;;AAUA;;cKLa,WAAA,YAAuB,YAAA;EAAA,iBACjB,GAAA;EAAA,iBACA,aAAA;EAAA,iBACA,MAAA;;;;;;EAOjB,WAAA,CAAY,OAAA,EAAS,kBAAA;EJvCvB;;;;;;;;;;EIuDE,OAAA,CAAc,OAAA,EAAS,qBAAA,GAAwB,OAAA;;;AHrBjD;;;;;UG4CgB,oBAAA;;;;;;;;UAmCA,aAAA;AAAA"}
|