@react-native-firebase/app-check 20.0.0 → 20.2.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/CHANGELOG.md +10 -0
- package/lib/index.d.ts +24 -6
- package/lib/index.js +47 -3
- package/lib/version.js +1 -1
- package/lib/web/RNFBAppCheckModule.android.js +2 -0
- package/lib/web/RNFBAppCheckModule.ios.js +2 -0
- package/lib/web/RNFBAppCheckModule.js +95 -0
- package/package.json +4 -4
- package/type-test.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [20.2.0](https://github.com/invertase/react-native-firebase/compare/v20.1.0...v20.2.0) (2024-07-15)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **Other:** add App Check support ([#7905](https://github.com/invertase/react-native-firebase/issues/7905)) ([753b16e](https://github.com/invertase/react-native-firebase/commit/753b16e1a06f949c679fb75053c319394dd5ecfe))
|
|
11
|
+
|
|
12
|
+
## [20.1.0](https://github.com/invertase/react-native-firebase/compare/v20.0.0...v20.1.0) (2024-06-04)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @react-native-firebase/app-check
|
|
15
|
+
|
|
6
16
|
## [20.0.0](https://github.com/invertase/react-native-firebase/compare/v19.3.0...v20.0.0) (2024-05-20)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @react-native-firebase/app-check
|
package/lib/index.d.ts
CHANGED
|
@@ -68,16 +68,30 @@ export namespace FirebaseAppCheckTypes {
|
|
|
68
68
|
getToken(): Promise<AppCheckToken>;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Custom provider class.
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
export class CustomProvider implements AppCheckProvider {
|
|
76
|
+
constructor(customProviderOptions: CustomProviderOptions);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface CustomProviderOptions {
|
|
80
|
+
/**
|
|
81
|
+
* Function to get an App Check token through a custom provider
|
|
82
|
+
* service.
|
|
83
|
+
*/
|
|
84
|
+
getToken: () => Promise<AppCheckToken>;
|
|
85
|
+
}
|
|
71
86
|
/**
|
|
72
87
|
* Options for App Check initialization.
|
|
73
88
|
*/
|
|
74
89
|
export interface AppCheckOptions {
|
|
75
90
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* implementation of an AppCheck CustomProvider
|
|
91
|
+
* The App Check provider to use. This can be either the built-in reCAPTCHA provider
|
|
92
|
+
* or a custom provider.
|
|
79
93
|
*/
|
|
80
|
-
provider: CustomProvider
|
|
94
|
+
provider: CustomProvider;
|
|
81
95
|
|
|
82
96
|
/**
|
|
83
97
|
* If true, enables SDK to automatically
|
|
@@ -185,6 +199,7 @@ export namespace FirebaseAppCheckTypes {
|
|
|
185
199
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
186
200
|
export interface Statics {
|
|
187
201
|
// firebase.appCheck.* static props go here
|
|
202
|
+
CustomProvider: typeof CustomProvider;
|
|
188
203
|
}
|
|
189
204
|
|
|
190
205
|
/**
|
|
@@ -210,18 +225,19 @@ export namespace FirebaseAppCheckTypes {
|
|
|
210
225
|
*/
|
|
211
226
|
export class Module extends FirebaseModule {
|
|
212
227
|
/**
|
|
213
|
-
*
|
|
228
|
+
* Create a ReactNativeFirebaseAppCheckProvider option for use in react-native-firebase
|
|
214
229
|
*/
|
|
215
230
|
newReactNativeFirebaseAppCheckProvider(): ReactNativeFirebaseAppCheckProvider;
|
|
216
231
|
|
|
217
232
|
/**
|
|
218
|
-
*
|
|
233
|
+
* Initialize the AppCheck module. Note that in react-native-firebase AppCheckOptions must always
|
|
219
234
|
* be an object with a `provider` member containing `ReactNativeFirebaseAppCheckProvider` that has returned successfully
|
|
220
235
|
* from a call to the `configure` method, with sub-providers for the various platforms configured to meet your project
|
|
221
236
|
* requirements. This must be called prior to interacting with any firebase services protected by AppCheck
|
|
222
237
|
*
|
|
223
238
|
* @param options an AppCheckOptions with a configured ReactNativeFirebaseAppCheckProvider as the provider
|
|
224
239
|
*/
|
|
240
|
+
// TODO wrong types
|
|
225
241
|
initializeAppCheck(options: AppCheckOptions): Promise<void>;
|
|
226
242
|
|
|
227
243
|
/**
|
|
@@ -282,6 +298,7 @@ export namespace FirebaseAppCheckTypes {
|
|
|
282
298
|
*
|
|
283
299
|
* @returns A function that unsubscribes this listener.
|
|
284
300
|
*/
|
|
301
|
+
// TODO wrong types
|
|
285
302
|
onTokenChanged(observer: PartialObserver<AppCheckListenerResult>): () => void;
|
|
286
303
|
|
|
287
304
|
/**
|
|
@@ -301,6 +318,7 @@ export namespace FirebaseAppCheckTypes {
|
|
|
301
318
|
*
|
|
302
319
|
* @returns A function that unsubscribes this listener.
|
|
303
320
|
*/
|
|
321
|
+
// TODO wrong types
|
|
304
322
|
onTokenChanged(
|
|
305
323
|
onNext: (tokenResult: AppCheckListenerResult) => void,
|
|
306
324
|
onError?: (error: Error) => void,
|
package/lib/index.js
CHANGED
|
@@ -15,7 +15,15 @@
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
isBoolean,
|
|
20
|
+
isIOS,
|
|
21
|
+
isString,
|
|
22
|
+
isObject,
|
|
23
|
+
isFunction,
|
|
24
|
+
isUndefined,
|
|
25
|
+
isOther,
|
|
26
|
+
} from '@react-native-firebase/app/lib/common';
|
|
19
27
|
import {
|
|
20
28
|
createModuleNamespace,
|
|
21
29
|
FirebaseModule,
|
|
@@ -23,6 +31,8 @@ import {
|
|
|
23
31
|
} from '@react-native-firebase/app/lib/internal';
|
|
24
32
|
import { Platform } from 'react-native';
|
|
25
33
|
import ReactNativeFirebaseAppCheckProvider from './ReactNativeFirebaseAppCheckProvider';
|
|
34
|
+
import { setReactNativeModule } from '@react-native-firebase/app/lib/internal/nativeModule';
|
|
35
|
+
import fallBackModule from './web/RNFBAppCheckModule';
|
|
26
36
|
|
|
27
37
|
import version from './version';
|
|
28
38
|
|
|
@@ -34,12 +44,30 @@ export {
|
|
|
34
44
|
setTokenAutoRefreshEnabled,
|
|
35
45
|
} from './modular/index';
|
|
36
46
|
|
|
37
|
-
const statics = {};
|
|
38
|
-
|
|
39
47
|
const namespace = 'appCheck';
|
|
40
48
|
|
|
41
49
|
const nativeModuleName = 'RNFBAppCheckModule';
|
|
42
50
|
|
|
51
|
+
export class CustomProvider {
|
|
52
|
+
constructor(_customProviderOptions) {
|
|
53
|
+
if (!isObject(_customProviderOptions)) {
|
|
54
|
+
throw new Error('Invalid configuration: no provider options defined.');
|
|
55
|
+
}
|
|
56
|
+
if (!isFunction(_customProviderOptions.getToken)) {
|
|
57
|
+
throw new Error('Invalid configuration: no getToken function defined.');
|
|
58
|
+
}
|
|
59
|
+
this._customProviderOptions = _customProviderOptions;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async getToken() {
|
|
63
|
+
return this._customProviderOptions.getToken();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const statics = {
|
|
68
|
+
CustomProvider,
|
|
69
|
+
};
|
|
70
|
+
|
|
43
71
|
class FirebaseAppCheckModule extends FirebaseModule {
|
|
44
72
|
constructor(...args) {
|
|
45
73
|
super(...args);
|
|
@@ -63,6 +91,15 @@ class FirebaseAppCheckModule extends FirebaseModule {
|
|
|
63
91
|
}
|
|
64
92
|
|
|
65
93
|
initializeAppCheck(options) {
|
|
94
|
+
if (isOther) {
|
|
95
|
+
if (!isObject(options)) {
|
|
96
|
+
throw new Error('Invalid configuration: no options defined.');
|
|
97
|
+
}
|
|
98
|
+
if (isUndefined(options.provider)) {
|
|
99
|
+
throw new Error('Invalid configuration: no provider defined.');
|
|
100
|
+
}
|
|
101
|
+
return this.native.initializeAppCheck(options);
|
|
102
|
+
}
|
|
66
103
|
// determine token refresh setting, if not specified
|
|
67
104
|
if (!isBoolean(options.isTokenAutoRefreshEnabled)) {
|
|
68
105
|
options.isTokenAutoRefreshEnabled = this.firebaseJson.app_check_token_auto_refresh;
|
|
@@ -108,6 +145,9 @@ class FirebaseAppCheckModule extends FirebaseModule {
|
|
|
108
145
|
}
|
|
109
146
|
|
|
110
147
|
activate(siteKeyOrProvider, isTokenAutoRefreshEnabled) {
|
|
148
|
+
if (isOther) {
|
|
149
|
+
throw new Error('firebase.appCheck().activate(*) is not supported on other platforms');
|
|
150
|
+
}
|
|
111
151
|
if (!isString(siteKeyOrProvider)) {
|
|
112
152
|
throw new Error('siteKeyOrProvider must be a string value to match firebase-js-sdk API');
|
|
113
153
|
}
|
|
@@ -130,6 +170,7 @@ class FirebaseAppCheckModule extends FirebaseModule {
|
|
|
130
170
|
return this.initializeAppCheck({ provider: rnfbProvider, isTokenAutoRefreshEnabled });
|
|
131
171
|
}
|
|
132
172
|
|
|
173
|
+
// TODO this is an async call
|
|
133
174
|
setTokenAutoRefreshEnabled(isTokenAutoRefreshEnabled) {
|
|
134
175
|
this.native.setTokenAutoRefreshEnabled(isTokenAutoRefreshEnabled);
|
|
135
176
|
}
|
|
@@ -203,3 +244,6 @@ export default createModuleNamespace({
|
|
|
203
244
|
// appCheck().X(...);
|
|
204
245
|
// firebase.appCheck().X(...);
|
|
205
246
|
export const firebase = getFirebaseRoot();
|
|
247
|
+
|
|
248
|
+
// Register the interop module for non-native platforms.
|
|
249
|
+
setReactNativeModule(nativeModuleName, fallBackModule);
|
package/lib/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
module.exports = '20.
|
|
2
|
+
module.exports = '20.2.0';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getApp,
|
|
3
|
+
initializeAppCheck,
|
|
4
|
+
getToken,
|
|
5
|
+
getLimitedUseToken,
|
|
6
|
+
setTokenAutoRefreshEnabled,
|
|
7
|
+
CustomProvider,
|
|
8
|
+
onTokenChanged,
|
|
9
|
+
makeIDBAvailable,
|
|
10
|
+
} from '@react-native-firebase/app/lib/internal/web/firebaseAppCheck';
|
|
11
|
+
import { guard, emitEvent } from '@react-native-firebase/app/lib/internal/web/utils';
|
|
12
|
+
|
|
13
|
+
let appCheckInstances = {};
|
|
14
|
+
let listenersForApp = {};
|
|
15
|
+
|
|
16
|
+
function getAppCheckInstanceForApp(appName) {
|
|
17
|
+
if (!appCheckInstances[appName]) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
`firebase AppCheck instance for app ${appName} has not been initialized, ensure you have called initializeAppCheck() first.`,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
return appCheckInstances[appName];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* This is a 'NativeModule' for the web platform.
|
|
27
|
+
* Methods here are identical to the ones found in
|
|
28
|
+
* the native android/ios modules e.g. `@ReactMethod` annotated
|
|
29
|
+
* java methods on Android.
|
|
30
|
+
*/
|
|
31
|
+
export default {
|
|
32
|
+
initializeAppCheck(appName, options) {
|
|
33
|
+
makeIDBAvailable();
|
|
34
|
+
return guard(async () => {
|
|
35
|
+
if (appCheckInstances[appName]) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const { provider, isTokenAutoRefreshEnabled } = options;
|
|
39
|
+
const _provider = new CustomProvider({
|
|
40
|
+
getToken() {
|
|
41
|
+
return provider.getToken();
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
appCheckInstances[appName] = initializeAppCheck(getApp(appName), {
|
|
45
|
+
provider: _provider,
|
|
46
|
+
isTokenAutoRefreshEnabled,
|
|
47
|
+
});
|
|
48
|
+
return null;
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
setTokenAutoRefreshEnabled(appName, isTokenAutoRefreshEnabled) {
|
|
52
|
+
return guard(async () => {
|
|
53
|
+
const instance = getAppCheckInstanceForApp(appName);
|
|
54
|
+
setTokenAutoRefreshEnabled(instance, isTokenAutoRefreshEnabled);
|
|
55
|
+
return null;
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
getLimitedUseToken(appName) {
|
|
59
|
+
return guard(async () => {
|
|
60
|
+
const instance = getAppCheckInstanceForApp(appName);
|
|
61
|
+
return getLimitedUseToken(instance);
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
getToken(appName, forceRefresh) {
|
|
65
|
+
return guard(async () => {
|
|
66
|
+
const instance = getAppCheckInstanceForApp(appName);
|
|
67
|
+
return getToken(instance, forceRefresh);
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
addAppCheckListener(appName) {
|
|
71
|
+
return guard(async () => {
|
|
72
|
+
if (listenersForApp[appName]) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const instance = getAppCheckInstanceForApp(appName);
|
|
76
|
+
listenersForApp[appName] = onTokenChanged(instance, tokenResult => {
|
|
77
|
+
emitEvent('appCheck_token_changed', {
|
|
78
|
+
appName,
|
|
79
|
+
...tokenResult,
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
return null;
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
removeAppCheckListener(appName) {
|
|
86
|
+
return guard(async () => {
|
|
87
|
+
if (!listenersForApp[appName]) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
listenersForApp[appName]();
|
|
91
|
+
delete listenersForApp[appName];
|
|
92
|
+
return null;
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-firebase/app-check",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.2.0",
|
|
4
4
|
"author": "Invertase <oss@invertase.io> (http://invertase.io)",
|
|
5
5
|
"description": "React Native Firebase - App Check",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"appCheck"
|
|
26
26
|
],
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@react-native-firebase/app": "20.
|
|
28
|
+
"@react-native-firebase/app": "20.2.0",
|
|
29
29
|
"expo": ">=47.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"expo": "^50.0.
|
|
32
|
+
"expo": "^50.0.19"
|
|
33
33
|
},
|
|
34
34
|
"peerDependenciesMeta": {
|
|
35
35
|
"expo": {
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "82c50138d07e673213cd8dee5ce9a2f9b5656649"
|
|
43
43
|
}
|