@react-native-firebase/app-check 17.1.0 → 17.3.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 CHANGED
@@ -3,6 +3,28 @@
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
+ ## [17.3.0](https://github.com/invertase/react-native-firebase/compare/v17.2.0...v17.3.0) (2023-02-15)
7
+
8
+ ### Features
9
+
10
+ - **app-check:** Expose modular API that matches the Firebase web JS SDK v9 API ([#6912](https://github.com/invertase/react-native-firebase/issues/6912)) ([bf02676](https://github.com/invertase/react-native-firebase/commit/bf0267609251a5b8e4245c300678fe7d7ea53d92))
11
+
12
+ ### Bug Fixes
13
+
14
+ - **app-check, types:** Correct ReactNativeFirebaseAppCheckProvider options type ([#6911](https://github.com/invertase/react-native-firebase/issues/6911)) ([5d7241b](https://github.com/invertase/react-native-firebase/commit/5d7241b124dc283852efb4c549f6888005101ecd))
15
+
16
+ ## [17.2.0](https://github.com/invertase/react-native-firebase/compare/v17.1.0...v17.2.0) (2023-02-15)
17
+
18
+ ### Features
19
+
20
+ - **app, android:** firebase-android-sdk 31.2.0 ([87156e7](https://github.com/invertase/react-native-firebase/commit/87156e75e16775db14ef8f9bf6b0049b15ee1277))
21
+
22
+ ### Bug Fixes
23
+
24
+ - **app-check, ios:** debugToken in config on iOS works now ([04615e5](https://github.com/invertase/react-native-firebase/commit/04615e5568af549fb79d8b1ed59dbbce29ddb5f9))
25
+ - **app-check, types:** add `newReactNativeFirebaseAppCheckProvider` function type ([9f5f231](https://github.com/invertase/react-native-firebase/commit/9f5f231e06ebe3f75e553b898eef173395954ae8))
26
+ - **app-check:** better validation of configuration ([df60d83](https://github.com/invertase/react-native-firebase/commit/df60d834c897e55c7c62b4850be12a2a396ac21f))
27
+
6
28
  ## [17.1.0](https://github.com/invertase/react-native-firebase/compare/v17.0.0...v17.1.0) (2023-02-09)
7
29
 
8
30
  **Note:** Version bump only for package @react-native-firebase/app-check
@@ -20,4 +20,10 @@ describe('appCheck()', function () {
20
20
  );
21
21
  });
22
22
  });
23
+
24
+ describe('react-native-firebase provider', function () {
25
+ it('correctly creates a provider instance', function () {
26
+ expect(firebase.appCheck().newReactNativeFirebaseAppCheckProvider()).toBeDefined();
27
+ });
28
+ });
23
29
  });
@@ -18,15 +18,19 @@ package io.invertase.firebase.appcheck;
18
18
  */
19
19
 
20
20
  import android.util.Log;
21
+ import androidx.annotation.NonNull;
21
22
  import com.google.android.gms.tasks.Task;
22
23
  import com.google.firebase.FirebaseApp;
23
24
  import com.google.firebase.appcheck.AppCheckProvider;
24
- import com.google.firebase.appcheck.AppCheckProviderFactory;
25
25
  import com.google.firebase.appcheck.AppCheckToken;
26
26
  import com.google.firebase.appcheck.debug.DebugAppCheckProviderFactory;
27
+ import com.google.firebase.appcheck.debug.InternalDebugSecretProvider;
28
+ import com.google.firebase.appcheck.debug.internal.DebugAppCheckProvider;
27
29
  import com.google.firebase.appcheck.playintegrity.PlayIntegrityAppCheckProviderFactory;
28
30
  import com.google.firebase.appcheck.safetynet.SafetyNetAppCheckProviderFactory;
29
- import java.lang.reflect.Constructor;
31
+ import com.google.firebase.inject.Provider;
32
+ import java.util.concurrent.ExecutorService;
33
+ import java.util.concurrent.Executors;
30
34
 
31
35
  // Facade for all possible provider factory delegates,
32
36
  // configurable dynamically instead of at startup
@@ -35,6 +39,7 @@ public class ReactNativeFirebaseAppCheckProvider implements AppCheckProvider {
35
39
 
36
40
  AppCheckProvider delegateProvider;
37
41
 
42
+ @NonNull
38
43
  @Override
39
44
  public Task<AppCheckToken> getToken() {
40
45
  Log.d(LOGTAG, "Provider::getToken - delegating to native provider");
@@ -58,13 +63,25 @@ public class ReactNativeFirebaseAppCheckProvider implements AppCheckProvider {
58
63
 
59
64
  // the debug configuration may have a token, or may not
60
65
  if (debugToken != null) {
61
- // Create a debug provider using hidden factory constructor and our debug token
62
- Class<DebugAppCheckProviderFactory> debugACFactoryClass =
63
- DebugAppCheckProviderFactory.class;
64
- Class<?>[] argType = {String.class};
65
- Constructor c = debugACFactoryClass.getDeclaredConstructor(argType);
66
- Object[] cArgs = {debugToken};
67
- delegateProvider = ((AppCheckProviderFactory) c.newInstance(cArgs)).create(app);
66
+ // To use this token, create debug provider using local secret provider + standard thread
67
+ // pool
68
+ ExecutorService executor = Executors.newCachedThreadPool();
69
+ delegateProvider =
70
+ new DebugAppCheckProvider(
71
+ app,
72
+ new Provider<InternalDebugSecretProvider>() {
73
+ public InternalDebugSecretProvider get() {
74
+ return new InternalDebugSecretProvider() {
75
+ public String getDebugSecret() {
76
+ return debugToken;
77
+ }
78
+ };
79
+ }
80
+ },
81
+ executor,
82
+ executor,
83
+ executor);
84
+
68
85
  } else {
69
86
  delegateProvider = DebugAppCheckProviderFactory.getInstance().create(app);
70
87
  }
@@ -18,17 +18,17 @@ package io.invertase.firebase.appcheck;
18
18
  */
19
19
 
20
20
  import android.util.Log;
21
+ import androidx.annotation.NonNull;
21
22
  import com.google.firebase.FirebaseApp;
22
23
  import com.google.firebase.appcheck.AppCheckProvider;
23
24
  import com.google.firebase.appcheck.AppCheckProviderFactory;
24
25
  import java.util.HashMap;
25
- import java.util.Map;
26
26
 
27
27
  public class ReactNativeFirebaseAppCheckProviderFactory implements AppCheckProviderFactory {
28
28
  private static final String LOGTAG = "RNFBAppCheck";
29
29
 
30
30
  // This object has one job - create + maintain control over one provider per app
31
- public Map<String, ReactNativeFirebaseAppCheckProvider> providers = new HashMap();
31
+ public HashMap<String, ReactNativeFirebaseAppCheckProvider> providers = new HashMap<>();
32
32
 
33
33
  // Our provider will serve as a facade to all the supported native providers,
34
34
  // we will just pass through configuration calls to it
@@ -41,7 +41,7 @@ public class ReactNativeFirebaseAppCheckProviderFactory implements AppCheckProvi
41
41
  + providerName
42
42
  + (debugToken != null ? "/(not shown)" : "/null"));
43
43
 
44
- ReactNativeFirebaseAppCheckProvider provider = null;
44
+ ReactNativeFirebaseAppCheckProvider provider;
45
45
 
46
46
  // Look up the correct provider for the given appName, create it if not created
47
47
  provider = providers.get(appName);
@@ -52,6 +52,7 @@ public class ReactNativeFirebaseAppCheckProviderFactory implements AppCheckProvi
52
52
  provider.configure(appName, providerName, debugToken);
53
53
  }
54
54
 
55
+ @NonNull
55
56
  public AppCheckProvider create(FirebaseApp firebaseApp) {
56
57
  String appName = firebaseApp.getName();
57
58
  Log.d(LOGTAG, "ProviderFactory::create - fetching provider for app " + appName);
@@ -38,18 +38,14 @@
38
38
 
39
39
  // - determine if debugToken is provided via nullable arg
40
40
  if ([providerName isEqualToString:@"debug"]) {
41
- // TODO: Currently not handling debugToken argument, relying on existing environment
42
- // variable configuration style.
43
- // - maybe directly setting an environment variable could work?
44
- // https://stackoverflow.com/questions/27139589/whats-the-idiomatic-way-of-setting-an-environment-variable-in-objective-c-coco
45
- // - ...otherwise if env var does not work
46
- // - subclass style: RNFBAppCheckDebugProvider, and we should print local token
47
- // - if a debugToken parameter was supplied, set
48
- // RNFBAppCheckDebugProvider.configuredDebugToken
49
- // - print local token
50
- // https://github.com/firebase/firebase-ios-sdk/blob/c7e95996ff/FirebaseAppCheck/Sources/DebugProvider/FIRAppCheckDebugProviderFactory.m
51
- // - print if current token in provided by configuration, by environment variable, or local
52
- // token?
41
+ // The firebase-ios-sdk debug app check provider will take a token from environment if it
42
+ // exists:
43
+ if (debugToken != nil) {
44
+ // We have a debug token, so just need to stuff it in the environment and it will hook up
45
+ char *key = "FIRAAppCheckDebugToken", *value = [debugToken UTF8String];
46
+ int overwrite = 1;
47
+ setenv(key, value, overwrite);
48
+ }
53
49
 
54
50
  self.delegateProvider = [[FIRAppCheckDebugProvider new] initWithApp:app];
55
51
  }
package/lib/index.d.ts CHANGED
@@ -135,12 +135,12 @@ export namespace FirebaseAppCheckTypes {
135
135
  * so AppCheck has the same experience across all platforms, with the only difference being the native
136
136
  * providers you choose to use on each platform.
137
137
  */
138
- configure(
139
- web?: ReactNativeFirebaseAppCheckProviderWebOptions,
140
- android?: ReactNativeFirebaseAppCheckProviderAndroidOptions,
141
- apple?: ReactNativeFirebaseAppCheckProviderAppleOptions,
142
- isTokenAutoRefreshEnabled?: boolean,
143
- ): Promise<void>;
138
+ configure(options: {
139
+ web?: ReactNativeFirebaseAppCheckProviderWebOptions;
140
+ android?: ReactNativeFirebaseAppCheckProviderAndroidOptions;
141
+ apple?: ReactNativeFirebaseAppCheckProviderAppleOptions;
142
+ isTokenAutoRefreshEnabled?: boolean;
143
+ }): Promise<void>;
144
144
  }
145
145
 
146
146
  /**
@@ -193,6 +193,11 @@ export namespace FirebaseAppCheckTypes {
193
193
  *
194
194
  */
195
195
  export class Module extends FirebaseModule {
196
+ /**
197
+ * create a ReactNativeFirebaseAppCheckProvider option for use in react-native-firebase
198
+ */
199
+ newReactNativeFirebaseAppCheckProvider(): ReactNativeFirebaseAppCheckProvider;
200
+
196
201
  /**
197
202
  * initialize the AppCheck module. Note that in react-native-firebase AppCheckOptions must always
198
203
  * be an object with a `provider` member containing `ReactNativeFirebaseAppCheckProvider` that has returned successfully
package/lib/index.js CHANGED
@@ -26,6 +26,13 @@ import ReactNativeFirebaseAppCheckProvider from './ReactNativeFirebaseAppCheckPr
26
26
 
27
27
  import version from './version';
28
28
 
29
+ export {
30
+ addTokenListener,
31
+ getToken,
32
+ initializeAppCheck,
33
+ setTokenAutoRefreshEnabled,
34
+ } from './modular/index';
35
+
29
36
  const statics = {};
30
37
 
31
38
  const namespace = 'appCheck';
@@ -61,13 +68,26 @@ class FirebaseAppCheckModule extends FirebaseModule {
61
68
  }
62
69
  this.native.setTokenAutoRefreshEnabled(options.isTokenAutoRefreshEnabled);
63
70
 
71
+ if (options.provider === undefined || options.provider.providerOptions === undefined) {
72
+ throw new Error('Invalid configuration: no provider or no provider options defined.');
73
+ }
64
74
  if (Platform.OS === 'android') {
75
+ if (!isString(options.provider.providerOptions.android.provider)) {
76
+ throw new Error(
77
+ 'Invalid configuration: no android provider configured while on android platform.',
78
+ );
79
+ }
65
80
  return this.native.configureProvider(
66
81
  options.provider.providerOptions.android.provider,
67
82
  options.provider.providerOptions.android.debugToken,
68
83
  );
69
84
  }
70
85
  if (Platform.OS === 'ios' || Platform.OS === 'macos') {
86
+ if (!isString(options.provider.providerOptions.apple.provider)) {
87
+ throw new Error(
88
+ 'Invalid configuration: no apple provider configured while on apple platform.',
89
+ );
90
+ }
71
91
  return this.native.configureProvider(
72
92
  options.provider.providerOptions.apple.provider,
73
93
  options.provider.providerOptions.apple.debugToken,
@@ -0,0 +1,70 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ /*
3
+ * Copyright (c) 2016-present Invertase Limited & Contributors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this library except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ import { firebase } from '..';
20
+
21
+ /**
22
+ * Activate App Check for the given app. Can be called only once per app.
23
+ * @param app - FirebaseApp. Optional.
24
+ * @param options - AppCheckOptions
25
+ * @returns {AppCheck}
26
+ */
27
+ export async function initializeAppCheck(app, options) {
28
+ if (app) {
29
+ await firebase.app(app.name).appCheck().initializeAppCheck(options);
30
+ return { app: firebase.app(app.name) };
31
+ }
32
+
33
+ await firebase.app().appCheck().initializeAppCheck(options);
34
+ return { app: firebase.app() };
35
+ }
36
+
37
+ /**
38
+ * Get the current App Check token. Attaches to the most recent in-flight request if one is present.
39
+ * Returns null if no token is present and no token requests are in-flight.
40
+ * @param appCheckInstance - AppCheck
41
+ * @param forceRefresh - boolean
42
+ * @returns {Promise<AppCheckTokenResult>}
43
+ */
44
+ export function getToken(appCheckInstance, forceRefresh) {
45
+ return appCheckInstance.app.appCheck().getToken(forceRefresh);
46
+ }
47
+
48
+ /**
49
+ * Registers a listener to changes in the token state.
50
+ * There can be more than one listener registered at the same time for one or more App Check instances.
51
+ * The listeners call back on the UI thread whenever the current
52
+ * token associated with this App Check instance changes.
53
+ * @param appCheckInstance - AppCheck
54
+ * @param listener - PartialObserver<AppCheckTokenResult>
55
+ * @returns {Unsubscribe}
56
+ */
57
+ export function addTokenListener(appCheckInstance, listener) {
58
+ // Not implemented on React Native
59
+ // See packages/app-check/lib/index.js:127
60
+ throw new Error('addTokenListener is not implemented on React Native');
61
+ }
62
+
63
+ /**
64
+ * Set whether App Check will automatically refresh tokens as needed.
65
+ * @param appCheckInstance - AppCheck
66
+ * @param isAutoRefreshEnabled - boolean
67
+ */
68
+ export function setTokenAutoRefreshEnabled(appCheckInstance, isAutoRefreshEnabled) {
69
+ return appCheckInstance.app.appCheck().setTokenAutoRefreshEnabled(isAutoRefreshEnabled);
70
+ }
package/lib/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- module.exports = '17.1.0';
2
+ module.exports = '17.3.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-firebase/app-check",
3
- "version": "17.1.0",
3
+ "version": "17.3.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",
@@ -23,10 +23,10 @@
23
23
  "appCheck"
24
24
  ],
25
25
  "peerDependencies": {
26
- "@react-native-firebase/app": "17.1.0"
26
+ "@react-native-firebase/app": "17.3.0"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"
30
30
  },
31
- "gitHead": "635d595389bfb224fc530681627fb2180fea6e26"
31
+ "gitHead": "2e51817c937247ffe51fb6234c164744c2a71693"
32
32
  }