diff --git a/native/ios/Comm.xcodeproj/project.pbxproj b/native/ios/Comm.xcodeproj/project.pbxproj --- a/native/ios/Comm.xcodeproj/project.pbxproj +++ b/native/ios/Comm.xcodeproj/project.pbxproj @@ -73,6 +73,7 @@ CB4821AC27CFB17C001AB7E1 /* Session.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 71BF5B6F26B3FF0900EDE27D /* Session.cpp */; }; CB4821AE27CFB187001AB7E1 /* Tools.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 71BF5B7326B401D300EDE27D /* Tools.cpp */; }; CB4821AF27CFB19D001AB7E1 /* PlatformSpecificTools.mm in Sources */ = {isa = PBXBuildFile; fileRef = 71762A74270D8AAE00F565ED /* PlatformSpecificTools.mm */; }; + CB74AB1C2B2AFF6E00CBB494 /* CommServicesAuthMetadataEmitter.mm in Sources */ = {isa = PBXBuildFile; fileRef = CB74AB1B2B2AFF6E00CBB494 /* CommServicesAuthMetadataEmitter.mm */; }; CB7EF17E295C674300B17035 /* CommIOSNotifications.mm in Sources */ = {isa = PBXBuildFile; fileRef = CB7EF17D295C5D1800B17035 /* CommIOSNotifications.mm */; }; CB7EF180295C674300B17035 /* CommIOSNotificationsBridgeQueue.mm in Sources */ = {isa = PBXBuildFile; fileRef = CB7EF17B295C580500B17035 /* CommIOSNotificationsBridgeQueue.mm */; }; CB90951F29534B32002F2A7F /* CommSecureStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 71D4D7CB26C50B1000FCDBCD /* CommSecureStore.mm */; }; @@ -261,6 +262,7 @@ CB38F2BE286C6C980010535C /* DeleteEntryMessageSpec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DeleteEntryMessageSpec.h; path = PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/DeleteEntryMessageSpec.h; sourceTree = ""; }; CB38F2BF286C6C980010535C /* UpdateRelationshipMessageSpec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UpdateRelationshipMessageSpec.h; path = PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/UpdateRelationshipMessageSpec.h; sourceTree = ""; }; CB3C621327CE66540054F24C /* libEXSecureStore.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libEXSecureStore.a; sourceTree = BUILT_PRODUCTS_DIR; }; + CB74AB1B2B2AFF6E00CBB494 /* CommServicesAuthMetadataEmitter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CommServicesAuthMetadataEmitter.mm; path = Comm/CommServicesAuthMetadataEmitter.mm; sourceTree = ""; }; CB7EF17B295C580500B17035 /* CommIOSNotificationsBridgeQueue.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = CommIOSNotificationsBridgeQueue.mm; path = Comm/CommIOSNotifications/CommIOSNotificationsBridgeQueue.mm; sourceTree = ""; }; CB7EF17C295C580500B17035 /* CommIOSNotificationsBridgeQueue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CommIOSNotificationsBridgeQueue.h; path = Comm/CommIOSNotifications/CommIOSNotificationsBridgeQueue.h; sourceTree = ""; }; CB7EF17D295C5D1800B17035 /* CommIOSNotifications.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = CommIOSNotifications.mm; path = Comm/CommIOSNotifications/CommIOSNotifications.mm; sourceTree = ""; }; @@ -362,6 +364,7 @@ 71B8CCB626BD30EC0040C0A2 /* CommCoreImplementations */ = { isa = PBXGroup; children = ( + CB74AB1B2B2AFF6E00CBB494 /* CommServicesAuthMetadataEmitter.mm */, DFD5E77D2B05264000C32B6A /* AESCrypto.mm */, CBCF57A92B05091D00EC4BC0 /* CommAESCryptoUtils */, CB90951729531647002F2A7F /* CommIOSNotifications */, @@ -1078,6 +1081,7 @@ CB38B48628771CDD00171182 /* TemporaryMessageStorage.mm in Sources */, CB38B48428771CAF00171182 /* EncryptedFileUtils.mm in Sources */, CBFE58292885852B003B94C9 /* ThreadOperations.cpp in Sources */, + CB74AB1C2B2AFF6E00CBB494 /* CommServicesAuthMetadataEmitter.mm in Sources */, 8E3994552B039A7C00D5E950 /* UserStore.cpp in Sources */, 7FBB2A7829E945C2002C6493 /* CommUtilsModule.cpp in Sources */, CB38B48228771C7A00171182 /* NonBlockingLock.mm in Sources */, diff --git a/native/ios/Comm/CommServicesAuthMetadataEmitter.mm b/native/ios/Comm/CommServicesAuthMetadataEmitter.mm new file mode 100644 --- /dev/null +++ b/native/ios/Comm/CommServicesAuthMetadataEmitter.mm @@ -0,0 +1,90 @@ +#import "CommServicesAuthMetadataEmitter.h" + +#import +#import +#import + +NSString *const commServicesAuthMetadata = @"commServicesAuthMetadata"; + +@interface CommServicesAuthMetadataEmitterIOSWrapper + : RCTEventEmitter +@property(nonatomic) BOOL hasListeners; + ++ (void)sendAccessTokenToJS:(NSString *)accessToken + withUserID:(NSString *)userID; +@end + +@implementation CommServicesAuthMetadataEmitterIOSWrapper + +RCT_EXPORT_MODULE(CommServicesAuthMetadataEmitter); + +static CommServicesAuthMetadataEmitterIOSWrapper *sharedInstance = nil; + +- (instancetype)init { + self = [super init]; + if (!self) { + return self; + } + _hasListeners = NO; + return self; +} + +- (void)startObserving { + @synchronized([self class]) { + _hasListeners = YES; + sharedInstance = self; + } +} + +- (void)stopObserving { + @synchronized([self class]) { + _hasListeners = NO; + sharedInstance = nil; + } +} + +- (NSArray *)supportedEvents { + return @[ commServicesAuthMetadata ]; +} + +- (NSDictionary *)constantsToExport { + return @{@"COMM_SERVICES_AUTH_METADATA" : commServicesAuthMetadata}; +} + ++ (BOOL)requiresMainQueueSetup { + return YES; +} + ++ (void)sendAccessTokenToJS:(NSString *)accessToken + withUserID:(NSString *)userID { + @synchronized([self class]) { + if (!sharedInstance) { + return; + } + + // Event body must match UserLoginResponse + // type from 'lib/types/identity-service-types.js' + NSDictionary *eventBody = + @{@"accessToken" : accessToken, @"userID" : userID}; + + [sharedInstance sendEventWithName:commServicesAuthMetadata body:eventBody]; + } +} + +@end + +namespace comm { + +void CommServicesAuthMetadataEmitter::sendAuthMetadataToJS( + rust::String accessToken, + rust::String userID) { + NSString *accessTokenObjC = + [NSString stringWithCString:std::string(accessToken).c_str() + encoding:NSUTF8StringEncoding]; + NSString *userIDObjC = [NSString stringWithCString:std::string(userID).c_str() + encoding:NSUTF8StringEncoding]; + + [CommServicesAuthMetadataEmitterIOSWrapper sendAccessTokenToJS:accessTokenObjC + withUserID:userIDObjC]; +} +} // namespace comm