From 95fb3adac2b9dc0c77c87a91b74371928d2200b0 Mon Sep 17 00:00:00 2001 From: Quentin Fox Date: Thu, 30 Dec 2021 18:31:33 -0800 Subject: [PATCH 1/8] fix app check `getToken` type --- packages/app-check/lib/index.d.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/packages/app-check/lib/index.d.ts b/packages/app-check/lib/index.d.ts index 7937a1164de..99ac648df9a 100644 --- a/packages/app-check/lib/index.d.ts +++ b/packages/app-check/lib/index.d.ts @@ -65,18 +65,9 @@ export namespace FirebaseAppCheckTypes { /** * Returns an AppCheck token. */ - getToken(): Promise; + getToken(): Promise; } - /** - * Result returned by `getToken()`. - */ - interface AppCheckTokenResult { - /** - * The token string in JWT format. - */ - readonly token: string; - } /** * The token returned from an `AppCheckProvider`. */ @@ -157,7 +148,7 @@ export namespace FirebaseAppCheckTypes { * If false, the cached token is used if it exists and has not expired yet. * In most cases, false should be used. True should only be used if the server explicitly returns an error, indicating a revoked token. */ - getToken(forceRefresh?: boolean): Promise; + getToken(forceRefresh?: boolean): Promise; /** * Registers a listener to changes in the token state. There can be more @@ -168,7 +159,7 @@ export namespace FirebaseAppCheckTypes { * @returns A function that unsubscribes this listener. */ // TODO there is a great deal of Observer / PartialObserver typing to carry-in - // onTokenChanged(observer: PartialObserver): () => void; + // onTokenChanged(observer: PartialObserver): () => void; /** * TODO implement token listener for android. @@ -184,7 +175,7 @@ export namespace FirebaseAppCheckTypes { * @returns A function that unsubscribes this listener. */ // onTokenChanged( - // onNext: (tokenResult: AppCheckTokenResult) => void, + // onNext: (tokenResult: string) => void, // onError?: (error: Error) => void, // onCompletion?: () => void, // ): () => void; From 5efde919d887e3892cf4caee70744d9c0e6af422 Mon Sep 17 00:00:00 2001 From: Quentin Fox Date: Thu, 30 Dec 2021 18:31:47 -0800 Subject: [PATCH 2/8] update tests to ensure `getToken` returns a string --- packages/app-check/e2e/appcheck.e2e.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/app-check/e2e/appcheck.e2e.js b/packages/app-check/e2e/appcheck.e2e.js index 22ca30460cf..bb1466ba999 100644 --- a/packages/app-check/e2e/appcheck.e2e.js +++ b/packages/app-check/e2e/appcheck.e2e.js @@ -44,6 +44,7 @@ describe('appCheck()', function () { it('token fetch attempt should work', async function () { // Our tests configure a debug provider with shared secret so we should get a valid token const token = await firebase.appCheck().getToken(); + token.should.be.a.String(); token.should.not.equal(''); const decodedToken = jwt.decode(token); decodedToken.aud[1].should.equal('projects/react-native-firebase-testing'); @@ -54,6 +55,7 @@ describe('appCheck()', function () { // Force refresh should get a different token? // TODO sometimes fails on android https://github.com/firebase/firebase-android-sdk/issues/2954 const token2 = await firebase.appCheck().getToken(true); + token.should.be.a.String(); token2.should.not.equal(''); const decodedToken2 = jwt.decode(token2); decodedToken2.aud[1].should.equal('projects/react-native-firebase-testing'); From a2243235f7bdaa9c03145edf193200a08e5e96c6 Mon Sep 17 00:00:00 2001 From: Quentin Fox Date: Thu, 30 Dec 2021 21:41:41 -0800 Subject: [PATCH 3/8] Revert "update tests to ensure `getToken` returns a string" This reverts commit 5efde919d887e3892cf4caee70744d9c0e6af422. --- packages/app-check/e2e/appcheck.e2e.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/app-check/e2e/appcheck.e2e.js b/packages/app-check/e2e/appcheck.e2e.js index bb1466ba999..22ca30460cf 100644 --- a/packages/app-check/e2e/appcheck.e2e.js +++ b/packages/app-check/e2e/appcheck.e2e.js @@ -44,7 +44,6 @@ describe('appCheck()', function () { it('token fetch attempt should work', async function () { // Our tests configure a debug provider with shared secret so we should get a valid token const token = await firebase.appCheck().getToken(); - token.should.be.a.String(); token.should.not.equal(''); const decodedToken = jwt.decode(token); decodedToken.aud[1].should.equal('projects/react-native-firebase-testing'); @@ -55,7 +54,6 @@ describe('appCheck()', function () { // Force refresh should get a different token? // TODO sometimes fails on android https://github.com/firebase/firebase-android-sdk/issues/2954 const token2 = await firebase.appCheck().getToken(true); - token.should.be.a.String(); token2.should.not.equal(''); const decodedToken2 = jwt.decode(token2); decodedToken2.aud[1].should.equal('projects/react-native-firebase-testing'); From f394850937bda4515fafde36be111d07b4b2b035 Mon Sep 17 00:00:00 2001 From: Quentin Fox Date: Thu, 30 Dec 2021 21:41:55 -0800 Subject: [PATCH 4/8] Revert "fix app check `getToken` type" This reverts commit 95fb3adac2b9dc0c77c87a91b74371928d2200b0. --- packages/app-check/lib/index.d.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/app-check/lib/index.d.ts b/packages/app-check/lib/index.d.ts index 99ac648df9a..7937a1164de 100644 --- a/packages/app-check/lib/index.d.ts +++ b/packages/app-check/lib/index.d.ts @@ -65,9 +65,18 @@ export namespace FirebaseAppCheckTypes { /** * Returns an AppCheck token. */ - getToken(): Promise; + getToken(): Promise; } + /** + * Result returned by `getToken()`. + */ + interface AppCheckTokenResult { + /** + * The token string in JWT format. + */ + readonly token: string; + } /** * The token returned from an `AppCheckProvider`. */ @@ -148,7 +157,7 @@ export namespace FirebaseAppCheckTypes { * If false, the cached token is used if it exists and has not expired yet. * In most cases, false should be used. True should only be used if the server explicitly returns an error, indicating a revoked token. */ - getToken(forceRefresh?: boolean): Promise; + getToken(forceRefresh?: boolean): Promise; /** * Registers a listener to changes in the token state. There can be more @@ -159,7 +168,7 @@ export namespace FirebaseAppCheckTypes { * @returns A function that unsubscribes this listener. */ // TODO there is a great deal of Observer / PartialObserver typing to carry-in - // onTokenChanged(observer: PartialObserver): () => void; + // onTokenChanged(observer: PartialObserver): () => void; /** * TODO implement token listener for android. @@ -175,7 +184,7 @@ export namespace FirebaseAppCheckTypes { * @returns A function that unsubscribes this listener. */ // onTokenChanged( - // onNext: (tokenResult: string) => void, + // onNext: (tokenResult: AppCheckTokenResult) => void, // onError?: (error: Error) => void, // onCompletion?: () => void, // ): () => void; From 5c27ed798b8c56d151b82b3aee207118c52fab05 Mon Sep 17 00:00:00 2001 From: Quentin Fox Date: Thu, 30 Dec 2021 22:32:12 -0800 Subject: [PATCH 5/8] use WritableMap and NSMutableDictionary to send result to bridge as `{ token: string }` --- .../appcheck/ReactNativeFirebaseAppCheckModule.java | 6 +++++- packages/app-check/ios/RNFBAppCheck/RNFBAppCheckModule.m | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java b/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java index c1a5f729676..09a3e9b0f47 100644 --- a/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java +++ b/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java @@ -82,7 +82,11 @@ public void getToken(String appName, boolean forceRefresh, Promise promise) { getExecutor(), (task) -> { if (task.isSuccessful()) { - promise.resolve(task.getResult().getToken()); + String token = task.getResult().getToken(); + + WritableMap tokenResultMap = Arguments.createMap(); + tokenResultMap.putString("token", tokne); + promise.resolve(tokenResultMap); } else { Log.e( TAG, diff --git a/packages/app-check/ios/RNFBAppCheck/RNFBAppCheckModule.m b/packages/app-check/ios/RNFBAppCheck/RNFBAppCheckModule.m index 894aa9176e9..3892161b7de 100644 --- a/packages/app-check/ios/RNFBAppCheck/RNFBAppCheckModule.m +++ b/packages/app-check/ios/RNFBAppCheck/RNFBAppCheckModule.m @@ -97,8 +97,10 @@ - (dispatch_queue_t)methodQueue { }]; return; } - - resolve(token.token); + + NSMutableDictionary *tokenResultDictionary = [NSMutableDictionary new]; + tokenResultDictionary[@"token"] = token.token; + resolve(tokenResultDictionary); }]; } From 4d5b5ae478542794614f77c30f66e1c35131ed3a Mon Sep 17 00:00:00 2001 From: Quentin Fox Date: Thu, 30 Dec 2021 22:35:13 -0800 Subject: [PATCH 6/8] fix `tokne` typo --- .../firebase/appcheck/ReactNativeFirebaseAppCheckModule.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java b/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java index 09a3e9b0f47..da705b5d63e 100644 --- a/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java +++ b/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java @@ -82,10 +82,8 @@ public void getToken(String appName, boolean forceRefresh, Promise promise) { getExecutor(), (task) -> { if (task.isSuccessful()) { - String token = task.getResult().getToken(); - WritableMap tokenResultMap = Arguments.createMap(); - tokenResultMap.putString("token", tokne); + tokenResultMap.putString("token", task.getResult().getToken()); promise.resolve(tokenResultMap); } else { Log.e( From 3caaf74e18c5646db5e7ea62373db54a32b27c53 Mon Sep 17 00:00:00 2001 From: Quentin Fox Date: Thu, 30 Dec 2021 22:38:01 -0800 Subject: [PATCH 7/8] fix tests to match new `getToken` return type --- packages/app-check/e2e/appcheck.e2e.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/app-check/e2e/appcheck.e2e.js b/packages/app-check/e2e/appcheck.e2e.js index 22ca30460cf..54894f37fbe 100644 --- a/packages/app-check/e2e/appcheck.e2e.js +++ b/packages/app-check/e2e/appcheck.e2e.js @@ -43,7 +43,7 @@ describe('appCheck()', function () { describe('getToken())', function () { it('token fetch attempt should work', async function () { // Our tests configure a debug provider with shared secret so we should get a valid token - const token = await firebase.appCheck().getToken(); + const { token } = await firebase.appCheck().getToken(); token.should.not.equal(''); const decodedToken = jwt.decode(token); decodedToken.aud[1].should.equal('projects/react-native-firebase-testing'); @@ -53,7 +53,7 @@ describe('appCheck()', function () { // Force refresh should get a different token? // TODO sometimes fails on android https://github.com/firebase/firebase-android-sdk/issues/2954 - const token2 = await firebase.appCheck().getToken(true); + const { token: token2 } = await firebase.appCheck().getToken(true); token2.should.not.equal(''); const decodedToken2 = jwt.decode(token2); decodedToken2.aud[1].should.equal('projects/react-native-firebase-testing'); From 31c4498705c3e4a3c4935681c0ada0a18f65b642 Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Fri, 31 Dec 2021 08:46:43 -0500 Subject: [PATCH 8/8] style(app-check, ios): clang-format on ios files --- packages/app-check/ios/RNFBAppCheck/RNFBAppCheckModule.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app-check/ios/RNFBAppCheck/RNFBAppCheckModule.m b/packages/app-check/ios/RNFBAppCheck/RNFBAppCheckModule.m index 3892161b7de..414c14a7fe4 100644 --- a/packages/app-check/ios/RNFBAppCheck/RNFBAppCheckModule.m +++ b/packages/app-check/ios/RNFBAppCheck/RNFBAppCheckModule.m @@ -97,7 +97,7 @@ - (dispatch_queue_t)methodQueue { }]; return; } - + NSMutableDictionary *tokenResultDictionary = [NSMutableDictionary new]; tokenResultDictionary[@"token"] = token.token; resolve(tokenResultDictionary);