@react-native-firebase/app-check 23.6.0 → 23.8.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/commonjs/ReactNativeFirebaseAppCheckProvider.js +19 -0
- package/dist/commonjs/ReactNativeFirebaseAppCheckProvider.js.map +1 -0
- package/dist/commonjs/index.js +38 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/modular.js +124 -0
- package/dist/commonjs/modular.js.map +1 -0
- package/dist/commonjs/namespaced.js +212 -0
- package/dist/commonjs/namespaced.js.map +1 -0
- package/dist/commonjs/package.json +1 -0
- package/dist/commonjs/types/appcheck.js +93 -0
- package/dist/commonjs/types/appcheck.js.map +1 -0
- package/dist/commonjs/version.js +9 -0
- package/dist/commonjs/version.js.map +1 -0
- package/dist/commonjs/web/RNFBAppCheckModule.android.js +9 -0
- package/dist/commonjs/web/RNFBAppCheckModule.android.js.map +2 -0
- package/dist/commonjs/web/RNFBAppCheckModule.ios.js +9 -0
- package/dist/commonjs/web/RNFBAppCheckModule.ios.js.map +2 -0
- package/dist/commonjs/web/RNFBAppCheckModule.js +97 -0
- package/dist/commonjs/web/RNFBAppCheckModule.js.map +1 -0
- package/dist/module/ReactNativeFirebaseAppCheckProvider.js +14 -0
- package/dist/module/ReactNativeFirebaseAppCheckProvider.js.map +1 -0
- package/{ios/RNFBAppCheck/RNFBAppCheckModule.h → dist/module/index.js} +10 -12
- package/dist/module/index.js.map +1 -0
- package/dist/module/modular.js +110 -0
- package/dist/module/modular.js.map +1 -0
- package/{lib/index.js → dist/module/namespaced.js} +50 -80
- package/dist/module/namespaced.js.map +1 -0
- package/dist/module/package.json +1 -0
- package/dist/module/types/appcheck.js +89 -0
- package/dist/module/types/appcheck.js.map +1 -0
- package/dist/module/version.js +5 -0
- package/dist/module/version.js.map +1 -0
- package/dist/module/web/RNFBAppCheckModule.android.js +5 -0
- package/dist/module/web/RNFBAppCheckModule.android.js.map +2 -0
- package/dist/module/web/RNFBAppCheckModule.ios.js +5 -0
- package/dist/module/web/RNFBAppCheckModule.ios.js.map +2 -0
- package/dist/module/web/RNFBAppCheckModule.js +88 -0
- package/dist/module/web/RNFBAppCheckModule.js.map +1 -0
- package/dist/typescript/commonjs/lib/ReactNativeFirebaseAppCheckProvider.d.ts +8 -0
- package/dist/typescript/commonjs/lib/ReactNativeFirebaseAppCheckProvider.d.ts.map +1 -0
- package/dist/typescript/commonjs/lib/index.d.ts +5 -0
- package/dist/typescript/commonjs/lib/index.d.ts.map +1 -0
- package/dist/typescript/commonjs/lib/modular.d.ts +57 -0
- package/dist/typescript/commonjs/lib/modular.d.ts.map +1 -0
- package/dist/typescript/commonjs/lib/namespaced.d.ts +17 -0
- package/dist/typescript/commonjs/lib/namespaced.d.ts.map +1 -0
- package/{lib/index.d.ts → dist/typescript/commonjs/lib/types/appcheck.d.ts} +162 -221
- package/dist/typescript/commonjs/lib/types/appcheck.d.ts.map +1 -0
- package/dist/typescript/commonjs/lib/version.d.ts +2 -0
- package/dist/typescript/commonjs/lib/version.d.ts.map +1 -0
- package/dist/typescript/commonjs/lib/web/RNFBAppCheckModule.android.d.ts +3 -0
- package/dist/typescript/commonjs/lib/web/RNFBAppCheckModule.android.d.ts.map +1 -0
- package/dist/typescript/commonjs/lib/web/RNFBAppCheckModule.d.ts +18 -0
- package/dist/typescript/commonjs/lib/web/RNFBAppCheckModule.d.ts.map +1 -0
- package/dist/typescript/commonjs/lib/web/RNFBAppCheckModule.ios.d.ts +3 -0
- package/dist/typescript/commonjs/lib/web/RNFBAppCheckModule.ios.d.ts.map +1 -0
- package/dist/typescript/commonjs/package.json +1 -0
- package/dist/typescript/module/lib/ReactNativeFirebaseAppCheckProvider.d.ts +8 -0
- package/dist/typescript/module/lib/ReactNativeFirebaseAppCheckProvider.d.ts.map +1 -0
- package/dist/typescript/module/lib/index.d.ts +5 -0
- package/dist/typescript/module/lib/index.d.ts.map +1 -0
- package/dist/typescript/module/lib/modular.d.ts +57 -0
- package/dist/typescript/module/lib/modular.d.ts.map +1 -0
- package/dist/typescript/module/lib/namespaced.d.ts +17 -0
- package/dist/typescript/module/lib/namespaced.d.ts.map +1 -0
- package/dist/typescript/module/lib/types/appcheck.d.ts +299 -0
- package/dist/typescript/module/lib/types/appcheck.d.ts.map +1 -0
- package/dist/typescript/module/lib/version.d.ts +2 -0
- package/dist/typescript/module/lib/version.d.ts.map +1 -0
- package/dist/typescript/module/lib/web/RNFBAppCheckModule.android.d.ts +3 -0
- package/dist/typescript/module/lib/web/RNFBAppCheckModule.android.d.ts.map +1 -0
- package/dist/typescript/module/lib/web/RNFBAppCheckModule.d.ts +18 -0
- package/dist/typescript/module/lib/web/RNFBAppCheckModule.d.ts.map +1 -0
- package/dist/typescript/module/lib/web/RNFBAppCheckModule.ios.d.ts +3 -0
- package/dist/typescript/module/lib/web/RNFBAppCheckModule.ios.d.ts.map +1 -0
- package/dist/typescript/module/package.json +1 -0
- package/lib/ReactNativeFirebaseAppCheckProvider.ts +21 -0
- package/lib/index.ts +46 -0
- package/lib/modular.ts +157 -0
- package/lib/namespaced.ts +305 -0
- package/lib/types/appcheck.ts +386 -0
- package/lib/version.ts +2 -0
- package/lib/web/RNFBAppCheckModule.android.ts +4 -0
- package/lib/web/RNFBAppCheckModule.ios.ts +4 -0
- package/lib/web/RNFBAppCheckModule.ts +115 -0
- package/package.json +64 -8
- package/tsconfig.json +21 -0
- package/CHANGELOG.md +0 -769
- package/RNFBAppCheck.podspec +0 -50
- package/android/.editorconfig +0 -10
- package/android/build.gradle +0 -110
- package/android/lint.xml +0 -5
- package/android/settings.gradle +0 -1
- package/android/src/main/AndroidManifest.xml +0 -7
- package/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java +0 -281
- package/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckPackage.java +0 -41
- package/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckProvider.java +0 -97
- package/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckProviderFactory.java +0 -67
- package/app.plugin.js +0 -1
- package/ios/RNFBAppCheck/RNFBAppCheckModule.m +0 -171
- package/ios/RNFBAppCheck/RNFBAppCheckProvider.h +0 -33
- package/ios/RNFBAppCheck/RNFBAppCheckProvider.m +0 -90
- package/ios/RNFBAppCheck/RNFBAppCheckProviderFactory.h +0 -28
- package/ios/RNFBAppCheck/RNFBAppCheckProviderFactory.m +0 -61
- package/ios/RNFBAppCheck.xcodeproj/project.pbxproj +0 -349
- package/ios/RNFBAppCheck.xcodeproj/xcshareddata/IDETemplateMacros.plist +0 -24
- package/lib/ReactNativeFirebaseAppCheckProvider.js +0 -9
- package/lib/modular/index.d.ts +0 -149
- package/lib/modular/index.js +0 -102
- package/lib/version.js +0 -2
- package/plugin/build/index.d.ts +0 -3
- package/plugin/build/index.js +0 -15
- package/plugin/build/ios/appDelegate.d.ts +0 -6
- package/plugin/build/ios/appDelegate.js +0 -137
- package/plugin/build/ios/index.d.ts +0 -2
- package/plugin/build/ios/index.js +0 -5
- package/plugin/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
isBoolean,
|
|
20
|
+
isIOS,
|
|
21
|
+
isString,
|
|
22
|
+
isObject,
|
|
23
|
+
isFunction,
|
|
24
|
+
isUndefined,
|
|
25
|
+
isOther,
|
|
26
|
+
parseListenerOrObserver,
|
|
27
|
+
} from '@react-native-firebase/app/lib/common';
|
|
28
|
+
import {
|
|
29
|
+
createModuleNamespace,
|
|
30
|
+
FirebaseModule,
|
|
31
|
+
getFirebaseRoot,
|
|
32
|
+
} from '@react-native-firebase/app/lib/internal';
|
|
33
|
+
import type { ModuleConfig } from '@react-native-firebase/app/lib/internal';
|
|
34
|
+
import { Platform } from 'react-native';
|
|
35
|
+
import ReactNativeFirebaseAppCheckProvider from './ReactNativeFirebaseAppCheckProvider';
|
|
36
|
+
import { setReactNativeModule } from '@react-native-firebase/app/lib/internal/nativeModule';
|
|
37
|
+
import fallBackModule from './web/RNFBAppCheckModule';
|
|
38
|
+
import { version } from './version';
|
|
39
|
+
import type {
|
|
40
|
+
CustomProviderOptions,
|
|
41
|
+
AppCheckProvider,
|
|
42
|
+
AppCheckTokenResult,
|
|
43
|
+
AppCheckOptions,
|
|
44
|
+
AppCheckListenerResult,
|
|
45
|
+
PartialObserver,
|
|
46
|
+
AppCheck,
|
|
47
|
+
AppCheckStatics,
|
|
48
|
+
ProviderWithOptions,
|
|
49
|
+
} from './types/appcheck';
|
|
50
|
+
import type { ReactNativeFirebase } from '@react-native-firebase/app';
|
|
51
|
+
|
|
52
|
+
const namespace = 'appCheck';
|
|
53
|
+
|
|
54
|
+
const nativeModuleName = 'RNFBAppCheckModule';
|
|
55
|
+
|
|
56
|
+
export class CustomProvider implements AppCheckProvider {
|
|
57
|
+
private _customProviderOptions: CustomProviderOptions;
|
|
58
|
+
|
|
59
|
+
constructor(_customProviderOptions: CustomProviderOptions) {
|
|
60
|
+
if (!isObject(_customProviderOptions)) {
|
|
61
|
+
throw new Error('Invalid configuration: no provider options defined.');
|
|
62
|
+
}
|
|
63
|
+
if (!isFunction(_customProviderOptions.getToken)) {
|
|
64
|
+
throw new Error('Invalid configuration: no getToken function defined.');
|
|
65
|
+
}
|
|
66
|
+
this._customProviderOptions = _customProviderOptions;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async getToken() {
|
|
70
|
+
return this._customProviderOptions.getToken();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const statics = {
|
|
75
|
+
CustomProvider,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Type guard to check if a provider has providerOptions.
|
|
80
|
+
* This provides proper type narrowing for providers that support platform-specific configuration.
|
|
81
|
+
*/
|
|
82
|
+
function hasProviderOptions(
|
|
83
|
+
provider: AppCheckOptions['provider'],
|
|
84
|
+
): provider is ProviderWithOptions {
|
|
85
|
+
return (
|
|
86
|
+
provider !== undefined &&
|
|
87
|
+
'providerOptions' in provider &&
|
|
88
|
+
provider.providerOptions !== undefined
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
class FirebaseAppCheckModule extends FirebaseModule {
|
|
93
|
+
_listenerCount: number;
|
|
94
|
+
|
|
95
|
+
constructor(
|
|
96
|
+
app: ReactNativeFirebase.FirebaseAppBase,
|
|
97
|
+
config: ModuleConfig,
|
|
98
|
+
customUrlOrRegion?: string | null,
|
|
99
|
+
) {
|
|
100
|
+
super(app, config, customUrlOrRegion);
|
|
101
|
+
|
|
102
|
+
this.emitter.addListener(this.eventNameForApp('appCheck_token_changed'), event => {
|
|
103
|
+
this.emitter.emit(this.eventNameForApp('onAppCheckTokenChanged'), event);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
this._listenerCount = 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
getIsTokenRefreshEnabledDefault(): boolean | undefined {
|
|
110
|
+
// no default to start
|
|
111
|
+
let isTokenAutoRefreshEnabled: boolean | undefined = undefined;
|
|
112
|
+
|
|
113
|
+
return isTokenAutoRefreshEnabled;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
newReactNativeFirebaseAppCheckProvider(): ReactNativeFirebaseAppCheckProvider {
|
|
117
|
+
return new ReactNativeFirebaseAppCheckProvider();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
initializeAppCheck(options: AppCheckOptions): Promise<void> {
|
|
121
|
+
if (isOther) {
|
|
122
|
+
if (!isObject(options)) {
|
|
123
|
+
throw new Error('Invalid configuration: no options defined.');
|
|
124
|
+
}
|
|
125
|
+
if (isUndefined(options.provider)) {
|
|
126
|
+
throw new Error('Invalid configuration: no provider defined.');
|
|
127
|
+
}
|
|
128
|
+
return this.native.initializeAppCheck(options);
|
|
129
|
+
}
|
|
130
|
+
// determine token refresh setting, if not specified
|
|
131
|
+
if (!isBoolean(options.isTokenAutoRefreshEnabled)) {
|
|
132
|
+
const tokenRefresh = this.firebaseJson.app_check_token_auto_refresh;
|
|
133
|
+
if (isBoolean(tokenRefresh)) {
|
|
134
|
+
options.isTokenAutoRefreshEnabled = tokenRefresh;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// If that was not defined, attempt to use app-wide data collection setting per docs:
|
|
139
|
+
if (!isBoolean(options.isTokenAutoRefreshEnabled)) {
|
|
140
|
+
const dataCollection = this.firebaseJson.app_data_collection_default_enabled;
|
|
141
|
+
if (isBoolean(dataCollection)) {
|
|
142
|
+
options.isTokenAutoRefreshEnabled = dataCollection;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// If that also was not defined, the default is documented as true.
|
|
147
|
+
if (!isBoolean(options.isTokenAutoRefreshEnabled)) {
|
|
148
|
+
options.isTokenAutoRefreshEnabled = true;
|
|
149
|
+
}
|
|
150
|
+
this.native.setTokenAutoRefreshEnabled(options.isTokenAutoRefreshEnabled);
|
|
151
|
+
|
|
152
|
+
if (!hasProviderOptions(options.provider)) {
|
|
153
|
+
throw new Error('Invalid configuration: no provider or no provider options defined.');
|
|
154
|
+
}
|
|
155
|
+
const provider = options.provider;
|
|
156
|
+
if (Platform.OS === 'android') {
|
|
157
|
+
if (!isString(provider.providerOptions?.android?.provider)) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
'Invalid configuration: no android provider configured while on android platform.',
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
return this.native.configureProvider(
|
|
163
|
+
provider.providerOptions.android.provider,
|
|
164
|
+
provider.providerOptions.android.debugToken,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
if (Platform.OS === 'ios' || Platform.OS === 'macos') {
|
|
168
|
+
if (!isString(provider.providerOptions?.apple?.provider)) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
'Invalid configuration: no apple provider configured while on apple platform.',
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
return this.native.configureProvider(
|
|
174
|
+
provider.providerOptions.apple.provider,
|
|
175
|
+
provider.providerOptions.apple.debugToken,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
throw new Error('Unsupported platform: ' + Platform.OS);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
activate(
|
|
182
|
+
siteKeyOrProvider: string | AppCheckProvider,
|
|
183
|
+
isTokenAutoRefreshEnabled?: boolean,
|
|
184
|
+
): Promise<void> {
|
|
185
|
+
if (isOther) {
|
|
186
|
+
throw new Error('firebase.appCheck().activate(*) is not supported on other platforms');
|
|
187
|
+
}
|
|
188
|
+
if (!isString(siteKeyOrProvider)) {
|
|
189
|
+
throw new Error('siteKeyOrProvider must be a string value to match firebase-js-sdk API');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// We wrap our new flexible interface, with compatible defaults
|
|
193
|
+
const rnfbProvider = new ReactNativeFirebaseAppCheckProvider();
|
|
194
|
+
rnfbProvider.configure({
|
|
195
|
+
android: {
|
|
196
|
+
provider: 'playIntegrity',
|
|
197
|
+
},
|
|
198
|
+
apple: {
|
|
199
|
+
provider: 'deviceCheck',
|
|
200
|
+
},
|
|
201
|
+
web: {
|
|
202
|
+
provider: 'reCaptchaV3',
|
|
203
|
+
siteKey: 'none',
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
return this.initializeAppCheck({ provider: rnfbProvider, isTokenAutoRefreshEnabled });
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// TODO this is an async call
|
|
211
|
+
setTokenAutoRefreshEnabled(isTokenAutoRefreshEnabled: boolean): void {
|
|
212
|
+
this.native.setTokenAutoRefreshEnabled(isTokenAutoRefreshEnabled);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
getToken(forceRefresh?: boolean): Promise<AppCheckTokenResult> {
|
|
216
|
+
if (!forceRefresh) {
|
|
217
|
+
return this.native.getToken(false);
|
|
218
|
+
} else {
|
|
219
|
+
return this.native.getToken(true);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
getLimitedUseToken(): Promise<AppCheckTokenResult> {
|
|
224
|
+
return this.native.getLimitedUseToken();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
onTokenChanged(
|
|
228
|
+
onNextOrObserver:
|
|
229
|
+
| PartialObserver<AppCheckListenerResult>
|
|
230
|
+
| ((tokenResult: AppCheckListenerResult) => void),
|
|
231
|
+
_onError?: (error: Error) => void,
|
|
232
|
+
_onCompletion?: () => void,
|
|
233
|
+
): () => void {
|
|
234
|
+
// iOS does not provide any native listening feature
|
|
235
|
+
if (isIOS) {
|
|
236
|
+
// eslint-disable-next-line no-console
|
|
237
|
+
console.warn('onTokenChanged is not implemented on IOS, only for Android');
|
|
238
|
+
return () => {};
|
|
239
|
+
}
|
|
240
|
+
const nextFn = parseListenerOrObserver(
|
|
241
|
+
onNextOrObserver as
|
|
242
|
+
| ((value: AppCheckListenerResult) => void)
|
|
243
|
+
| { next: (value: AppCheckListenerResult) => void },
|
|
244
|
+
);
|
|
245
|
+
// let errorFn = function () { };
|
|
246
|
+
// if (onNextOrObserver.error != null) {
|
|
247
|
+
// errorFn = onNextOrObserver.error.bind(onNextOrObserver);
|
|
248
|
+
// }
|
|
249
|
+
// else if (onError) {
|
|
250
|
+
// errorFn = onError;
|
|
251
|
+
// }
|
|
252
|
+
const subscription = this.emitter.addListener(
|
|
253
|
+
this.eventNameForApp('onAppCheckTokenChanged'),
|
|
254
|
+
nextFn,
|
|
255
|
+
);
|
|
256
|
+
if (this._listenerCount === 0) this.native.addAppCheckListener();
|
|
257
|
+
|
|
258
|
+
this._listenerCount++;
|
|
259
|
+
return () => {
|
|
260
|
+
subscription.remove();
|
|
261
|
+
this._listenerCount--;
|
|
262
|
+
if (this._listenerCount === 0) this.native.removeAppCheckListener();
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export const SDK_VERSION = version;
|
|
268
|
+
|
|
269
|
+
const appCheckNamespace = createModuleNamespace({
|
|
270
|
+
statics,
|
|
271
|
+
version,
|
|
272
|
+
namespace,
|
|
273
|
+
nativeModuleName,
|
|
274
|
+
nativeEvents: ['appCheck_token_changed'],
|
|
275
|
+
hasMultiAppSupport: true,
|
|
276
|
+
hasCustomUrlOrRegionSupport: false,
|
|
277
|
+
ModuleClass: FirebaseAppCheckModule,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
type AppCheckNamespace = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
|
|
281
|
+
AppCheck,
|
|
282
|
+
AppCheckStatics
|
|
283
|
+
> & {
|
|
284
|
+
appCheck: ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<AppCheck, AppCheckStatics>;
|
|
285
|
+
firebase: ReactNativeFirebase.Module;
|
|
286
|
+
app(name?: string): ReactNativeFirebase.FirebaseApp;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// import appCheck from '@react-native-firebase/app-check';
|
|
290
|
+
// appCheck().X(...);
|
|
291
|
+
export default appCheckNamespace as unknown as AppCheckNamespace;
|
|
292
|
+
|
|
293
|
+
// import appCheck, { firebase } from '@react-native-firebase/app-check';
|
|
294
|
+
// appCheck().X(...);
|
|
295
|
+
// firebase.appCheck().X(...);
|
|
296
|
+
export const firebase =
|
|
297
|
+
getFirebaseRoot() as unknown as ReactNativeFirebase.FirebaseNamespacedExport<
|
|
298
|
+
'appCheck',
|
|
299
|
+
AppCheck,
|
|
300
|
+
AppCheckStatics,
|
|
301
|
+
false
|
|
302
|
+
>;
|
|
303
|
+
|
|
304
|
+
// Register the interop module for non-native platforms.
|
|
305
|
+
setReactNativeModule(nativeModuleName, fallBackModule as unknown as Record<string, unknown>);
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { ReactNativeFirebase } from '@react-native-firebase/app';
|
|
19
|
+
|
|
20
|
+
// ============ Provider Types ============
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* An App Check provider. This can be either the built-in reCAPTCHA provider
|
|
24
|
+
* or a custom provider. For more on custom providers, see
|
|
25
|
+
* https://firebase.google.com/docs/app-check/web-custom-provider
|
|
26
|
+
*/
|
|
27
|
+
export interface AppCheckProvider {
|
|
28
|
+
/**
|
|
29
|
+
* Returns an AppCheck token.
|
|
30
|
+
*/
|
|
31
|
+
getToken(): Promise<AppCheckToken>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Function to get an App Check token through a custom provider service.
|
|
36
|
+
*/
|
|
37
|
+
export interface CustomProviderOptions {
|
|
38
|
+
getToken: () => Promise<AppCheckToken>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ============ Options & Result Types ============
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Custom provider class.
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export declare class CustomProvider implements AppCheckProvider {
|
|
48
|
+
constructor(customProviderOptions: CustomProviderOptions);
|
|
49
|
+
getToken(): Promise<AppCheckToken>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Options for App Check initialization.
|
|
54
|
+
*/
|
|
55
|
+
export interface AppCheckOptions {
|
|
56
|
+
/**
|
|
57
|
+
* The App Check provider to use. This can be either the built-in reCAPTCHA provider
|
|
58
|
+
* or a custom provider. For convenience, you can also pass an object with providerOptions
|
|
59
|
+
* directly, which will be accepted by the runtime.
|
|
60
|
+
*/
|
|
61
|
+
provider:
|
|
62
|
+
| CustomProvider
|
|
63
|
+
| ReactNativeFirebaseAppCheckProvider
|
|
64
|
+
| ReactNativeFirebaseAppCheckProviderConfig;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* If true, enables SDK to automatically
|
|
68
|
+
* refresh AppCheck token as needed. If undefined, the value will default
|
|
69
|
+
* to the value of `app.automaticDataCollectionEnabled`. That property
|
|
70
|
+
* defaults to false and can be set in the app config.
|
|
71
|
+
*/
|
|
72
|
+
isTokenAutoRefreshEnabled?: boolean;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The token returned from an `AppCheckProvider`.
|
|
77
|
+
*/
|
|
78
|
+
export interface AppCheckToken {
|
|
79
|
+
/**
|
|
80
|
+
* The token string in JWT format.
|
|
81
|
+
*/
|
|
82
|
+
readonly token: string;
|
|
83
|
+
/**
|
|
84
|
+
* The local timestamp after which the token will expire.
|
|
85
|
+
*/
|
|
86
|
+
readonly expireTimeMillis: number;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Result returned by `getToken()`.
|
|
91
|
+
*/
|
|
92
|
+
export interface AppCheckTokenResult {
|
|
93
|
+
/**
|
|
94
|
+
* The token string in JWT format.
|
|
95
|
+
*/
|
|
96
|
+
readonly token: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The result return from `onTokenChanged`
|
|
101
|
+
*/
|
|
102
|
+
export type AppCheckListenerResult = AppCheckToken & { readonly appName: string };
|
|
103
|
+
|
|
104
|
+
// ============ Observer Types ============
|
|
105
|
+
|
|
106
|
+
export type NextFn<T> = (value: T) => void;
|
|
107
|
+
export type ErrorFn = (error: Error) => void;
|
|
108
|
+
export type CompleteFn = () => void;
|
|
109
|
+
|
|
110
|
+
export interface Observer<T> {
|
|
111
|
+
next: NextFn<T>;
|
|
112
|
+
error: ErrorFn;
|
|
113
|
+
complete: CompleteFn;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export type PartialObserver<T> = Partial<Observer<T>>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A function that unsubscribes from token changes.
|
|
120
|
+
*/
|
|
121
|
+
export type Unsubscribe = () => void;
|
|
122
|
+
|
|
123
|
+
// ============ ReactNativeFirebaseAppCheckProvider Types ============
|
|
124
|
+
|
|
125
|
+
export interface ReactNativeFirebaseAppCheckProviderOptions {
|
|
126
|
+
/**
|
|
127
|
+
* debug token to use, if any. Defaults to undefined, pre-configure tokens in firebase web console if needed
|
|
128
|
+
*/
|
|
129
|
+
debugToken?: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface ReactNativeFirebaseAppCheckProviderWebOptions extends ReactNativeFirebaseAppCheckProviderOptions {
|
|
133
|
+
/**
|
|
134
|
+
* The web provider to use, either `reCaptchaV3` or `reCaptchaEnterprise`, defaults to `reCaptchaV3`
|
|
135
|
+
*/
|
|
136
|
+
provider?: 'debug' | 'reCaptchaV3' | 'reCaptchaEnterprise';
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* siteKey for use in web queries, defaults to `none`
|
|
140
|
+
*/
|
|
141
|
+
siteKey?: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface ReactNativeFirebaseAppCheckProviderAppleOptions extends ReactNativeFirebaseAppCheckProviderOptions {
|
|
145
|
+
/**
|
|
146
|
+
* The apple provider to use, either `deviceCheck` or `appAttest`, or `appAttestWithDeviceCheckFallback`,
|
|
147
|
+
* defaults to `DeviceCheck`. `appAttest` requires iOS 14+ or will fail, `appAttestWithDeviceCheckFallback`
|
|
148
|
+
* will use `appAttest` for iOS14+ and fallback to `deviceCheck` on devices with ios13 and lower
|
|
149
|
+
*/
|
|
150
|
+
provider?: 'debug' | 'deviceCheck' | 'appAttest' | 'appAttestWithDeviceCheckFallback';
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface ReactNativeFirebaseAppCheckProviderAndroidOptions extends ReactNativeFirebaseAppCheckProviderOptions {
|
|
154
|
+
/**
|
|
155
|
+
* The android provider to use, either `debug` or `playIntegrity`. default is `playIntegrity`.
|
|
156
|
+
*/
|
|
157
|
+
provider?: 'debug' | 'playIntegrity';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Platform-specific provider options configuration.
|
|
162
|
+
*/
|
|
163
|
+
export type ReactNativeFirebaseAppCheckProviderOptionsMap = {
|
|
164
|
+
web?: ReactNativeFirebaseAppCheckProviderWebOptions;
|
|
165
|
+
android?: ReactNativeFirebaseAppCheckProviderAndroidOptions;
|
|
166
|
+
apple?: ReactNativeFirebaseAppCheckProviderAppleOptions;
|
|
167
|
+
isTokenAutoRefreshEnabled?: boolean;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Configuration object for ReactNativeFirebaseAppCheckProvider
|
|
172
|
+
* that can be passed directly with providerOptions (for convenience in initialization).
|
|
173
|
+
* The runtime accepts objects with providerOptions even if they don't have
|
|
174
|
+
* getToken() and configure() methods.
|
|
175
|
+
*/
|
|
176
|
+
export interface ReactNativeFirebaseAppCheckProviderConfig {
|
|
177
|
+
providerOptions: ReactNativeFirebaseAppCheckProviderOptionsMap;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export interface ReactNativeFirebaseAppCheckProvider extends AppCheckProvider {
|
|
181
|
+
/**
|
|
182
|
+
* Provider options for platform-specific configuration.
|
|
183
|
+
* This is set when configure() is called.
|
|
184
|
+
*/
|
|
185
|
+
providerOptions?: ReactNativeFirebaseAppCheckProviderOptionsMap;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Specify how the app check provider should be configured. The new configuration is
|
|
189
|
+
* in effect when this call returns. You must call `getToken()`
|
|
190
|
+
* after this call to get a token using the new configuration.
|
|
191
|
+
* This custom provider allows for delayed configuration and re-configuration on all platforms
|
|
192
|
+
* so AppCheck has the same experience across all platforms, with the only difference being the native
|
|
193
|
+
* providers you choose to use on each platform.
|
|
194
|
+
*/
|
|
195
|
+
configure(options: ReactNativeFirebaseAppCheckProviderOptionsMap): void;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Type representing providers that have providerOptions.
|
|
200
|
+
* Used for type narrowing in runtime code.
|
|
201
|
+
*/
|
|
202
|
+
export type ProviderWithOptions =
|
|
203
|
+
| ReactNativeFirebaseAppCheckProvider
|
|
204
|
+
| ReactNativeFirebaseAppCheckProviderConfig;
|
|
205
|
+
|
|
206
|
+
// ============ Module Interface ============
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* App Check module instance - returned from firebase.appCheck() or firebase.app().appCheck()
|
|
210
|
+
*/
|
|
211
|
+
export interface AppCheck extends ReactNativeFirebase.FirebaseModule {
|
|
212
|
+
/** The FirebaseApp this module is associated with */
|
|
213
|
+
app: ReactNativeFirebase.FirebaseApp;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Create a ReactNativeFirebaseAppCheckProvider option for use in react-native-firebase
|
|
217
|
+
*/
|
|
218
|
+
newReactNativeFirebaseAppCheckProvider(): ReactNativeFirebaseAppCheckProvider;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Initialize the AppCheck module. Note that in react-native-firebase AppCheckOptions must always
|
|
222
|
+
* be an object with a `provider` member containing `ReactNativeFirebaseAppCheckProvider` that has returned successfully
|
|
223
|
+
* from a call to the `configure` method, with sub-providers for the various platforms configured to meet your project
|
|
224
|
+
* requirements. This must be called prior to interacting with any firebase services protected by AppCheck
|
|
225
|
+
*
|
|
226
|
+
* @param options an AppCheckOptions with a configured ReactNativeFirebaseAppCheckProvider as the provider
|
|
227
|
+
*/
|
|
228
|
+
initializeAppCheck(options: AppCheckOptions): Promise<void>;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Activate App Check
|
|
232
|
+
* On iOS App Check is activated with DeviceCheck provider simply by including the module, using the token auto refresh default or
|
|
233
|
+
* the specific value (if configured) in firebase.json, but calling this does no harm.
|
|
234
|
+
* On Android if you call this it will install the PlayIntegrity provider in release builds, the Debug provider if debuggable.
|
|
235
|
+
* On both platforms you may use this method to alter the token refresh setting after startup.
|
|
236
|
+
* On iOS if you want to set a specific AppCheckProviderFactory (for instance to FIRAppCheckDebugProviderFactory or
|
|
237
|
+
* FIRAppAttestProvider) you must manually do that in your AppDelegate.m prior to calling [FIRApp configure]
|
|
238
|
+
*
|
|
239
|
+
* @deprecated use initializeAppCheck to gain access to all platform providers and firebase-js-sdk v9 compatibility
|
|
240
|
+
* @param siteKeyOrProvider - This is ignored, Android uses DebugProviderFactory if the app is debuggable (https://firebase.google.com/docs/app-check/android/debug-provider)
|
|
241
|
+
* Android uses PlayIntegrityProviderFactory for release builds.
|
|
242
|
+
* iOS uses DeviceCheckProviderFactory by default unless altered in AppDelegate.m manually
|
|
243
|
+
* @param isTokenAutoRefreshEnabled - If true, enables SDK to automatically
|
|
244
|
+
* refresh AppCheck token as needed. If undefined, the value will default
|
|
245
|
+
* to the value of `app.automaticDataCollectionEnabled`. That property
|
|
246
|
+
* defaults to false and can be set in the app config.
|
|
247
|
+
*/
|
|
248
|
+
activate(
|
|
249
|
+
siteKeyOrProvider: string | AppCheckProvider,
|
|
250
|
+
isTokenAutoRefreshEnabled?: boolean,
|
|
251
|
+
): Promise<void>;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Alter the token auto refresh setting. By default it will take the value of automaticDataCollectionEnabled from Info.plist / AndroidManifest.xml
|
|
255
|
+
* @param isTokenAutoRefreshEnabled - If true, the SDK automatically
|
|
256
|
+
* refreshes App Check tokens as needed. This overrides any value set
|
|
257
|
+
* during `activate()` or taken by default from automaticDataCollectionEnabled in plist / android manifest
|
|
258
|
+
*/
|
|
259
|
+
setTokenAutoRefreshEnabled(isTokenAutoRefreshEnabled: boolean): void;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Requests Firebase App Check token.
|
|
263
|
+
* This method should only be used if you need to authorize requests to a non-Firebase backend.
|
|
264
|
+
* Requests to Firebase backend are authorized automatically if configured.
|
|
265
|
+
*
|
|
266
|
+
* @param forceRefresh - If true, a new Firebase App Check token is requested and the token cache is ignored.
|
|
267
|
+
* If false, the cached token is used if it exists and has not expired yet.
|
|
268
|
+
* In most cases, false should be used. True should only be used if the server explicitly returns an error, indicating a revoked token.
|
|
269
|
+
*/
|
|
270
|
+
getToken(forceRefresh?: boolean): Promise<AppCheckTokenResult>;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Requests a Firebase App Check token. This method should be used only if you need to authorize requests
|
|
274
|
+
* to a non-Firebase backend. Returns limited-use tokens that are intended for use with your non-Firebase
|
|
275
|
+
* backend endpoints that are protected with Replay Protection (https://firebase.google.com/docs/app-check/custom-resource-backend#replay-protection).
|
|
276
|
+
* This method does not affect the token generation behavior of the getAppCheckToken() method.
|
|
277
|
+
*/
|
|
278
|
+
getLimitedUseToken(): Promise<AppCheckTokenResult>;
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Registers a listener to changes in the token state. There can be more
|
|
282
|
+
* than one listener registered at the same time for one or more
|
|
283
|
+
* App Check instances. The listeners call back on the UI thread whenever
|
|
284
|
+
* the current token associated with this App Check instance changes.
|
|
285
|
+
*
|
|
286
|
+
* @returns A function that unsubscribes this listener.
|
|
287
|
+
*/
|
|
288
|
+
onTokenChanged(observer: PartialObserver<AppCheckListenerResult>): () => void;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Registers a listener to changes in the token state. There can be more
|
|
292
|
+
* than one listener registered at the same time for one or more
|
|
293
|
+
* App Check instances. The listeners call back on the UI thread whenever
|
|
294
|
+
* the current token associated with this App Check instance changes.
|
|
295
|
+
*
|
|
296
|
+
* Token listeners do not exist in the native SDK for iOS, no token change events will be emitted on that platform.
|
|
297
|
+
* This is not yet implemented on Android, no token change events will be emitted until implemented.
|
|
298
|
+
*
|
|
299
|
+
* NOTE: Although an `onError` callback can be provided, it will
|
|
300
|
+
* never be called, Android sdk code doesn't provide handling for onError function
|
|
301
|
+
*
|
|
302
|
+
* NOTE: Although an `onCompletion` callback can be provided, it will
|
|
303
|
+
* never be called because the token stream is never-ending.
|
|
304
|
+
*
|
|
305
|
+
* @returns A function that unsubscribes this listener.
|
|
306
|
+
*/
|
|
307
|
+
onTokenChanged(
|
|
308
|
+
onNext: (tokenResult: AppCheckListenerResult) => void,
|
|
309
|
+
onError?: (error: Error) => void,
|
|
310
|
+
onCompletion?: () => void,
|
|
311
|
+
): () => void;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// ============ Statics Interface ============
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Static properties available on firebase.appCheck
|
|
318
|
+
*/
|
|
319
|
+
export interface AppCheckStatics {
|
|
320
|
+
CustomProvider: new (customProviderOptions: CustomProviderOptions) => CustomProvider;
|
|
321
|
+
SDK_VERSION: string;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* FirebaseApp type with appCheck() method.
|
|
326
|
+
* @deprecated Import FirebaseApp from '@react-native-firebase/app' instead.
|
|
327
|
+
* The appCheck() method is added via module augmentation.
|
|
328
|
+
*/
|
|
329
|
+
export type FirebaseApp = ReactNativeFirebase.FirebaseApp;
|
|
330
|
+
|
|
331
|
+
// ============ Module Augmentation ============
|
|
332
|
+
|
|
333
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
334
|
+
declare module '@react-native-firebase/app' {
|
|
335
|
+
namespace ReactNativeFirebase {
|
|
336
|
+
interface Module {
|
|
337
|
+
appCheck: FirebaseModuleWithStaticsAndApp<AppCheck, AppCheckStatics>;
|
|
338
|
+
}
|
|
339
|
+
interface FirebaseApp {
|
|
340
|
+
appCheck(): AppCheck;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/* eslint-enable @typescript-eslint/no-namespace */
|
|
345
|
+
|
|
346
|
+
// ============ Backwards Compatibility Namespace ============
|
|
347
|
+
|
|
348
|
+
// Helper types to reference outer scope types within the namespace
|
|
349
|
+
// These are needed because TypeScript can't directly alias types with the same name
|
|
350
|
+
type _AppCheckProvider = AppCheckProvider;
|
|
351
|
+
type _CustomProviderOptions = CustomProviderOptions;
|
|
352
|
+
type _AppCheckOptions = AppCheckOptions;
|
|
353
|
+
type _AppCheckToken = AppCheckToken;
|
|
354
|
+
type _AppCheckTokenResult = AppCheckTokenResult;
|
|
355
|
+
type _AppCheckListenerResult = AppCheckListenerResult;
|
|
356
|
+
type _AppCheck = AppCheck;
|
|
357
|
+
type _AppCheckStatics = AppCheckStatics;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* @deprecated Use the exported types directly instead.
|
|
361
|
+
* FirebaseAppCheckTypes namespace is kept for backwards compatibility.
|
|
362
|
+
*/
|
|
363
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
364
|
+
export namespace FirebaseAppCheckTypes {
|
|
365
|
+
// Short name aliases referencing top-level types
|
|
366
|
+
export type Provider = AppCheckProvider;
|
|
367
|
+
export type ProviderOptions = CustomProviderOptions;
|
|
368
|
+
export type Options = AppCheckOptions;
|
|
369
|
+
export type Token = AppCheckToken;
|
|
370
|
+
export type TokenResult = AppCheckTokenResult;
|
|
371
|
+
export type ListenerResult = AppCheckListenerResult;
|
|
372
|
+
export type Statics = AppCheckStatics;
|
|
373
|
+
export type Module = AppCheck;
|
|
374
|
+
|
|
375
|
+
// AppCheck* aliases that reference the exported types above via helper types
|
|
376
|
+
// These provide backwards compatibility for code using FirebaseAppCheckTypes.AppCheckProvider
|
|
377
|
+
export type AppCheckProvider = _AppCheckProvider;
|
|
378
|
+
export type CustomProviderOptions = _CustomProviderOptions;
|
|
379
|
+
export type AppCheckOptions = _AppCheckOptions;
|
|
380
|
+
export type AppCheckToken = _AppCheckToken;
|
|
381
|
+
export type AppCheckTokenResult = _AppCheckTokenResult;
|
|
382
|
+
export type AppCheckListenerResult = _AppCheckListenerResult;
|
|
383
|
+
export type AppCheck = _AppCheck;
|
|
384
|
+
export type AppCheckStatics = _AppCheckStatics;
|
|
385
|
+
}
|
|
386
|
+
/* eslint-enable @typescript-eslint/no-namespace */
|
package/lib/version.ts
ADDED