Skip to content

Commit 8b42e20

Browse files
committed
fix(app-check): getToken(false) fix, listener unsubscribe is a function
- previously sending false through would crash android - forceRefresh currently ignored on iOS because of upstream issue causing native crash - fix docs
1 parent 3ef3410 commit 8b42e20

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

packages/app-check/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121

2222
---
2323

24-
AppCheck description.
24+
App Check works alongside other Firebase services to help protect your backend resources from abuse, such as billing fraud or phishing. With App Check, devices running your app will use an app or device attestation provider that attests to one or both of the following:
2525

26-
[> Learn More](https://firebase.google.com/products/app-check/)
26+
- Requests originate from your authentic app
27+
- Requests originate from an authentic, untampered device
28+
29+
This attestation is attached to every request your app makes to your Firebase backend resources.
30+
31+
[> Learn More](https://firebase.google.com/docs/app-check/)
2732

2833
## Installation
2934

@@ -35,9 +40,8 @@ yarn add @react-native-firebase/app-check
3540

3641
## Documentation
3742

38-
- [Guides](#TODO)
39-
- [Installation](#TODO)
40-
- [Reference](#TODO)
43+
- [Guides](https://rnfirebase.io/app-check/usage/)
44+
- [Reference](https://rnfirebase.io/reference/app-check)
4145

4246
## License
4347

packages/app-check/e2e/appcheck.e2e.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,26 @@ describe('appCheck()', function () {
4343
describe('getToken())', function () {
4444
it('token fetch attempt should work', async function () {
4545
// Our tests configure a debug provider with shared secret so we should get a valid token
46-
const token = await firebase.appCheck().getToken(true);
46+
const token = await firebase.appCheck().getToken();
4747
token.should.not.equal('');
4848
const decodedToken = jwt.decode(token);
4949
decodedToken.aud[1].should.equal('projects/react-native-firebase-testing');
5050
if (decodedToken.exp < Date.now()) {
5151
Promise.reject('Token already expired');
5252
}
53+
54+
// Force refresh should get a different token?
55+
// TODO iOS tokens are stale because of https://github.com/firebase/firebase-ios-sdk/issues/8544
56+
if (device.getPlatform() === 'android') {
57+
const token2 = await firebase.appCheck().getToken(true);
58+
token2.should.not.equal('');
59+
const decodedToken2 = jwt.decode(token2);
60+
decodedToken2.aud[1].should.equal('projects/react-native-firebase-testing');
61+
if (decodedToken2.exp < Date.now()) {
62+
Promise.reject('Token already expired');
63+
}
64+
(token === token2).should.be.false();
65+
}
5366
});
5467
});
5568
describe('activate())', function () {

packages/app-check/ios/RNFBAppcheck/RNFBAppCheckModule.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ - (dispatch_queue_t)methodQueue {
7575
: (RCTPromiseResolveBlock)resolve
7676
: (RCTPromiseRejectBlock)reject) {
7777
FIRAppCheck *appCheck = [FIRAppCheck appCheckWithApp:firebaseApp];
78-
[appCheck tokenForcingRefresh:NO
78+
[appCheck tokenForcingRefresh:NO // TODO Cannot use forceRefresh argument, if we send 'YES' in
79+
// https://github.com/firebase/firebase-ios-sdk/issues/8544
7980
completion:^(FIRAppCheckToken *_Nullable token, NSError *_Nullable error) {
8081
if (error != nil) {
8182
// Handle any errors if the token was not retrieved.

packages/app-check/lib/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,20 @@ class FirebaseAppCheckModule extends FirebaseModule {
4040
}
4141

4242
getToken(forceRefresh) {
43-
return this.native.getToken(forceRefresh);
43+
if (!forceRefresh) {
44+
return this.native.getToken(false);
45+
} else {
46+
return this.native.getToken(true);
47+
}
4448
}
4549

4650
onTokenChanged() {
4751
// iOS does not provide any native listening feature
4852
if (isIOS) {
49-
return;
53+
return () => {};
5054
}
5155
// TODO unimplemented on Android
52-
return;
56+
return () => {};
5357
}
5458
}
5559

@@ -63,7 +67,7 @@ export default createModuleNamespace({
6367
version,
6468
namespace,
6569
nativeModuleName,
66-
nativeEvents: false, // TODO verify if this is interesting - token refresh listener perhaps?
70+
nativeEvents: false, // TODO implement ['appcheck-token-changed'],
6771
hasMultiAppSupport: true,
6872
hasCustomUrlOrRegionSupport: false,
6973
ModuleClass: FirebaseAppCheckModule,

0 commit comments

Comments
 (0)