Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@
7AFE856B2368DDB80091D6A5 /* OSFocusCallParams.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFE856A2368DDB80091D6A5 /* OSFocusCallParams.m */; };
7AFE856C2368DDB80091D6A5 /* OSFocusCallParams.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFE856A2368DDB80091D6A5 /* OSFocusCallParams.m */; };
7AFE856D2368DDB80091D6A5 /* OSFocusCallParams.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFE856A2368DDB80091D6A5 /* OSFocusCallParams.m */; };
8E949FF4C7A7A2C7182E53EA /* OSUserJwtConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9376A4957E9090C748BCB18 /* OSUserJwtConfigTests.swift */; };
911E2CBD1E398AB3003112A4 /* UnitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 911E2CBC1E398AB3003112A4 /* UnitTests.m */; };
911E2CC51E398B53003112A4 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E08E2701D49A5C8002176DE /* SystemConfiguration.framework */; };
911E2CC61E398B97003112A4 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 37E6B2BA19D9CAF300D0C601 /* UIKit.framework */; };
Expand Down Expand Up @@ -382,8 +383,10 @@
9D34853A233D2E3600EB81C9 /* OneSignalLocationOverrider.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D348539233D2E3600EB81C9 /* OneSignalLocationOverrider.m */; };
9D59C2F82321C7720008ECCF /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CACBAAAB218A662B000ACAA5 /* WebKit.framework */; };
9D59C2F92321C7780008ECCF /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9D3300F923149DAE000F0A83 /* CoreGraphics.framework */; };
9FF50E2A40C88E4533033A38 /* OSIdentityVerificationServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4855B81F170253FB0C1749D /* OSIdentityVerificationServiceTests.swift */; };
A662399326850DDE00D52FD8 /* LanguageTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A662399026850DDE00D52FD8 /* LanguageTest.m */; };
A66239952686612F00D52FD8 /* OneSignalFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = 912411F01E73342200E41FD7 /* OneSignalFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
BE737361D82E74544B7A1996 /* OSUserJwtConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6552F2A6DF7776B0582CFAEF /* OSUserJwtConfig.swift */; };
CA08FC871FE99BB4004C445F /* OneSignalClientOverrider.m in Sources */ = {isa = PBXBuildFile; fileRef = CA08FC831FE99BB4004C445F /* OneSignalClientOverrider.m */; };
CA1A6E6920DC2E31001C41B9 /* OneSignalDialogController.h in Headers */ = {isa = PBXBuildFile; fileRef = CA1A6E6720DC2E31001C41B9 /* OneSignalDialogController.h */; };
CA1A6E6A20DC2E31001C41B9 /* OneSignalDialogController.m in Sources */ = {isa = PBXBuildFile; fileRef = CA1A6E6820DC2E31001C41B9 /* OneSignalDialogController.m */; };
Expand Down Expand Up @@ -669,6 +672,7 @@
DEFB3E632BB731BD00E65DAD /* ActivityKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEFB3E622BB731BD00E65DAD /* ActivityKit.framework */; platformFilter = ios; };
DEFB3E652BB7346D00E65DAD /* OSLiveActivities.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFB3E642BB7346D00E65DAD /* OSLiveActivities.swift */; };
DEFB3E672BB735B500E65DAD /* OSStubLiveActivities.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFB3E662BB735B500E65DAD /* OSStubLiveActivities.swift */; };
ECD9DF65FB98056806A43541 /* OSIdentityVerificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4EAEA1BC62D8FC57927511 /* OSIdentityVerificationService.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -1348,6 +1352,7 @@
16664C5425DDB2CB003B8A14 /* NSTimeZoneOverrider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSTimeZoneOverrider.h; sourceTree = "<group>"; };
1AF75EAC1E8567FD0097B315 /* NSString+OneSignal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+OneSignal.h"; sourceTree = "<group>"; };
1AF75EAD1E8567FD0097B315 /* NSString+OneSignal.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+OneSignal.m"; sourceTree = "<group>"; };
1C4EAEA1BC62D8FC57927511 /* OSIdentityVerificationService.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = OSIdentityVerificationService.swift; sourceTree = "<group>"; };
37747F9319147D6500558FAD /* libOneSignal.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libOneSignal.a; sourceTree = BUILT_PRODUCTS_DIR; };
37E6B2BA19D9CAF300D0C601 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
3C01518E2C2E298E0079E076 /* OneSignalInAppMessagesTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OneSignalInAppMessagesTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -1543,6 +1548,7 @@
5BC1DE612C90B85A00CA8807 /* OSIamFetchOffsetKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSIamFetchOffsetKey.swift; sourceTree = "<group>"; };
5BC1DE632C90BB9000CA8807 /* OSIamFetchReadyCondition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSIamFetchReadyCondition.swift; sourceTree = "<group>"; };
5BC1DE672C90C23E00CA8807 /* OSConsistencyManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSConsistencyManagerTests.swift; sourceTree = "<group>"; };
6552F2A6DF7776B0582CFAEF /* OSUserJwtConfig.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = OSUserJwtConfig.swift; sourceTree = "<group>"; };
7A123294235DFE3B002B6CE3 /* OutcomeTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OutcomeTests.m; sourceTree = "<group>"; };
7A12EBD523060A6F005C4FA5 /* OSSessionManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSSessionManager.m; sourceTree = "<group>"; };
7A12EBD623060A6F005C4FA5 /* OSSessionManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSSessionManager.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1868,6 +1874,8 @@
DEFB3E622BB731BD00E65DAD /* ActivityKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ActivityKit.framework; path = System/Library/Frameworks/ActivityKit.framework; sourceTree = SDKROOT; };
DEFB3E642BB7346D00E65DAD /* OSLiveActivities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSLiveActivities.swift; sourceTree = "<group>"; };
DEFB3E662BB735B500E65DAD /* OSStubLiveActivities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSStubLiveActivities.swift; sourceTree = "<group>"; };
E9376A4957E9090C748BCB18 /* OSUserJwtConfigTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = OSUserJwtConfigTests.swift; sourceTree = "<group>"; };
F4855B81F170253FB0C1749D /* OSIdentityVerificationServiceTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = OSIdentityVerificationServiceTests.swift; sourceTree = "<group>"; };
FF4B19D1EC31C0750F13065A /* OSIamFetchReadyConditionTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = OSIamFetchReadyConditionTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -2309,6 +2317,7 @@
4710EA522B8FCFB200435356 /* OSDispatchQueue.swift */,
DEFB3E642BB7346D00E65DAD /* OSLiveActivities.swift */,
DEFB3E662BB735B500E65DAD /* OSStubLiveActivities.swift */,
A843B922174496E99F2D00A8 /* Jwt */,
);
path = Source;
sourceTree = "<group>";
Expand Down Expand Up @@ -2614,10 +2623,21 @@
3C23A21E2FCE0AA1001D32E3 /* OSResilientStorageTests.swift */,
3C23A21C2FCE0A83001D32E3 /* OSModelStoreRefreshTests.swift */,
FF4B19D1EC31C0750F13065A /* OSIamFetchReadyConditionTests.swift */,
5B47CE0CE255AC7128442FFF /* Jwt */,
);
path = OneSignalOSCoreTests;
sourceTree = "<group>";
};
5B47CE0CE255AC7128442FFF /* Jwt */ = {
isa = PBXGroup;
children = (
F4855B81F170253FB0C1749D /* OSIdentityVerificationServiceTests.swift */,
E9376A4957E9090C748BCB18 /* OSUserJwtConfigTests.swift */,
);
name = Jwt;
path = Jwt;
sourceTree = "<group>";
};
5BC1DE652C90BC9F00CA8807 /* Consistency */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2773,6 +2793,16 @@
name = Categories;
sourceTree = "<group>";
};
A843B922174496E99F2D00A8 /* Jwt */ = {
isa = PBXGroup;
children = (
1C4EAEA1BC62D8FC57927511 /* OSIdentityVerificationService.swift */,
6552F2A6DF7776B0582CFAEF /* OSUserJwtConfig.swift */,
);
name = Jwt;
path = Jwt;
sourceTree = "<group>";
};
DE51DDE2294262670073D5C4 /* RemoteParameters */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -4515,6 +4545,8 @@
3C11518D289AF5E800565C41 /* OSModelChangedHandler.swift in Sources */,
3C14E3B32FAE54C006ED053 /* OSLoggerPlatformProvider.swift in Sources */,
3C8E6DF928A6D89E0031E48A /* OSOperationExecutor.swift in Sources */,
ECD9DF65FB98056806A43541 /* OSIdentityVerificationService.swift in Sources */,
BE737361D82E74544B7A1996 /* OSUserJwtConfig.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -4660,6 +4692,8 @@
C781A33FED62B4B54221A09A /* OSLogCrashHandlerTests.swift in Sources */,
3C23A21B2FCE0A52001D32E3 /* OneSignalIdentifiersFallbackTests.swift in Sources */,
DD2A89A8052E2D1912B0038B /* OSIamFetchReadyConditionTests.swift in Sources */,
9FF50E2A40C88E4533033A38 /* OSIdentityVerificationServiceTests.swift in Sources */,
8E949FF4C7A7A2C7182E53EA /* OSUserJwtConfigTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
// Remote SDK feature flags (Turbine GET apps/{app_id}/sdk/features/{platform}/{sdk_version})
#define OSUD_SDK_REMOTE_FEATURE_FLAGS @"OSUD_SDK_REMOTE_FEATURE_FLAGS"
#define OSUD_SDK_REMOTE_FEATURE_FLAG_METADATA @"OSUD_SDK_REMOTE_FEATURE_FLAG_METADATA"
#define OSUD_USE_IDENTITY_VERIFICATION @"OSUD_USE_IDENTITY_VERIFICATION"
// Remote Params - Receive Receipts
#define OSUD_RECEIVE_RECEIPTS_ENABLED @"OS_ENABLE_RECEIVE_RECEIPTS" // * OSUD_RECEIVE_RECEIPTS_ENABLED
// Outcomes
Expand Down Expand Up @@ -132,7 +133,7 @@
#define IOS_USES_PROVISIONAL_AUTHORIZATION @"uses_provisional_auth"
#define IOS_REQUIRES_EMAIL_AUTHENTICATION @"require_email_auth"
#define IOS_REQUIRES_SMS_AUTHENTICATION @"require_sms_auth"
#define IOS_REQUIRES_USER_ID_AUTHENTICATION @"require_user_id_auth"
#define IOS_JWT_REQUIRED @"jwt_required"
#define IOS_RECEIVE_RECEIPTS_ENABLE @"receive_receipts_enable"
#define IOS_OUTCOMES_V2_SERVICE_ENABLE @"v2_enabled"
#define IOS_LOCATION_SHARED @"location_shared"
Expand Down Expand Up @@ -321,6 +322,15 @@ typedef enum {GET, POST, HEAD, PUT, DELETE, OPTIONS, CONNECT, TRACE, PATCH} HTTP
#define OS_SNAPSHOT_ONESIGNAL_ID @"OS_SNAPSHOT_ONESIGNAL_ID"
#define OS_SNAPSHOT_EXTERNAL_ID @"OS_SNAPSHOT_EXTERNAL_ID"

/* Identity Verification */
#define OS_JWT_BEARER_TOKEN @"OS_JWT_BEARER_TOKEN"
#define OS_JWT_TOKEN_INVALID @"OS_JWT_TOKEN_INVALID"

// Posted when work held for want of an answer can be reattempted: the requirement hydrated, or the app
// supplied a token. Listeners re-read the current state rather than take anything from the post.
#define OS_ON_JWT_CONFIG_HYDRATED @"OS_ON_JWT_CONFIG_HYDRATED"
#define OS_ON_USER_JWT_UPDATED @"OS_ON_USER_JWT_UPDATED"

// Models and Model Stores
#define OS_IDENTITY_MODEL_KEY @"OS_IDENTITY_MODEL_KEY"
#define OS_IDENTITY_MODEL_STORE_KEY @"OS_IDENTITY_MODEL_STORE_KEY"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
Modified MIT License

Copyright 2026 OneSignal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

1. The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

2. All copies of substantial portions of the Software may only be used in connection
with services provided by OneSignal.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import Foundation
import OneSignalCore
@_implementationOnly import OneSignalKMP

/// Who is waiting on hydration. Keyed so re-registering replaces rather than stacking a duplicate.
public enum OSJwtConfigHydratedObserver {
case userExecutor
case operationRepo
case userManager
}

/**
Decides Identity Verification gating from the rollout feature flag and the app's `jwt_required`
setting.

- `ivBehaviorActive`: whether IV behavior is in effect (JWT on requests, `external_id` alias, 401
handling).
- `newCodePathsRun`: whether IV code paths should run at all (feature flag, or always when the app
requires auth).
- `requirement`: use when you must tell `unknown` apart from `off` — both booleans are `false` while
the requirement is unknown, which is fine for apps that do not require Identity Verification, but
callers that must not send an unsigned request should wait until it is known.
*/
public final class OSIdentityVerificationService {
private let featureManager: OSFeatureManager
private let jwtConfig: OSUserJwtConfig

private let handlerLock = NSLock()
// Ordered by registration: User executor's held Create User before Deltas that need its onesignal_id.
private var jwtConfigHydratedHandlers: [(observer: OSJwtConfigHydratedObserver, handler: (OSRequiresUserAuth) -> Void)] = []

/// The raw `jwt_required` value, including `unknown` before remote params arrive.
public var requirement: OSRequiresUserAuth {
return jwtConfig.requirement
}

/// Whether Identity Verification behavior applies: JWT on requests, `external_id` alias, 401 handling.
public var ivBehaviorActive: Bool {
return jwtConfig.requirement == .on
}

/// Whether the new Identity Verification code paths run at all. An app that requires auth is always in,
/// no matter how the rollout flag is set.
public var newCodePathsRun: Bool {
return featureManager.isEnabled(featureKey: FeatureFlag.sdkIdentityVerification.key) || ivBehaviorActive
}

public init(featureManager: OSFeatureManager, jwtConfig: OSUserJwtConfig) {
self.featureManager = featureManager
self.jwtConfig = jwtConfig
jwtConfig.setOnHydratedHandler { [weak self] requirement in
self?.fireJwtConfigHydrated(requirement)
}
}

/**
Fires on every hydration, including an unchanged value — deferred work waits on that. A handler
registered after `requirement` is already known runs immediately, since that hydration is not repeated.
*/
public func addOnJwtConfigHydratedHandler(for observer: OSJwtConfigHydratedObserver, _ handler: @escaping (OSRequiresUserAuth) -> Void) {
let alreadyKnown = handlerLock.withLock { () -> OSRequiresUserAuth in
if let index = jwtConfigHydratedHandlers.firstIndex(where: { $0.observer == observer }) {
jwtConfigHydratedHandlers[index] = (observer, handler)
} else {
jwtConfigHydratedHandlers.append((observer, handler))
}
return jwtConfig.requirement
}

guard alreadyKnown != .unknown else {
return
}
handler(alreadyKnown)
Comment thread
nan-li marked this conversation as resolved.
}

public func removeOnJwtConfigHydratedHandler(for observer: OSJwtConfigHydratedObserver) {
handlerLock.withLock {
jwtConfigHydratedHandlers.removeAll { $0.observer == observer }
}
}

private func fireJwtConfigHydrated(_ requirement: OSRequiresUserAuth) {
// Snapshot: a handler can register another, and handlers take locks of their own.
let handlers = handlerLock.withLock { jwtConfigHydratedHandlers }
for entry in handlers {
entry.handler(requirement)
}
}
}
Loading
Loading