Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App check and storage, functions and RTDB support #7928

Merged
merged 196 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
196 commits
Select commit Hold shift + click to select a range
1c175fa
AppAttestation initial public API
maksymmalyhin Mar 31, 2020
44479a9
Run ./scripts/style.sh
maksymmalyhin Mar 31, 2020
9b5f2aa
Copyright
maksymmalyhin Mar 31, 2020
9e64cfa
Cleanup
maksymmalyhin Mar 31, 2020
e716fe2
Cleanup
maksymmalyhin Mar 31, 2020
230caf0
Get token forcing refresh method
maksymmalyhin Mar 31, 2020
9bd817f
Formatting
maksymmalyhin Mar 31, 2020
a389b58
Forcing refresh samples
maksymmalyhin Mar 31, 2020
29779d7
Interop introduced
maksymmalyhin Apr 2, 2020
ddcb955
Code samples for Interop
maksymmalyhin Apr 2, 2020
299f9e5
Run ./scripts/style.sh
maksymmalyhin Apr 2, 2020
a3ba5ff
Cleanup
maksymmalyhin Apr 2, 2020
0422d89
Merge branch 'app-attestation' into mm/attestation-init
maksymmalyhin Apr 2, 2020
bad426e
TODOs and Copirights
maksymmalyhin Apr 6, 2020
d70d42f
Fix build
maksymmalyhin Apr 6, 2020
762bba4
Supported iOS versions
maksymmalyhin Apr 6, 2020
b637018
Remove unnecessary bridging header
maksymmalyhin Apr 6, 2020
6cf31d2
Run ./scripts/style.sh
maksymmalyhin Apr 6, 2020
8c622e3
[WIP] DeviceCheckAttestationProvider as a subspec
maksymmalyhin Apr 6, 2020
7fbc3ea
cleanup
maksymmalyhin Apr 6, 2020
6cfbd56
Add memory attributes to readonly properties
maksymmalyhin Apr 6, 2020
31ae2d1
Move FIRDeviceCheckAttestationProvider.h to private headers
maksymmalyhin Apr 7, 2020
f92d4c7
TODO for `FirebaseAppAttestation/Core` name
maksymmalyhin Apr 7, 2020
0f6661f
Remove memory attributes from FIRAppAttestationToken properties
maksymmalyhin Apr 7, 2020
ba241f2
Merge pull request #622 from FirebasePrivate/mm/attestation-init
maksymmalyhin Apr 7, 2020
45f7e5e
Merge branch 'master' into app-attestation
maksymmalyhin Apr 7, 2020
901a66c
FIRAppAttestationTests.testSetAttestationProviderFactory introduced
maksymmalyhin Apr 7, 2020
1dda651
FIRAppAttestationToken initializer
maksymmalyhin Apr 7, 2020
f631d83
Basic FIRLibrary implementation and FIRAppAttestationProviderFactory …
maksymmalyhin Apr 7, 2020
5cdc32d
Fix
maksymmalyhin Apr 7, 2020
7b91645
FIRAppAttestationToken+Interop.h
maksymmalyhin Apr 7, 2020
922a997
TODOs
maksymmalyhin Apr 7, 2020
05d2d95
Tests: reset FIRApps
maksymmalyhin Apr 7, 2020
6d707e9
GHA for App Attestation
maksymmalyhin Apr 7, 2020
7b2dd55
Run ./scripts/style.sh
maksymmalyhin Apr 7, 2020
51090d8
Style fixes.
maksymmalyhin Apr 8, 2020
0bdec79
Run ./scripts/style.sh
maksymmalyhin Apr 8, 2020
0740a31
TODO
maksymmalyhin Apr 8, 2020
7936849
Nullable initializer and type annpotations
maksymmalyhin Apr 8, 2020
e676103
TODOs
maksymmalyhin Apr 9, 2020
91f0c58
TODOs
maksymmalyhin Apr 9, 2020
0c19287
TODO
maksymmalyhin Apr 9, 2020
42fdeb0
Merge pull request #624 from FirebasePrivate/mm/provider-ingestion
maksymmalyhin Apr 9, 2020
53fe715
Merge branch 'master' into app-attestation
maksymmalyhin Apr 9, 2020
3bb141b
Merge branch 'app-attestation' of github.com:FirebasePrivate/firebase…
maksymmalyhin Apr 9, 2020
bc981cb
Merge branch 'app-attestation' into mm/app-attest-gha
maksymmalyhin Apr 9, 2020
3281da9
Fix spec and allow warnings
maksymmalyhin Apr 9, 2020
7d9f2f2
Merge pull request #625 from FirebasePrivate/mm/app-attest-gha
maksymmalyhin Apr 9, 2020
745659b
AppAttestation initial public API
maksymmalyhin Mar 31, 2020
265cc31
Run ./scripts/style.sh
maksymmalyhin Mar 31, 2020
fa145a0
Copyright
maksymmalyhin Mar 31, 2020
81b04f3
Cleanup
maksymmalyhin Mar 31, 2020
6981035
Cleanup
maksymmalyhin Mar 31, 2020
cce8828
Get token forcing refresh method
maksymmalyhin Mar 31, 2020
5c4b6b6
Formatting
maksymmalyhin Mar 31, 2020
459f3a8
Forcing refresh samples
maksymmalyhin Mar 31, 2020
3efd07a
Interop introduced
maksymmalyhin Apr 2, 2020
53a3d82
Code samples for Interop
maksymmalyhin Apr 2, 2020
ad33b5a
Run ./scripts/style.sh
maksymmalyhin Apr 2, 2020
326a110
Cleanup
maksymmalyhin Apr 2, 2020
35d5aa3
TODOs and Copirights
maksymmalyhin Apr 6, 2020
7887c16
Fix build
maksymmalyhin Apr 6, 2020
adbed71
Supported iOS versions
maksymmalyhin Apr 6, 2020
5610bcf
Remove unnecessary bridging header
maksymmalyhin Apr 6, 2020
3415586
Run ./scripts/style.sh
maksymmalyhin Apr 6, 2020
ff754f0
[WIP] DeviceCheckAttestationProvider as a subspec
maksymmalyhin Apr 6, 2020
6a35ce4
cleanup
maksymmalyhin Apr 6, 2020
7979898
Add memory attributes to readonly properties
maksymmalyhin Apr 6, 2020
19c98a5
Move FIRDeviceCheckAttestationProvider.h to private headers
maksymmalyhin Apr 7, 2020
adc2da5
TODO for `FirebaseAppAttestation/Core` name
maksymmalyhin Apr 7, 2020
e7f0e97
Remove memory attributes from FIRAppAttestationToken properties
maksymmalyhin Apr 7, 2020
338a970
FIRAppAttestationTests.testSetAttestationProviderFactory introduced
maksymmalyhin Apr 7, 2020
17726b3
FIRAppAttestationToken initializer
maksymmalyhin Apr 7, 2020
2eac029
Basic FIRLibrary implementation and FIRAppAttestationProviderFactory …
maksymmalyhin Apr 7, 2020
e323564
Fix
maksymmalyhin Apr 7, 2020
6f2af53
FIRAppAttestationToken+Interop.h
maksymmalyhin Apr 7, 2020
cdf682b
TODOs
maksymmalyhin Apr 7, 2020
6d55ad1
Tests: reset FIRApps
maksymmalyhin Apr 7, 2020
7ddda22
Run ./scripts/style.sh
maksymmalyhin Apr 7, 2020
c43094b
Style fixes.
maksymmalyhin Apr 8, 2020
062152d
Run ./scripts/style.sh
maksymmalyhin Apr 8, 2020
137813e
TODO
maksymmalyhin Apr 8, 2020
a24910b
Nullable initializer and type annpotations
maksymmalyhin Apr 8, 2020
62543e3
TODOs
maksymmalyhin Apr 9, 2020
7e479d5
TODOs
maksymmalyhin Apr 9, 2020
d2322c1
TODO
maksymmalyhin Apr 9, 2020
3d1fd8c
Merge branch 'app-attestation' of github.com:FirebasePrivate/firebase…
maksymmalyhin Apr 14, 2020
a1d8b90
Merge branch 'master' into app-attestation
maksymmalyhin Apr 14, 2020
5a7a003
Merge branch 'master' into app-attestation
maksymmalyhin Apr 16, 2020
5884b57
Revert FirestoreDecoder.swift formatting.
maksymmalyhin Apr 16, 2020
d0a2478
Basic implementation of FIRDeviceCheckAttestationProvider and tests (…
maksymmalyhin Apr 16, 2020
3770936
Merge branch 'master' into app-attestation
maksymmalyhin Apr 20, 2020
f49da3d
FIRAppAttestStorage implementation and tests (#627)
maksymmalyhin Apr 21, 2020
b0c6f28
Merge branch 'master' into app-attestation
maksymmalyhin Apr 23, 2020
a81b931
Merge branch 'app-attestation' of github.com:FirebasePrivate/firebase…
maksymmalyhin Apr 23, 2020
7f764d6
Merge branch 'master' into app-attestation
maksymmalyhin May 6, 2020
589047b
Attestation Token caching (#630)
maksymmalyhin May 11, 2020
6b1bc1b
Merge branch 'master' into app-attestation
maksymmalyhin May 11, 2020
00c33df
Merge branch 'master' into app-attestation
maksymmalyhin May 12, 2020
ab6eb21
Rename App Attestation -> App Check (#631)
maksymmalyhin May 13, 2020
3297e37
'Merge branch 'master' into app-attestation
maksymmalyhin May 14, 2020
d66a08c
Default Custom Provider (#633)
maksymmalyhin May 19, 2020
fc80c30
Merge branch 'master' into app-attestation
maksymmalyhin May 21, 2020
1e19a2a
AppCheck: remove not unnecessary public API (#634)
maksymmalyhin May 21, 2020
b4810b2
AppCheck: DeviceCheck token server API (#635)
maksymmalyhin May 28, 2020
d22838d
Merge branch 'master' into app-attestation
maksymmalyhin May 28, 2020
55430c2
Merge branch 'app-attestation' of github.com:FirebasePrivate/firebase…
maksymmalyhin May 28, 2020
978a699
'Merge branch 'master' into app-attestation
maksymmalyhin May 29, 2020
8b81351
AppCheck: API errors and tests (#636)
maksymmalyhin Jun 1, 2020
9ebc103
AppCheck: Register device check provider factory as a default (#637)
maksymmalyhin Jun 1, 2020
e47a981
Merge branch 'master' into app-attestation
maksymmalyhin Jun 5, 2020
e728fcf
Merge branch 'app-attestation' of github.com:FirebasePrivate/firebase…
maksymmalyhin Jun 5, 2020
8afce8a
Merge branch 'master' into app-attestation
maksymmalyhin Jun 8, 2020
d4f1e69
Merge branch 'master' into app-attestation
maksymmalyhin Jun 10, 2020
ef4ddec
AppCheck: API communication common for all providers moved to FIRAppC…
maksymmalyhin Jun 11, 2020
199c33e
Merge remote-tracking branch 'origin/master' into app-attestation
maksymmalyhin Jul 16, 2020
48dc9a8
Merge remote-tracking branch 'origin/master' into app-attestation
maksymmalyhin Jul 24, 2020
a7c55d9
DeviceCheck mock server integration and tests (#686)
maksymmalyhin Jul 24, 2020
d142fff
Merge remote-tracking branch 'origin/master' into mm/appcheck-merge-m…
maksymmalyhin Oct 19, 2020
a204009
Merge remote-tracking branch 'origin/master' into app-attestation
maksymmalyhin Oct 20, 2020
61b490f
App Check: Firebase 7 fixes (#715)
maksymmalyhin Oct 20, 2020
2af70cf
AppCheck: debug FAC token provider (#716)
maksymmalyhin Oct 21, 2020
53098ff
Merge remote-tracking branch 'origin/master' into app-attestation
maksymmalyhin Oct 21, 2020
b516668
AppCheck: merge into single spec (package) (#717)
maksymmalyhin Oct 21, 2020
a6c539f
Merge remote-tracking branch 'origin/master' into app-attestation
maksymmalyhin Oct 26, 2020
d1d8171
AppCheck: server request adjustments (#718)
maksymmalyhin Oct 26, 2020
669d52f
AppCheck: primitive test app (#719)
maksymmalyhin Oct 27, 2020
119cda6
Merge remote-tracking branch 'origin/master' into app-attestation
maksymmalyhin Nov 3, 2020
4f1b622
Storage: integration with AppCheck (#720)
maksymmalyhin Nov 10, 2020
f3e53ee
Merge remote-tracking branch 'origin/master' into app-attestation
maksymmalyhin Nov 16, 2020
2c0ad56
AppCheck: separate 2P and 3P API (#724)
maksymmalyhin Dec 1, 2020
59083d7
Merge remote-tracking branch 'origin/master' into app-attestation
maksymmalyhin Dec 3, 2020
ec2cedb
AppCheck cleanup (#737)
maksymmalyhin Dec 3, 2020
0008d77
Merge remote-tracking branch 'origin/master' into app-attestation
maksymmalyhin Dec 7, 2020
62d0b47
Merge branch 'app-attestation' of github.com:FirebasePrivate/firebase…
maksymmalyhin Dec 7, 2020
b10f350
AppCheck: Debug token to AppCheck token exchange API (#739)
maksymmalyhin Dec 7, 2020
0d216d6
App Check debug provider: integrate with exchange API (#743)
maksymmalyhin Dec 9, 2020
eb7b818
App Check test app debug provider fix (#747)
maksymmalyhin Dec 9, 2020
9b13154
App Check: minor touchups (#750)
maksymmalyhin Dec 11, 2020
2d683d8
App Check: use prod environment (#751)
maksymmalyhin Dec 15, 2020
5552215
Merge branch 'master' into app-check-main
maksymmalyhin Jan 6, 2021
6092cc7
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Jan 7, 2021
5d87756
Merge branch 'app-check-main' of github.com:FirebasePrivate/firebase-…
maksymmalyhin Jan 7, 2021
c98fc60
App Check SwiftPM support (#753)
maksymmalyhin Jan 7, 2021
82d32fd
Merge branch 'master' into app-check-main
maksymmalyhin Jan 8, 2021
dc20b77
Merge branch 'app-check-main' of github.com:FirebasePrivate/firebase-…
maksymmalyhin Jan 8, 2021
596ced2
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Jan 11, 2021
348918b
Merge branch 'master' into app-check-main
maksymmalyhin Jan 13, 2021
c0e0d2a
Merge branch 'master' into app-check-main
maksymmalyhin Jan 15, 2021
eeafecd
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Jan 18, 2021
2abe8b7
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Jan 19, 2021
6ce7beb
App Check: token auto-refresh (#754)
maksymmalyhin Jan 20, 2021
00605a4
Merge branch 'master' into app-check-main
maksymmalyhin Jan 20, 2021
d6185d1
App Check fixes (#755)
maksymmalyhin Jan 21, 2021
d596255
Merge branch 'master' into app-check-main
maksymmalyhin Jan 21, 2021
caa37dc
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Jan 28, 2021
c6a2b9e
Temporary exclude App Check from platfrom logging (#756)
maksymmalyhin Jan 28, 2021
f87ac45
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Feb 1, 2021
fda54b7
App Check: send app check SDK version only in the header (#757)
maksymmalyhin Feb 1, 2021
84eec4e
Merge branch 'master' into app-check-main
maksymmalyhin Feb 3, 2021
1def155
Merge branch 'app-check-main' of github.com:FirebasePrivate/firebase-…
maksymmalyhin Feb 3, 2021
7a38145
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Feb 8, 2021
f54e385
App Check: store FAC token per app ID (#758)
maksymmalyhin Feb 8, 2021
09a2d47
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Feb 18, 2021
9b671a3
AppCheckCustomProvideApp (#760)
maksymmalyhin Feb 23, 2021
484bcdb
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Feb 23, 2021
7167680
Merge branch 'app-check-main' of github.com:FirebasePrivate/firebase-…
maksymmalyhin Feb 23, 2021
beb8962
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Mar 1, 2021
75594b7
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Mar 16, 2021
42caf9d
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Mar 19, 2021
e3485b9
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Mar 25, 2021
0f30b26
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Mar 29, 2021
9b625b4
Functions: App Check integration (#762)
maksymmalyhin Mar 30, 2021
c22050f
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Mar 31, 2021
2dc9e75
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Apr 1, 2021
76c1539
RTDB: pass FAC token to web socket (#763)
maksymmalyhin Apr 1, 2021
62fa539
App Check: token update notifications (#764)
maksymmalyhin Apr 6, 2021
5ed6ddc
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Apr 6, 2021
b5ffb0f
Merge branch 'app-check-main' of github.com:FirebasePrivate/firebase-…
maksymmalyhin Apr 6, 2021
398386a
RTDB: send app check token updates to keep connection open (#765)
maksymmalyhin Apr 9, 2021
2eb60e3
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Apr 12, 2021
2bb1189
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Apr 13, 2021
a08345e
App Check API cleanup and docs (#766)
maksymmalyhin Apr 14, 2021
617e7cc
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Apr 15, 2021
953cd45
App Check cleanup (#767)
maksymmalyhin Apr 15, 2021
25efe5d
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Apr 15, 2021
58c05ec
Migrate v1alpha URLs to v1beta
ncooke3 Apr 19, 2021
fe5d6b0
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Apr 19, 2021
0f43f32
Migrate v1alpha URLs to v1beta
ncooke3 Apr 19, 2021
d4d8f1a
Merge branch 'app-check-main' into nc/update-vlalpha-urls
ncooke3 Apr 19, 2021
0016ae8
Merge pull request #768 from FirebasePrivate/nc/update-vlalpha-urls
ncooke3 Apr 19, 2021
26e1e5d
Merge remote-tracking branch 'origin/master' into app-check-main
maksymmalyhin Apr 21, 2021
44fd73d
Run ./scripts/style.sh
maksymmalyhin Apr 21, 2021
4a70082
Functions tests: fix Xcode 11 warnings (#7931)
maksymmalyhin Apr 21, 2021
c39f029
App Check: token auto-refresh opt-out API (#769)
maksymmalyhin Apr 21, 2021
9b22410
Merge branch 'app-check-main' of github.com:firebase/firebase-ios-sdk…
maksymmalyhin Apr 21, 2021
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
App Check: token update notifications (#764)
* AppCheck: token did change API and tests

* notification implementation and fixes

* Run ./scripts/style.sh

* Update comments
  • Loading branch information
maksymmalyhin authored Apr 6, 2021
commit 62fa539c2ec0c6b40ea4dceabced68f0e8930f1e
58 changes: 51 additions & 7 deletions FirebaseAppCheck/Sources/Core/FIRAppCheck.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@

NS_ASSUME_NONNULL_BEGIN

/// A notification with the specified name is sent to the default notification center
/// (`NotificationCenter.default`) each time a Firebase app check token is refreshed.
/// The user info dictionary contains `kFIRAppCheckTokenNotificationKey` and
/// `kFIRAppCheckAppNameNotificationKey` keys.
const NSNotificationName FIRAppCheckAppCheckTokenDidChangeNotification =
@"FIRAppCheckAppCheckTokenDidChangeNotification";

/// `userInfo` key for the `AppCheckToken` in `appCheckTokenRefreshNotification`.
NSString *const kFIRAppCheckTokenNotificationKey = @"FIRAppCheckTokenNotificationKey";

/// `userInfo` key for the `FirebaseApp.name` in `appCheckTokenRefreshNotification`.
NSString *const kFIRAppCheckAppNameNotificationKey = @"FIRAppCheckAppNameNotificationKey";

static id<FIRAppCheckProviderFactory> _providerFactory;

static const NSTimeInterval kTokenExpirationThreshold = 5 * 60; // 5 min.
Expand All @@ -50,6 +63,7 @@ @interface FIRAppCheck () <FIRLibrary, FIRAppCheckInterop>
@property(nonatomic, readonly) NSString *appName;
@property(nonatomic, readonly) id<FIRAppCheckProvider> appCheckProvider;
@property(nonatomic, readonly) id<FIRAppCheckStorageProtocol> storage;
@property(nonatomic, readonly) NSNotificationCenter *notificationCenter;

@property(nonatomic, readonly, nullable) id<FIRAppCheckTokenRefresherProtocol> tokenRefresher;

Expand Down Expand Up @@ -115,19 +129,22 @@ - (nullable instancetype)initWithApp:(FIRApp *)app {
return [self initWithAppName:app.name
appCheckProvider:appCheckProvider
storage:storage
tokenRefresher:tokenRefresher];
tokenRefresher:tokenRefresher
notificationCenter:NSNotificationCenter.defaultCenter];
}

- (instancetype)initWithAppName:(NSString *)appName
appCheckProvider:(id<FIRAppCheckProvider>)appCheckProvider
storage:(id<FIRAppCheckStorageProtocol>)storage
tokenRefresher:(id<FIRAppCheckTokenRefresherProtocol>)tokenRefresher {
tokenRefresher:(id<FIRAppCheckTokenRefresherProtocol>)tokenRefresher
notificationCenter:(NSNotificationCenter *)notificationCenter {
self = [super init];
if (self) {
_appName = appName;
_appCheckProvider = appCheckProvider;
_storage = storage;
_tokenRefresher = tokenRefresher;
_notificationCenter = notificationCenter;

__auto_type __weak weakSelf = self;
tokenRefresher.tokenRefreshHandler = ^(FIRAppCheckTokenRefreshCompletion _Nonnull completion) {
Expand Down Expand Up @@ -176,6 +193,18 @@ - (void)getTokenForcingRefresh:(BOOL)forcingRefresh
});
}

- (nonnull NSString *)tokenDidChangeNotificationName {
return FIRAppCheckAppCheckTokenDidChangeNotification;
}

- (nonnull NSString *)notificationAppNameKey {
return kFIRAppCheckAppNameNotificationKey;
}

- (nonnull NSString *)notificationTokenKey {
return kFIRAppCheckTokenNotificationKey;
}

#pragma mark - FAA token cache

- (FBLPromise<FIRAppCheckToken *> *)retrieveOrRefreshTokenForcingRefresh:(BOOL)forcingRefresh {
Expand Down Expand Up @@ -208,12 +237,16 @@ - (void)getTokenForcingRefresh:(BOOL)forcingRefresh
}

- (FBLPromise<FIRAppCheckToken *> *)refreshToken {
return
[FBLPromise wrapObjectOrErrorCompletion:^(
FBLPromiseObjectOrErrorCompletion _Nonnull handler) {
[self.appCheckProvider getTokenWithCompletion:handler];
}].then(^id _Nullable(FIRAppCheckToken *_Nullable token) {
return [FBLPromise
wrapObjectOrErrorCompletion:^(FBLPromiseObjectOrErrorCompletion _Nonnull handler) {
[self.appCheckProvider getTokenWithCompletion:handler];
}]
.then(^id _Nullable(FIRAppCheckToken *_Nullable token) {
return [self.storage setToken:token];
})
.then(^id _Nullable(FIRAppCheckToken *_Nullable token) {
[self postTokenUpdateNotificationWithToken:token];
return token;
});
}

Expand All @@ -230,6 +263,17 @@ - (void)periodicTokenRefreshWithCompletion:(FIRAppCheckTokenRefreshCompletion)co
});
}

#pragma mark - Token update notification

- (void)postTokenUpdateNotificationWithToken:(FIRAppCheckToken *)token {
[self.notificationCenter postNotificationName:FIRAppCheckAppCheckTokenDidChangeNotification
object:nil
userInfo:@{
kFIRAppCheckTokenNotificationKey : token.token,
kFIRAppCheckAppNameNotificationKey : self.appName
}];
}

@end

NS_ASSUME_NONNULL_END
12 changes: 12 additions & 0 deletions FirebaseAppCheck/Sources/Interop/FIRAppCheckInterop.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ typedef void (^FIRAppCheckTokenHandlerInterop)(id<FIRAppCheckTokenResultInterop>
completion:(FIRAppCheckTokenHandlerInterop)handler
NS_SWIFT_NAME(getToken(forcingRefresh:completion:));

/// A notification with the specified name is sent to the default notification center
/// (`NotificationCenter.default`) each time a Firebase app check token is refreshed.
/// The user info dictionary contains `-[self notificationTokenKey]` and
/// `-[self notificationAppNameKey]` keys.
- (NSString *)tokenDidChangeNotificationName;

/// `userInfo` key for the FAC token in a notification for `tokenDidChangeNotificationName`.
- (NSString *)notificationTokenKey;
/// `userInfo` key for the `FirebaseApp.name` in a notification for
/// `tokenDidChangeNotificationName`.
- (NSString *)notificationAppNameKey;

@end

NS_ASSUME_NONNULL_END
102 changes: 81 additions & 21 deletions FirebaseAppCheck/Tests/Unit/Core/FIRAppCheckTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ @interface FIRAppCheck (Tests) <FIRAppCheckInterop>
- (instancetype)initWithAppName:(NSString *)appName
appCheckProvider:(id<FIRAppCheckProvider>)appCheckProvider
storage:(id<FIRAppCheckStorageProtocol>)storage
tokenRefresher:(id<FIRAppCheckTokenRefresherProtocol>)tokenRefresher;
tokenRefresher:(id<FIRAppCheckTokenRefresherProtocol>)tokenRefresher
notificationCenter:(NSNotificationCenter *)notificationCenter;

- (nullable instancetype)initWithApp:(FIRApp *)app;
@end
Expand All @@ -51,6 +52,7 @@ @interface FIRAppCheckTests : XCTestCase
@property(nonatomic) OCMockObject<FIRAppCheckStorageProtocol> *mockStorage;
@property(nonatomic) OCMockObject<FIRAppCheckProvider> *mockAppCheckProvider;
@property(nonatomic) OCMockObject<FIRAppCheckTokenRefresherProtocol> *mockTokenRefresher;
@property(nonatomic) NSNotificationCenter *notificationCenter;
@property(nonatomic) FIRAppCheck<FIRAppCheckInterop> *appCheck;

@property(nonatomic, copy, nullable) FIRAppCheckTokenRefreshBlock tokenRefreshHandler;
Expand All @@ -66,13 +68,15 @@ - (void)setUp {
self.mockStorage = OCMProtocolMock(@protocol(FIRAppCheckStorageProtocol));
self.mockAppCheckProvider = OCMProtocolMock(@protocol(FIRAppCheckProvider));
self.mockTokenRefresher = OCMProtocolMock(@protocol(FIRAppCheckTokenRefresherProtocol));
self.notificationCenter = [[NSNotificationCenter alloc] init];

[self stubSetTokenRefreshHandler];

self.appCheck = [[FIRAppCheck alloc] initWithAppName:self.appName
appCheckProvider:self.mockAppCheckProvider
storage:self.mockStorage
tokenRefresher:self.mockTokenRefresher];
tokenRefresher:self.mockTokenRefresher
notificationCenter:self.notificationCenter];
}

- (void)tearDown {
Expand Down Expand Up @@ -164,7 +168,11 @@ - (void)testGetToken_WhenNoCache_Success {
OCMExpect([self.mockStorage setToken:tokenToReturn])
.andReturn([FBLPromise resolvedWith:tokenToReturn]);

// 4. Request token.
// 4. Expect token update notification to be sent.
XCTestExpectation *notificationExpectation =
[self tokenUpdateNotificationWithExpectedToken:tokenToReturn.token];

// 5. Request token.
XCTestExpectation *getTokenExpectation = [self expectationWithDescription:@"getToken"];
[self.appCheck getTokenForcingRefresh:NO
completion:^(id<FIRAppCheckTokenResultInterop> tokenResult) {
Expand All @@ -175,8 +183,8 @@ - (void)testGetToken_WhenNoCache_Success {
XCTAssertNil(tokenResult.error);
}];

// 5. Wait for expectations and validate mocks.
[self waitForExpectations:@[ getTokenExpectation ] timeout:0.5];
// 6. Wait for expectations and validate mocks.
[self waitForExpectations:@[ notificationExpectation, getTokenExpectation ] timeout:0.5];
OCMVerifyAll(self.mockStorage);
OCMVerifyAll(self.mockAppCheckProvider);
}
Expand All @@ -191,7 +199,11 @@ - (void)testGetToken_WhenCachedTokenIsValid_Success {
// 2. Don't expect token requested from app check provider.
OCMReject([self.mockAppCheckProvider getTokenWithCompletion:[OCMArg any]]);

// 3. Request token.
// 3. Don't expect token update notification to be sent.
XCTestExpectation *notificationExpectation = [self tokenUpdateNotificationWithExpectedToken:@""];
notificationExpectation.inverted = YES;

// 4. Request token.
XCTestExpectation *getTokenExpectation = [self expectationWithDescription:@"getToken"];
[self.appCheck getTokenForcingRefresh:NO
completion:^(id<FIRAppCheckTokenResultInterop> tokenResult) {
Expand All @@ -201,8 +213,8 @@ - (void)testGetToken_WhenCachedTokenIsValid_Success {
XCTAssertNil(tokenResult.error);
}];

// 4. Wait for expectations and validate mocks.
[self waitForExpectations:@[ getTokenExpectation ] timeout:0.5];
// 5. Wait for expectations and validate mocks.
[self waitForExpectations:@[ notificationExpectation, getTokenExpectation ] timeout:0.5];
OCMVerifyAll(self.mockStorage);
OCMVerifyAll(self.mockAppCheckProvider);
}
Expand All @@ -221,7 +233,11 @@ - (void)testGetTokenForcingRefresh_WhenCachedTokenIsValid_Success {
OCMExpect([self.mockStorage setToken:tokenToReturn])
.andReturn([FBLPromise resolvedWith:tokenToReturn]);

// 4. Request token.
// 4. Expect token update notification to be sent.
XCTestExpectation *notificationExpectation =
[self tokenUpdateNotificationWithExpectedToken:tokenToReturn.token];

// 5. Request token.
XCTestExpectation *getTokenExpectation = [self expectationWithDescription:@"getToken"];
[self.appCheck getTokenForcingRefresh:YES
completion:^(id<FIRAppCheckTokenResultInterop> tokenResult) {
Expand All @@ -232,8 +248,8 @@ - (void)testGetTokenForcingRefresh_WhenCachedTokenIsValid_Success {
XCTAssertNil(tokenResult.error);
}];

// 5. Wait for expectations and validate mocks.
[self waitForExpectations:@[ getTokenExpectation ] timeout:0.5];
// 6. Wait for expectations and validate mocks.
[self waitForExpectations:@[ notificationExpectation, getTokenExpectation ] timeout:0.5];
OCMVerifyAll(self.mockStorage);
OCMVerifyAll(self.mockAppCheckProvider);
}
Expand All @@ -255,7 +271,11 @@ - (void)testGetToken_WhenCachedTokenExpired_Success {
OCMExpect([self.mockStorage setToken:tokenToReturn])
.andReturn([FBLPromise resolvedWith:tokenToReturn]);

// 4. Request token.
// 4. Expect token update notification to be sent.
XCTestExpectation *notificationExpectation =
[self tokenUpdateNotificationWithExpectedToken:tokenToReturn.token];

// 5. Request token.
XCTestExpectation *getTokenExpectation = [self expectationWithDescription:@"getToken"];
[self.appCheck getTokenForcingRefresh:NO
completion:^(id<FIRAppCheckTokenResultInterop> tokenResult) {
Expand All @@ -265,8 +285,8 @@ - (void)testGetToken_WhenCachedTokenExpired_Success {
XCTAssertNil(tokenResult.error);
}];

// 5. Wait for expectations and validate mocks.
[self waitForExpectations:@[ getTokenExpectation ] timeout:0.5];
// 6. Wait for expectations and validate mocks.
[self waitForExpectations:@[ notificationExpectation, getTokenExpectation ] timeout:0.5];
OCMVerifyAll(self.mockStorage);
OCMVerifyAll(self.mockAppCheckProvider);
}
Expand All @@ -287,7 +307,11 @@ - (void)testGetToken_AppCheckProviderError {
// 3. Don't expect token requested from app check provider.
OCMReject([self.mockAppCheckProvider getTokenWithCompletion:[OCMArg any]]);

// 4. Request token.
// 4. Don't expect token update notification to be sent.
XCTestExpectation *notificationExpectation = [self tokenUpdateNotificationWithExpectedToken:@""];
notificationExpectation.inverted = YES;

// 5. Request token.
XCTestExpectation *getTokenExpectation = [self expectationWithDescription:@"getToken"];
[self.appCheck
getTokenForcingRefresh:NO
Expand All @@ -302,8 +326,8 @@ - (void)testGetToken_AppCheckProviderError {
XCTAssertEqualObjects(result.error, providerError);
}];

// 5. Wait for expectations and validate mocks.
[self waitForExpectations:@[ getTokenExpectation ] timeout:0.5];
// 6. Wait for expectations and validate mocks.
[self waitForExpectations:@[ notificationExpectation, getTokenExpectation ] timeout:0.5];
OCMVerifyAll(self.mockStorage);
OCMVerifyAll(self.mockAppCheckProvider);
}
Expand All @@ -325,7 +349,11 @@ - (void)testTokenRefreshTriggeredAndRefreshSuccess {
OCMExpect([self.mockStorage setToken:tokenToReturn])
.andReturn([FBLPromise resolvedWith:tokenToReturn]);

// 4. Trigger refresh and expect the result.
// 4. Expect token update notification to be sent.
XCTestExpectation *notificationExpectation =
[self tokenUpdateNotificationWithExpectedToken:tokenToReturn.token];

// 5. Trigger refresh and expect the result.
if (self.tokenRefreshHandler == nil) {
XCTFail(@"`tokenRefreshHandler` must be not `nil`.");
return;
Expand All @@ -338,7 +366,7 @@ - (void)testTokenRefreshTriggeredAndRefreshSuccess {
XCTAssertTrue(success);
});

[self waitForExpectations:@[ completionExpectation ] timeout:0.5];
[self waitForExpectations:@[ notificationExpectation, completionExpectation ] timeout:0.5];
OCMVerifyAll(self.mockStorage);
OCMVerifyAll(self.mockAppCheckProvider);
}
Expand All @@ -355,7 +383,11 @@ - (void)testTokenRefreshTriggeredAndRefreshError {
// 3. Don't expect token requested from app check provider.
OCMReject([self.mockAppCheckProvider getTokenWithCompletion:[OCMArg any]]);

// 4. Trigger refresh and expect the result.
// 4. Don't expect token update notification to be sent.
XCTestExpectation *notificationExpectation = [self tokenUpdateNotificationWithExpectedToken:@""];
notificationExpectation.inverted = YES;

// 5. Trigger refresh and expect the result.
if (self.tokenRefreshHandler == nil) {
XCTFail(@"`tokenRefreshHandler` must be not `nil`.");
return;
Expand All @@ -368,11 +400,21 @@ - (void)testTokenRefreshTriggeredAndRefreshError {
XCTAssertFalse(success);
});

[self waitForExpectations:@[ completionExpectation ] timeout:0.5];
[self waitForExpectations:@[ notificationExpectation, completionExpectation ] timeout:0.5];
OCMVerifyAll(self.mockStorage);
OCMVerifyAll(self.mockAppCheckProvider);
}

#pragma mark - Token update notifications

- (void)testTokenUpdateNotificationKeys {
XCTAssertEqualObjects([self.appCheck tokenDidChangeNotificationName],
@"FIRAppCheckAppCheckTokenDidChangeNotification");
XCTAssertEqualObjects([self.appCheck notificationAppNameKey],
@"FIRAppCheckAppNameNotificationKey");
XCTAssertEqualObjects([self.appCheck notificationTokenKey], @"FIRAppCheckTokenNotificationKey");
}

#pragma mark - Helpers

- (void)stubSetTokenRefreshHandler {
Expand All @@ -383,4 +425,22 @@ - (void)stubSetTokenRefreshHandler {
OCMExpect([self.mockTokenRefresher setTokenRefreshHandler:arg]);
}

- (XCTestExpectation *)tokenUpdateNotificationWithExpectedToken:(NSString *)expectedToken {
XCTestExpectation *expectation =
[self expectationForNotification:[self.appCheck tokenDidChangeNotificationName]
object:nil
notificationCenter:self.notificationCenter
handler:^BOOL(NSNotification *_Nonnull notification) {
XCTAssertEqualObjects(
notification.userInfo[[self.appCheck notificationAppNameKey]],
self.appName);
XCTAssertEqualObjects(
notification.userInfo[[self.appCheck notificationTokenKey]],
expectedToken);
return YES;
}];

return expectation;
}

@end
12 changes: 12 additions & 0 deletions SharedTestUtilities/AppCheckFake/FIRAppCheckFake.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,16 @@ - (void)getTokenForcingRefresh:(BOOL)forcingRefresh
});
}

- (nonnull NSString *)notificationAppNameKey {
return @"FakeAppCheckTokenDidChangeNotification";
}

- (nonnull NSString *)notificationTokenKey {
return @"FakeTokenNotificationKey";
}

- (nonnull NSString *)tokenDidChangeNotificationName {
return @"FakeAppCheckTokenDidChangeNotification";
}

@end