Skip to content

Commit d4588f5

Browse files
authored
Merge pull request #1487 from OneSignal/identity_verification_multiple_users
[JWT] Improve management of multiple users + finalize API
2 parents 74e4ef7 + 1e7bce1 commit d4588f5

33 files changed

+698
-312
lines changed

iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#import <UIKit/UIKit.h>
3232
#import <OneSignalFramework/OneSignalFramework.h>
3333

34-
@interface AppDelegate : UIResponder <UIApplicationDelegate, OSNotificationPermissionObserver, OSInAppMessageLifecycleListener, OSPushSubscriptionObserver, OSNotificationLifecycleListener, OSInAppMessageClickListener, OSNotificationClickListener, OSUserStateObserver>
34+
@interface AppDelegate : UIResponder <UIApplicationDelegate, OSNotificationPermissionObserver, OSInAppMessageLifecycleListener, OSPushSubscriptionObserver, OSNotificationLifecycleListener, OSInAppMessageClickListener, OSNotificationClickListener, OSUserStateObserver, OSUserJwtInvalidatedListener>
3535

3636
@property (strong, nonatomic) UIWindow *window;
3737

iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
7676
[OneSignal.User addObserver:self];
7777
[OneSignal.Notifications addPermissionObserver:self];
7878
[OneSignal.InAppMessages addClickListener:self];
79-
80-
81-
[OneSignal.User onJwtInvalidatedWithInvalidatedHandler:^(OSJwtInvalidatedEvent * _Nonnull invalidatedEvent) {
82-
NSLog(@"JWT INVALIDATED CALLBACK FOR: %@", invalidatedEvent.externalId);
83-
}];
79+
[OneSignal addUserJwtInvalidatedListener:self];
8480

8581
NSLog(@"UNUserNotificationCenter.delegate: %@", UNUserNotificationCenter.currentNotificationCenter.delegate);
8682

@@ -95,8 +91,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
9591
return YES;
9692
}
9793

98-
#define ONESIGNAL_APP_ID_DEFAULT @"0139bd6f-451f-438c-8886-4e0f0fe3a085"
99-
#define ONESIGNAL_APP_ID_KEY_FOR_TESTING @"0139bd6f-451f-438c-8886-4e0f0fe3a085"
94+
#define ONESIGNAL_APP_ID_DEFAULT @"77e32082-ea27-42e3-a898-c72e141824ef"
95+
#define ONESIGNAL_APP_ID_KEY_FOR_TESTING @"77e32082-ea27-42e3-a898-c72e141824ef"
10096

10197
+ (NSString*)getOneSignalAppId {
10298
NSString* userDefinedAppId = [[NSUserDefaults standardUserDefaults] objectForKey:ONESIGNAL_APP_ID_KEY_FOR_TESTING];
@@ -130,6 +126,10 @@ - (void)onUserStateDidChangeWithState:(OSUserChangedState * _Nonnull)state {
130126
NSLog(@"Dev App onUserStateDidChangeWithState: %@", [state jsonRepresentation]);
131127
}
132128

129+
- (void)onUserJwtInvalidatedWithEvent:(OSUserJwtInvalidatedEvent * _Nonnull)event {
130+
NSLog(@"Dev App onUserJwtInvalidatedWithEvent: %@", [event jsonRepresentation]);
131+
}
132+
133133
#pragma mark OSInAppMessageDelegate
134134

135135
- (void)onClickInAppMessage:(OSInAppMessageClickEvent * _Nonnull)event {

iOS_SDK/OneSignalDevApp/OneSignalDevApp/SwiftTest.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@
2828
import Foundation
2929
import OneSignalFramework
3030

31-
class SwiftTest: NSObject {
31+
class SwiftTest: NSObject, OSUserJwtInvalidatedListener {
32+
func onUserJwtInvalidated(event: OSUserJwtInvalidatedEvent) {
33+
print("event: \(event.jsonRepresentation())")
34+
print("externalId: \(event.externalId)")
35+
}
36+
3237
func testSwiftUserModel() {
3338
let token1 = OneSignal.User.pushSubscription.token
3439
let token = OneSignal.User.pushSubscription.token
3540
OneSignal.Debug._dump()
41+
OneSignal.login(externalId: "euid", token: "token")
42+
OneSignal.updateUserJwt(externalId: "euid", token: "token")
43+
OneSignal.addUserJwtInvalidatedListener(self)
44+
OneSignal.removeUserJwtInvalidatedListener(self)
3645
}
3746
}

iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ - (IBAction)inAppMessagingSegmentedControlValueChanged:(UISegmentedControl *)sen
197197
- (IBAction)loginExternalUserId:(UIButton *)sender {
198198
NSString* externalUserId = self.externalUserIdTextField.text;
199199
NSString* token = self.tokenTextField.text;
200-
NSLog(@"Dev App: Logging in to external user ID %@ and token %@", externalUserId, token);
200+
NSLog(@"Dev App: Logging in to external user ID %@ and token %@", externalUserId, token);
201201
[OneSignal login:externalUserId withToken:token];
202202
}
203203

204204
- (IBAction)updateJwt:(id)sender {
205205
NSString* externalUserId = self.externalUserIdTextField.text;
206206
NSString* token = self.tokenTextField.text;
207-
NSLog(@"Dev App: updating JWT for external user ID %@ and token %@", externalUserId, token);
207+
NSLog(@"Dev App: updating JWT for external user ID %@ and token %@", externalUserId, token);
208208
[OneSignal updateUserJwt:externalUserId withToken:token];
209209
}
210210

iOS_SDK/OneSignalDevApp/OneSignalExample.xcodeproj/project.pbxproj

Lines changed: 221 additions & 6 deletions
Large diffs are not rendered by default.

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
3C47A975292642B100312125 /* OneSignalConfigManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C47A973292642B100312125 /* OneSignalConfigManager.m */; };
8989
3C4F9E4428A4466C009F453A /* OSOperationRepo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C4F9E4328A4466C009F453A /* OSOperationRepo.swift */; };
9090
3C5117172B15C31E00563465 /* OSUserState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C5117162B15C31E00563465 /* OSUserState.swift */; };
91+
3C5929E32CAD9EC50020D6FF /* OneSignalUserManagerImpl+OSLoggable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C5929E22CAD9EC50020D6FF /* OneSignalUserManagerImpl+OSLoggable.swift */; };
92+
3C5929E52CAE523E0020D6FF /* MockUserJwtInvalidatedListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C5929E42CAE523E0020D6FF /* MockUserJwtInvalidatedListener.swift */; };
9193
3C62999F2BEEA34800649187 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3C62999E2BEEA34800649187 /* PrivacyInfo.xcprivacy */; };
9294
3C6299A12BEEA38100649187 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3C6299A02BEEA38100649187 /* PrivacyInfo.xcprivacy */; };
9395
3C6299A32BEEA3CC00649187 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3C6299A22BEEA3CC00649187 /* PrivacyInfo.xcprivacy */; };
@@ -350,7 +352,7 @@
350352
DE16C14524D3724700670EFA /* OneSignalLifecycleObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = DE16C14324D3724700670EFA /* OneSignalLifecycleObserver.m */; };
351353
DE16C14724D3727200670EFA /* OneSignalLifecycleObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = DE16C14624D3727200670EFA /* OneSignalLifecycleObserver.h */; };
352354
DE16C17024D3989A00670EFA /* OneSignalLifecycleObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = DE16C14324D3724700670EFA /* OneSignalLifecycleObserver.m */; };
353-
DE1DD0602C87D87B00787071 /* OSJwtInvalidatedEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE1DD05F2C87D87B00787071 /* OSJwtInvalidatedEvent.swift */; };
355+
DE1DD0602C87D87B00787071 /* OSUserJwtInvalidatedEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE1DD05F2C87D87B00787071 /* OSUserJwtInvalidatedEvent.swift */; };
354356
DE20425E24E21C2C00350E4F /* UIApplication+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */; };
355357
DE20425F24E21C2C00350E4F /* UIApplication+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */; };
356358
DE20426024E21C2C00350E4F /* UIApplication+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */; };
@@ -1249,6 +1251,8 @@
12491251
3C47A973292642B100312125 /* OneSignalConfigManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalConfigManager.m; sourceTree = "<group>"; };
12501252
3C4F9E4328A4466C009F453A /* OSOperationRepo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSOperationRepo.swift; sourceTree = "<group>"; };
12511253
3C5117162B15C31E00563465 /* OSUserState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSUserState.swift; sourceTree = "<group>"; };
1254+
3C5929E22CAD9EC50020D6FF /* OneSignalUserManagerImpl+OSLoggable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OneSignalUserManagerImpl+OSLoggable.swift"; sourceTree = "<group>"; };
1255+
3C5929E42CAE523E0020D6FF /* MockUserJwtInvalidatedListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockUserJwtInvalidatedListener.swift; sourceTree = "<group>"; };
12521256
3C62999E2BEEA34800649187 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
12531257
3C6299A02BEEA38100649187 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
12541258
3C6299A22BEEA3CC00649187 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
@@ -1519,7 +1523,7 @@
15191523
CACBAAAB218A662B000ACAA5 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
15201524
DE16C14324D3724700670EFA /* OneSignalLifecycleObserver.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalLifecycleObserver.m; sourceTree = "<group>"; };
15211525
DE16C14624D3727200670EFA /* OneSignalLifecycleObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalLifecycleObserver.h; sourceTree = "<group>"; };
1522-
DE1DD05F2C87D87B00787071 /* OSJwtInvalidatedEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSJwtInvalidatedEvent.swift; sourceTree = "<group>"; };
1526+
DE1DD05F2C87D87B00787071 /* OSUserJwtInvalidatedEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSUserJwtInvalidatedEvent.swift; sourceTree = "<group>"; };
15231527
DE20425C24E21C1500350E4F /* UIApplication+OneSignal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIApplication+OneSignal.h"; sourceTree = "<group>"; };
15241528
DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIApplication+OneSignal.m"; sourceTree = "<group>"; };
15251529
DE3568E92C88F56600AF447C /* PropertyExecutorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyExecutorTests.swift; sourceTree = "<group>"; };
@@ -2124,7 +2128,7 @@
21242128
3C3130DF2CA383F800906665 /* OSUser.swift */,
21252129
3C3130E22CA3858500906665 /* OSPushSubscription.swift */,
21262130
3C5117162B15C31E00563465 /* OSUserState.swift */,
2127-
DE1DD05F2C87D87B00787071 /* OSJwtInvalidatedEvent.swift */,
2131+
DE1DD05F2C87D87B00787071 /* OSUserJwtInvalidatedEvent.swift */,
21282132
);
21292133
path = Public;
21302134
sourceTree = "<group>";
@@ -2208,6 +2212,7 @@
22082212
3C8706712BDEE076000D8CD2 /* MockUserDefines.swift */,
22092213
3CC063E52B6D7F96002BB07F /* OneSignalUserMocks.swift */,
22102214
DE3568EB2C88F5BD00AF447C /* OneSignalExecutorMocks.swift */,
2215+
3C5929E42CAE523E0020D6FF /* MockUserJwtInvalidatedListener.swift */,
22112216
);
22122217
path = OneSignalUserMocks;
22132218
sourceTree = "<group>";
@@ -2527,6 +2532,7 @@
25272532
3C3130E52CA385B700906665 /* Public */,
25282533
DE69E1A9282ED8790090BB3D /* UnitTestApp-Bridging-Header.h */,
25292534
DE69E1AA282ED8790090BB3D /* OneSignalUserManagerImpl.swift */,
2535+
3C5929E22CAD9EC50020D6FF /* OneSignalUserManagerImpl+OSLoggable.swift */,
25302536
3C0EF49D28A1DBCB00E5434B /* OSUserInternalImpl.swift */,
25312537
3C277D7D2BD76E0000857606 /* OSIdentityModelRepo.swift */,
25322538
);
@@ -4164,6 +4170,7 @@
41644170
3C8706702BDE0957000D8CD2 /* MockUserRequests.swift in Sources */,
41654171
3C8706722BDEE076000D8CD2 /* MockUserDefines.swift in Sources */,
41664172
3CC063E62B6D7F96002BB07F /* OneSignalUserMocks.swift in Sources */,
4173+
3C5929E52CAE523E0020D6FF /* MockUserJwtInvalidatedListener.swift in Sources */,
41674174
DE3568EC2C88F5BD00AF447C /* OneSignalExecutorMocks.swift in Sources */,
41684175
);
41694176
runOnlyForDeploymentPostprocessing = 0;
@@ -4327,7 +4334,8 @@
43274334
files = (
43284335
3CE795F928DB99B500736BD4 /* OSSubscriptionModelStoreListener.swift in Sources */,
43294336
DE69E1AC282ED87A0090BB3D /* OneSignalUserManagerImpl.swift in Sources */,
4330-
DE1DD0602C87D87B00787071 /* OSJwtInvalidatedEvent.swift in Sources */,
4337+
DE1DD0602C87D87B00787071 /* OSUserJwtInvalidatedEvent.swift in Sources */,
4338+
3C5929E32CAD9EC50020D6FF /* OneSignalUserManagerImpl+OSLoggable.swift in Sources */,
43314339
3C9AD6CF2B228B7800BC1540 /* OSRequestAddAliases.swift in Sources */,
43324340
3C9AD6D32B228BB000BC1540 /* OSRequestUpdateProperties.swift in Sources */,
43334341
3C9AD6CD2B228B6300BC1540 /* OSRequestFetchUser.swift in Sources */,

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCommonDefines.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
// Networking
3434
#define OS_API_VERSION @"1"
3535
#define OS_API_ACCEPT_HEADER @"application/vnd.onesignal.v" OS_API_VERSION @"+json"
36-
#define OS_API_SERVER_URL @"https://api.staging.onesignal.com/"
37-
#define OS_IAM_WEBVIEW_BASE_URL @"https://staging.onesignal.com/"
36+
#define OS_API_SERVER_URL @"https://api.onesignal.com/"
37+
#define OS_IAM_WEBVIEW_BASE_URL @"https://onesignal.com/"
3838

3939
// OneSignalUserDefault keys
4040
// String values start with "OSUD_" to maintain a level of uniqueness from other libs and app code
@@ -79,7 +79,6 @@
7979
#define OSUD_REQUIRES_USER_PRIVACY_CONSENT @"OSUD_REQUIRES_USER_PRIVACY_CONSENT"
8080

8181
/* Identity Verification */
82-
// TODO: JWT 🔐 Figure out the key below and may need to relate to existing key IOS_REQUIRES_USER_ID_AUTHENTICATION
8382
#define OSUD_USE_IDENTITY_VERIFICATION @"OSUD_USE_IDENTITY_VERIFICATION"
8483
#define OS_JWT_BEARER_TOKEN @"OS_JWT_BEARER_TOKEN"
8584
#define OS_JWT_TOKEN_INVALID @"OS_JWT_TOKEN_INVALID"
@@ -135,7 +134,7 @@
135134
#define IOS_USES_PROVISIONAL_AUTHORIZATION @"uses_provisional_auth"
136135
#define IOS_REQUIRES_EMAIL_AUTHENTICATION @"require_email_auth"
137136
#define IOS_REQUIRES_SMS_AUTHENTICATION @"require_sms_auth"
138-
#define IOS_REQUIRES_USER_ID_AUTHENTICATION @"require_user_id_auth" // TODO: JWT 🔐 Figure out the key, also think about needing to migrate this value
137+
#define IOS_JWT_REQUIRED @"jwt_required" // Returned by remote params
139138
#define IOS_RECEIVE_RECEIPTS_ENABLE @"receive_receipts_enable"
140139
#define IOS_OUTCOMES_V2_SERVICE_ENABLE @"v2_enabled"
141140
#define IOS_LOCATION_SHARED @"location_shared"

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalMobileProvision.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ + (OSUIApplicationReleaseMode) releaseMode {
8787
NSDictionary *entitlements = nil;
8888
NSDictionary *provision = [self getProvision];
8989
if (provision) {
90-
// [OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"provision: %@", provision]];
90+
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"provision: %@", provision]];
9191
entitlements = [provision objectForKey:@"Entitlements"];
9292
}
9393
else

iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSMessagingController.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,6 @@ - (void)onPushSubscriptionDidChangeWithState:(OSPushSubscriptionChangedState * _
11541154

11551155
#pragma mark OSUserStateObserver Methods
11561156
- (void)onUserStateDidChangeWithState:(OSUserChangedState * _Nonnull)state {
1157-
NSLog(@"❌ OSMessagingController onUserStateDidChangeWithState: %@", [state jsonRepresentation]);
11581157
if (state.current.onesignalId && shouldRetryGetInAppMessagesOnUserChange) {
11591158
shouldRetryGetInAppMessagesOnUserChange = false;
11601159
[self getInAppMessagesFromServer];
@@ -1167,7 +1166,6 @@ - (void)onRequiresUserAuthChangedFrom:(enum OSRequiresUserAuth)from to:(enum OSR
11671166
}
11681167

11691168
- (void)onJwtUpdatedWithExternalId:(NSString *)externalId token:(NSString *)token {
1170-
NSLog(@"❌ OSMessagingController onJwtUpdatedWithExternalId: %@ token: %@", externalId, token);
11711169
if (![token isEqual: OS_JWT_TOKEN_INVALID] && shouldRetryGetInAppMessagesOnJwtUpdated) {
11721170
shouldRetryGetInAppMessagesOnJwtUpdated = false;
11731171
[self getInAppMessagesFromServer];

iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Jwt/OSUserJwtConfig.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ public class OSUserJwtConfig {
6464
return
6565
}
6666

67-
print("❌ OSUserJwtConfig.requiresUserAuth: changing from \(oldValue) to \(requiresUserAuth), firing \(changeNotifier)")
68-
67+
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSUserJwtConfig.requiresUserAuth: changing from \(oldValue) to \(requiresUserAuth), firing listeners")
6968
// Persist new value
7069
OneSignalUserDefaults.initShared().saveInteger(forKey: OSUD_USE_IDENTITY_VERIFICATION, withValue: requiresUserAuth.rawValue)
7170

@@ -93,9 +92,6 @@ public class OSUserJwtConfig {
9392

9493
public init() {
9594
let rawValue = OneSignalUserDefaults.initShared().getSavedInteger(forKey: OSUD_USE_IDENTITY_VERIFICATION, defaultValue: OSRequiresUserAuth.unknown.rawValue)
96-
97-
print("❌ OSUserJwtConfig init(): \(String(describing: OSRequiresUserAuth(rawValue: rawValue))))")
98-
9995
requiresUserAuth = OSRequiresUserAuth(rawValue: rawValue) ?? OSRequiresUserAuth.unknown
10096
}
10197

@@ -104,7 +100,7 @@ public class OSUserJwtConfig {
104100
}
105101

106102
public func onJwtTokenChanged(externalId: String, token: String?) {
107-
print("OSUserJwtConfig.onJwtTokenChanged \(externalId): \(token)")
103+
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSUserJwtConfig.onJwtTokenChanged for \(externalId) with token \(token ?? "nil"), firing listeners")
108104
changeNotifier.fire { listener in
109105
listener.onJwtUpdated(externalId: externalId, token: token)
110106
}

0 commit comments

Comments
 (0)