31
31
#import " FirebaseAppCheck/Sources/AppAttestProvider/Storage/FIRAppAttestArtifactStorage.h"
32
32
#import " FirebaseAppCheck/Sources/AppAttestProvider/Storage/FIRAppAttestKeyIDStorage.h"
33
33
#import " FirebaseAppCheck/Sources/Core/APIService/FIRAppCheckAPIService.h"
34
+ #import " FirebaseAppCheck/Sources/Core/Backoff/FIRAppCheckBackoffWrapper.h"
34
35
#import " FirebaseAppCheck/Sources/Core/FIRAppCheckLogger.h"
35
36
36
37
#import " FirebaseAppCheck/Sources/Core/Utils/FIRAppCheckCryptoUtils.h"
@@ -107,6 +108,7 @@ @interface FIRAppAttestProvider ()
107
108
@property (nonatomic , readonly ) id <FIRAppAttestService> appAttestService;
108
109
@property (nonatomic , readonly ) id <FIRAppAttestKeyIDStorageProtocol> keyIDStorage;
109
110
@property (nonatomic , readonly ) id <FIRAppAttestArtifactStorageProtocol> artifactStorage;
111
+ @property (nonatomic , readonly ) id <FIRAppCheckBackoffWrapperProtocol> backoffWrapper;
110
112
111
113
@property (nonatomic , nullable ) FBLPromise<FIRAppCheckToken *> *ongoingGetTokenOperation;
112
114
@@ -119,13 +121,15 @@ @implementation FIRAppAttestProvider
119
121
- (instancetype )initWithAppAttestService : (id <FIRAppAttestService>)appAttestService
120
122
APIService : (id <FIRAppAttestAPIServiceProtocol>)APIService
121
123
keyIDStorage : (id <FIRAppAttestKeyIDStorageProtocol>)keyIDStorage
122
- artifactStorage : (id <FIRAppAttestArtifactStorageProtocol>)artifactStorage {
124
+ artifactStorage : (id <FIRAppAttestArtifactStorageProtocol>)artifactStorage
125
+ backoffWrapper : (id <FIRAppCheckBackoffWrapperProtocol>)backoffWrapper {
123
126
self = [super init ];
124
127
if (self) {
125
128
_appAttestService = appAttestService;
126
129
_APIService = APIService;
127
130
_keyIDStorage = keyIDStorage;
128
131
_artifactStorage = artifactStorage;
132
+ _backoffWrapper = backoffWrapper;
129
133
_queue = dispatch_queue_create (" com.firebase.FIRAppAttestProvider" , DISPATCH_QUEUE_SERIAL);
130
134
}
131
135
return self;
@@ -155,10 +159,13 @@ - (nullable instancetype)initWithApp:(FIRApp *)app {
155
159
appID: app.options.googleAppID
156
160
accessGroup: app.options.appGroupID];
157
161
162
+ FIRAppCheckBackoffWrapper *backoffWrapper = [[FIRAppCheckBackoffWrapper alloc ] init ];
163
+
158
164
return [self initWithAppAttestService: DCAppAttestService.sharedService
159
165
APIService: appAttestAPIService
160
166
keyIDStorage: keyIDStorage
161
- artifactStorage: artifactStorage];
167
+ artifactStorage: artifactStorage
168
+ backoffWrapper: backoffWrapper];
162
169
#else // FIR_APP_ATTEST_SUPPORTED_TARGETS
163
170
return nil ;
164
171
#endif // FIR_APP_ATTEST_SUPPORTED_TARGETS
@@ -185,7 +192,7 @@ - (void)getTokenWithCompletion:(void (^)(FIRAppCheckToken *_Nullable, NSError *_
185
192
// Kick off a new handshake sequence only when there is not an ongoing
186
193
// handshake to avoid race conditions.
187
194
self.ongoingGetTokenOperation =
188
- [self createGetTokenSequencePromise ]
195
+ [self createGetTokenSequenceWithBackoffPromise ]
189
196
190
197
// Release the ongoing operation promise on completion.
191
198
.then (^FIRAppCheckToken *(FIRAppCheckToken *token) {
@@ -201,6 +208,14 @@ - (void)getTokenWithCompletion:(void (^)(FIRAppCheckToken *_Nullable, NSError *_
201
208
}];
202
209
}
203
210
211
+ - (FBLPromise<FIRAppCheckToken *> *)createGetTokenSequenceWithBackoffPromise {
212
+ return [self .backoffWrapper
213
+ applyBackoffToOperation: ^FBLPromise *_Nonnull {
214
+ return [self createGetTokenSequencePromise ];
215
+ }
216
+ errorHandler: [self .backoffWrapper defaultAppCheckProviderErrorHandler ]];
217
+ }
218
+
204
219
- (FBLPromise<FIRAppCheckToken *> *)createGetTokenSequencePromise {
205
220
// Check attestation state to decide on the next steps.
206
221
return [self attestationState ].thenOn (self.queue , ^id (FIRAppAttestProviderState *attestState) {
0 commit comments