1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
/**
* The Firebase App Check Web SDK.
*
* @remarks
* Firebase App Check does not work in a Node.js environment using `ReCaptchaV3Provider` or
* `ReCaptchaEnterpriseProvider`, but can be used in Node.js if you use
* `CustomProvider` and write your own attestation method.
*
* @packageDocumentation
*/
import { FirebaseApp } from '@firebase/app';
import { PartialObserver } from '@firebase/util';
import { Unsubscribe } from '@firebase/util';
/**
* The Firebase App Check service interface.
*
* @public
*/
export declare interface AppCheck {
/**
* The {@link @firebase/app#FirebaseApp} this `AppCheck` instance is associated with.
*/
app: FirebaseApp;
}
/* Excluded from this release type: _AppCheckComponentName */
/* Excluded from this release type: _AppCheckInternalComponentName */
/**
* Options for App Check initialization.
* @public
*/
export declare interface AppCheckOptions {
/**
* A reCAPTCHA V3 provider, reCAPTCHA Enterprise provider, or custom provider.
*/
provider: CustomProvider | ReCaptchaV3Provider | ReCaptchaEnterpriseProvider;
/**
* If set to true, enables automatic background refresh of App Check token.
*/
isTokenAutoRefreshEnabled?: boolean;
}
declare interface AppCheckProvider {
/* Excluded from this release type: getToken */
/* Excluded from this release type: initialize */
}
/**
* The token returned from an App Check provider.
* @public
*/
export declare interface AppCheckToken {
readonly token: string;
/**
* The local timestamp after which the token will expire.
*/
readonly expireTimeMillis: number;
}
declare interface AppCheckTokenInternal extends AppCheckToken {
issuedAtTimeMillis: number;
}
/**
* A listener that is called whenever the App Check token changes.
* @public
*/
export declare type AppCheckTokenListener = (token: AppCheckTokenResult) => void;
/**
* Result returned by `getToken()`.
* @public
*/
export declare interface AppCheckTokenResult {
/**
* The token string in JWT format.
*/
readonly token: string;
}
/**
* Custom provider class.
* @public
*/
export declare class CustomProvider implements AppCheckProvider {
private _customProviderOptions;
private _app?;
constructor(_customProviderOptions: CustomProviderOptions);
/* Excluded from this release type: getToken */
/* Excluded from this release type: initialize */
/* Excluded from this release type: isEqual */
}
/**
* Options when creating a {@link CustomProvider}.
* @public
*/
export declare interface CustomProviderOptions {
/**
* Function to get an App Check token through a custom provider
* service.
*/
getToken: () => Promise<AppCheckToken>;
}
/**
* Requests a Firebase App Check token. This method should be used
* only if you need to authorize requests to a non-Firebase backend.
*
* Returns limited-use tokens that are intended for use with your
* non-Firebase backend endpoints that are protected with
* <a href="https://firebase.google.com/docs/app-check/custom-resource-backend#replay-protection">
* Replay Protection</a>. This method
* does not affect the token generation behavior of the
* #getAppCheckToken() method.
*
* @param appCheckInstance - The App Check service instance.
* @returns The limited use token.
* @public
*/
export declare function getLimitedUseToken(appCheckInstance: AppCheck): Promise<AppCheckTokenResult>;
/**
* Get the current App Check token. If `forceRefresh` is false, this function first
* checks for a valid token in memory, then local persistence (IndexedDB).
* If not found, or if `forceRefresh` is true, it makes a request to the
* App Check endpoint for a fresh token. That request attaches
* to the most recent in-flight request if one is present.
*
* @param appCheckInstance - The App Check service instance.
* @param forceRefresh - If true, will always try to fetch a fresh token.
* If false, will use a cached token if found in storage.
* @public
*/
export declare function getToken(appCheckInstance: AppCheck, forceRefresh?: boolean): Promise<AppCheckTokenResult>;
/**
* Activate App Check for the given app. Can be called only once per app.
* @param app - the {@link @firebase/app#FirebaseApp} to activate App Check for
* @param options - App Check initialization options
* @public
*/
export declare function initializeAppCheck(app: FirebaseApp | undefined, options: AppCheckOptions): AppCheck;
/**
* Registers a listener to changes in the token state. There can be more
* than one listener registered at the same time for one or more
* App Check instances. The listeners call back on the UI thread whenever
* the current token associated with this App Check instance changes.
*
* @param appCheckInstance - The App Check service instance.
* @param observer - An object with `next`, `error`, and `complete`
* properties. `next` is called with an
* {@link AppCheckTokenResult}
* whenever the token changes. `error` is optional and is called if an
* error is thrown by the listener (the `next` function). `complete`
* is unused, as the token stream is unending.
*
* @returns A function that unsubscribes this listener.
* @public
*/
export declare function onTokenChanged(appCheckInstance: AppCheck, observer: PartialObserver<AppCheckTokenResult>): Unsubscribe;
/**
* Registers a listener to changes in the token state. There can be more
* than one listener registered at the same time for one or more
* App Check instances. The listeners call back on the UI thread whenever
* the current token associated with this App Check instance changes.
*
* @param appCheckInstance - The App Check service instance.
* @param onNext - When the token changes, this function is called with an
* {@link AppCheckTokenResult}.
* @param onError - Optional. Called if there is an error thrown by the
* listener (the `onNext` function).
* @param onCompletion - Currently unused, as the token stream is unending.
* @returns A function that unsubscribes this listener.
* @public
*/
export declare function onTokenChanged(appCheckInstance: AppCheck, onNext: (tokenResult: AppCheckTokenResult) => void, onError?: (error: Error) => void, onCompletion?: () => void): Unsubscribe;
export { PartialObserver }
/**
* App Check provider that can obtain a reCAPTCHA Enterprise token and exchange it
* for an App Check token.
*
* @public
*/
export declare class ReCaptchaEnterpriseProvider implements AppCheckProvider {
private _siteKey;
private _app?;
private _heartbeatServiceProvider?;
/**
* Throttle requests on certain error codes to prevent too many retries
* in a short time.
*/
private _throttleData;
/**
* Create a ReCaptchaEnterpriseProvider instance.
* @param siteKey - reCAPTCHA Enterprise score-based site key.
*/
constructor(_siteKey: string);
/* Excluded from this release type: getToken */
/* Excluded from this release type: initialize */
/* Excluded from this release type: isEqual */
}
/**
* App Check provider that can obtain a reCAPTCHA V3 token and exchange it
* for an App Check token.
*
* @public
*/
export declare class ReCaptchaV3Provider implements AppCheckProvider {
private _siteKey;
private _app?;
private _heartbeatServiceProvider?;
/**
* Throttle requests on certain error codes to prevent too many retries
* in a short time.
*/
private _throttleData;
/**
* Create a ReCaptchaV3Provider instance.
* @param siteKey - ReCAPTCHA V3 siteKey.
*/
constructor(_siteKey: string);
/* Excluded from this release type: getToken */
/* Excluded from this release type: initialize */
/* Excluded from this release type: isEqual */
}
/**
* Set whether App Check will automatically refresh tokens as needed.
*
* @param appCheckInstance - The App Check service instance.
* @param isTokenAutoRefreshEnabled - If true, the SDK automatically
* refreshes App Check tokens as needed. This overrides any value set
* during `initializeAppCheck()`.
* @public
*/
export declare function setTokenAutoRefreshEnabled(appCheckInstance: AppCheck, isTokenAutoRefreshEnabled: boolean): void;
export { Unsubscribe }
export { }
|