Skip to content

Commit

Permalink
Fire JWT callback from IAMs
Browse files Browse the repository at this point in the history
This will always fire it for 401 even if JWT is not required, so validate the JWT config in the user manager before firing the callback
  • Loading branch information
emawby committed Sep 11, 2024
1 parent 5afab13 commit 1d0b97f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ - (void)initializeTriggerController {
- (void)updateInAppMessagesFromCache {
self.messages = [OneSignalUserDefaults.initStandard getSavedCodeableDataForKey:OS_IAM_MESSAGES_ARRAY defaultValue:[NSArray new]];
// ECM THIS NEEDS TO RUN ON THE MAIN THREAD
[self evaluateMessages];
dispatch_async(dispatch_get_main_queue(), ^{
[self evaluateMessages];
});
}

/**
Expand Down Expand Up @@ -324,11 +326,16 @@ - (void)getInAppMessagesFromServer {
OSResponseStatusType responseType = [OSNetworkingUtils getResponseStatusType:error.code];
if (responseType == OSResponseStatusUnauthorized) {
shouldRetryGetInAppMessagesOnJwtUpdated = true;
[self handleUnauthroizedError:error externalId:alias.id];
}
[self updateInAppMessagesFromCache];
}];
}

- (void)handleUnauthroizedError:(NSError*)error externalId:(NSString *)externalId {
[OneSignalUserManagerImpl.sharedInstance invalidateJwtForExternalIdWithExternalId:externalId error:error];
}

- (void)updateInAppMessagesFromServer:(NSArray<OSInAppMessageInternal *> *)newMessages {
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"updateInAppMessagesFromServer"];
self.messages = newMessages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,10 @@ extension OneSignalUserManagerImpl {

@objc
public func invalidateJwtForExternalId(externalId: String, error: NSError) {
guard jwtConfig.isRequired == true, let identityModel = identityModelRepo.get(externalId: externalId) else {
guard jwtConfig.isRequired == true else {
return
}
guard let identityModel = identityModelRepo.get(externalId: externalId) else {
OneSignalLog.onesignalLog(.LL_ERROR, message: "Unable to find identity model for externalId: \(externalId)")
return
}
Expand Down

0 comments on commit 1d0b97f

Please sign in to comment.