Skip to content

Commit cd0456e

Browse files
authored
[App Check] Split App Check Component into separate file (#11220)
Extracted the App Check Component (FIRLibrary) into a separate file.
1 parent 370dcd2 commit cd0456e

File tree

3 files changed

+88
-25
lines changed

3 files changed

+88
-25
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheck.h"
20+
21+
NS_ASSUME_NONNULL_BEGIN
22+
23+
@interface FIRAppCheck ()
24+
25+
- (nullable instancetype)initWithApp:(FIRApp *)app;
26+
27+
@end
28+
29+
NS_ASSUME_NONNULL_END

FirebaseAppCheck/Sources/Core/FIRAppCheck.m

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckProviderFactory.h"
2828

2929
#import "FirebaseAppCheck/Sources/Core/Errors/FIRAppCheckErrorUtil.h"
30+
#import "FirebaseAppCheck/Sources/Core/FIRAppCheck+Internal.h"
3031
#import "FirebaseAppCheck/Sources/Core/FIRAppCheckLogger.h"
3132
#import "FirebaseAppCheck/Sources/Core/FIRAppCheckSettings.h"
3233
#import "FirebaseAppCheck/Sources/Core/FIRAppCheckToken+Internal.h"
@@ -38,8 +39,6 @@
3839
#import "FirebaseAppCheck/Interop/FIRAppCheckInterop.h"
3940
#import "FirebaseAppCheck/Interop/FIRAppCheckTokenResultInterop.h"
4041

41-
#import "FirebaseCore/Extension/FirebaseCoreInternal.h"
42-
4342
NS_ASSUME_NONNULL_BEGIN
4443

4544
/// A notification with the specified name is sent to the default notification center
@@ -61,7 +60,7 @@
6160

6261
static NSString *const kDummyFACTokenValue = @"eyJlcnJvciI6IlVOS05PV05fRVJST1IifQ==";
6362

64-
@interface FIRAppCheck () <FIRLibrary, FIRAppCheckInterop>
63+
@interface FIRAppCheck () <FIRAppCheckInterop>
6564
@property(class, nullable) id<FIRAppCheckProviderFactory> providerFactory;
6665

6766
@property(nonatomic, readonly) NSString *appName;
@@ -78,28 +77,7 @@ @interface FIRAppCheck () <FIRLibrary, FIRAppCheckInterop>
7877

7978
@implementation FIRAppCheck
8079

81-
#pragma mark - FIRComponents
82-
83-
+ (void)load {
84-
[FIRApp registerInternalLibrary:(Class<FIRLibrary>)self withName:@"fire-app-check"];
85-
}
86-
87-
+ (NSArray<FIRComponent *> *)componentsToRegister {
88-
FIRComponentCreationBlock creationBlock =
89-
^id _Nullable(FIRComponentContainer *container, BOOL *isCacheable) {
90-
*isCacheable = YES;
91-
return [[FIRAppCheck alloc] initWithApp:container.app];
92-
};
93-
94-
// Use eager instantiation timing to give a chance for FAC token to be requested before it is
95-
// actually needed to avoid extra delaying dependent requests.
96-
FIRComponent *appCheckProvider =
97-
[FIRComponent componentWithProtocol:@protocol(FIRAppCheckInterop)
98-
instantiationTiming:FIRInstantiationTimingAlwaysEager
99-
dependencies:@[]
100-
creationBlock:creationBlock];
101-
return @[ appCheckProvider ];
102-
}
80+
#pragma mark - Internal
10381

10482
- (nullable instancetype)initWithApp:(FIRApp *)app {
10583
id<FIRAppCheckProviderFactory> providerFactory = [FIRAppCheck providerFactory];
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
#import "FirebaseAppCheck/Sources/Core/FIRAppCheck+Internal.h"
20+
#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheck.h"
21+
22+
#import "FirebaseAppCheck/Interop/FIRAppCheckInterop.h"
23+
24+
#import "FirebaseCore/Extension/FirebaseCoreInternal.h"
25+
26+
NS_ASSUME_NONNULL_BEGIN
27+
28+
@interface FIRAppCheckComponent : NSObject <FIRLibrary>
29+
@end
30+
31+
@implementation FIRAppCheckComponent
32+
33+
+ (void)load {
34+
[FIRApp registerInternalLibrary:(Class<FIRLibrary>)self withName:@"fire-app-check"];
35+
}
36+
37+
+ (NSArray<FIRComponent *> *)componentsToRegister {
38+
FIRComponentCreationBlock creationBlock =
39+
^id _Nullable(FIRComponentContainer *container, BOOL *isCacheable) {
40+
*isCacheable = YES;
41+
return [[FIRAppCheck alloc] initWithApp:container.app];
42+
};
43+
44+
// Use eager instantiation timing to give a chance for FAC token to be requested before it is
45+
// actually needed to avoid extra delaying dependent requests.
46+
FIRComponent *appCheckProvider =
47+
[FIRComponent componentWithProtocol:@protocol(FIRAppCheckInterop)
48+
instantiationTiming:FIRInstantiationTimingAlwaysEager
49+
dependencies:@[]
50+
creationBlock:creationBlock];
51+
return @[ appCheckProvider ];
52+
}
53+
54+
@end
55+
56+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)