|
31 | 31 | FirebaseAppCheckCredentialsProvider::FirebaseAppCheckCredentialsProvider(
|
32 | 32 | FIRApp* app, id<FIRAppCheckInterop> app_check) {
|
33 | 33 | contents_ = std::make_shared<Contents>(app, app_check);
|
34 |
| - std::weak_ptr<Contents> weak_contents = contents_; |
35 | 34 |
|
| 35 | + if (app_check == nil) { |
| 36 | + return; |
| 37 | + } |
| 38 | + |
| 39 | + std::weak_ptr<Contents> weak_contents = contents_; |
36 | 40 | app_check_listener_handle_ = [[NSNotificationCenter defaultCenter]
|
37 | 41 | addObserverForName:[app_check tokenDidChangeNotificationName]
|
38 | 42 | object:nil
|
|
73 | 77 |
|
74 | 78 | void FirebaseAppCheckCredentialsProvider::GetToken(
|
75 | 79 | TokenListener<std::string> completion) {
|
76 |
| - HARD_ASSERT(app_check_listener_handle_, |
77 |
| - "GetToken cannot be called after listener removed."); |
78 |
| - |
79 |
| - void (^get_token_callback)(id<FIRAppCheckTokenResultInterop>) = |
80 |
| - ^(id<FIRAppCheckTokenResultInterop> result) { |
81 |
| - if (result.error != nil) { |
82 |
| - LOG_WARN("AppCheck failed: '%s'", |
83 |
| - util::MakeString(result.error.localizedDescription)); |
84 |
| - } |
85 |
| - completion(util::MakeString(result.token)); // Always return token |
86 |
| - }; |
87 |
| - |
88 | 80 | std::weak_ptr<Contents> weak_contents = contents_;
|
89 | 81 | if (contents_->app_check) {
|
| 82 | + void (^get_token_callback)(id<FIRAppCheckTokenResultInterop>) = |
| 83 | + ^(id<FIRAppCheckTokenResultInterop> result) { |
| 84 | + if (result.error != nil) { |
| 85 | + LOG_WARN("AppCheck failed: '%s'", |
| 86 | + util::MakeString(result.error.localizedDescription)); |
| 87 | + } |
| 88 | + completion(util::MakeString(result.token)); // Always return token |
| 89 | + }; |
| 90 | + |
90 | 91 | // Retrieve a cached or generate a new FAC Token. If forcingRefresh == YES
|
91 | 92 | // always generates a new token and updates the cache.
|
92 | 93 | [contents_->app_check getTokenForcingRefresh:force_refresh_
|
|
106 | 107 | // Fire initial event.
|
107 | 108 | change_listener(contents_->current_token);
|
108 | 109 | } else {
|
109 |
| - HARD_ASSERT(app_check_listener_handle_, "removed change_listener twice!"); |
110 | 110 | HARD_ASSERT(change_listener_, "change_listener removed without being set!");
|
111 |
| - [[NSNotificationCenter defaultCenter] |
112 |
| - removeObserver:app_check_listener_handle_]; |
113 |
| - app_check_listener_handle_ = nil; |
| 111 | + if (app_check_listener_handle_) { |
| 112 | + [[NSNotificationCenter defaultCenter] |
| 113 | + removeObserver:app_check_listener_handle_]; |
| 114 | + app_check_listener_handle_ = nil; |
| 115 | + } |
114 | 116 | }
|
115 | 117 |
|
116 | 118 | change_listener_ = change_listener;
|
|
0 commit comments