Skip to content

Commit

Permalink
Merge pull request #381 from radarlabs/fraud-failure-reasons
Browse files Browse the repository at this point in the history
Expose token.failureReasons and token._id, add setExpectedJurisdiction(), fix hanging getConfig()
  • Loading branch information
nickpatrick authored Aug 15, 2024
2 parents d98cf66 + 3743591 commit 63c92df
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 9 deletions.
2 changes: 1 addition & 1 deletion RadarSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'RadarSDK'
s.version = '3.16.0'
s.version = '3.16.1'
s.summary = 'iOS SDK for Radar, the leading geofencing and location tracking platform'
s.homepage = 'https://radar.com'
s.author = { 'Radar Labs, Inc.' => '[email protected]' }
Expand Down
6 changes: 3 additions & 3 deletions RadarSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@
DD236C792308797B00EB88F9 /* Info.plist */,
532FC303277A783900989279 /* Radar+Internal.h */,
DD236C9023087A3500EB88F9 /* Radar.m */,
F667F8282BFBF3D1001F2F67 /* RadarSdkConfiguration.h */,
DD236C9823087F9200EB88F9 /* RadarAPIClient.h */,
DD236C9923087F9200EB88F9 /* RadarAPIClient.m */,
DD633EC1237C5B800026C91A /* RadarAPIHelper.h */,
Expand Down Expand Up @@ -495,6 +494,7 @@
82D04ABA29722ED20036619F /* RadarReplayBuffer.h */,
82D04AB929722ED20036619F /* RadarReplayBuffer.m */,
DD236C782308797B00EB88F9 /* RadarSDK.h */,
F667F8282BFBF3D1001F2F67 /* RadarSdkConfiguration.h */,
F667F8262BFBF3C8001F2F67 /* RadarSdkConfiguration.m */,
DD236CFB230895D400EB88F9 /* RadarSettings.h */,
DD236CFC230895D400EB88F9 /* RadarSettings.m */,
Expand Down Expand Up @@ -1022,7 +1022,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.16.0;
MARKETING_VERSION = 3.16.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1080,7 +1080,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.16.0;
MARKETING_VERSION = 3.16.1;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
OTHER_CFLAGS = "-fembed-bitcode";
Expand Down
8 changes: 8 additions & 0 deletions RadarSDK/Include/Radar.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,14 @@ typedef void (^_Nonnull RadarLogConversionCompletionHandler)(RadarStatus status,
*/
+ (void)getVerifiedLocationToken:(RadarTrackVerifiedCompletionHandler _Nullable)completionHandler NS_SWIFT_NAME(getVerifiedLocationToken(completionHandler:));

/**
Optionally sets the user's expected country and state for jurisdiction checks.
@param countryCode The user's expected two-letter country code.
@param stateCode The user's expected two-letter state code.
*/
+ (void)setExpectedJurisdictionWithCountryCode:(NSString *_Nullable)countryCode stateCode:(NSString *_Nullable)stateCode NS_SWIFT_NAME(setExpectedJurisdiction(countryCode:stateCode:));

/**
Starts tracking the user's location in the background with configurable tracking options.
Expand Down
10 changes: 10 additions & 0 deletions RadarSDK/Include/RadarVerifiedLocationToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
*/
@property (assign, nonatomic, readonly) bool passed;

/**
An array of failure reasons for jurisdiction and fraud detection checks.
*/
@property (nullable, copy, nonatomic, readonly) NSArray<NSString *> *failureReasons;

/**
The Radar ID of the location check.
*/
@property (nullable, copy, nonatomic, readonly) NSString *_id;

- (NSDictionary *_Nonnull)dictionaryValue;

@end
6 changes: 6 additions & 0 deletions RadarSDK/Radar.m
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ + (void)getVerifiedLocationToken:(RadarTrackVerifiedCompletionHandler)completion
getVerifiedLocationTokenWithCompletionHandler:completionHandler];
}

+ (void)setExpectedJurisdictionWithCountryCode:(NSString *)countryCode stateCode:(NSString *)stateCode {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelInfo type:RadarLogTypeSDKCall message:@"setExpectedJurisdiction()"];
[[RadarVerificationManager sharedInstance]
setExpectedJurisdictionWithCountryCode:countryCode stateCode:stateCode];
}

+ (void)startTrackingWithOptions:(RadarTrackingOptions *)options {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelInfo type:RadarLogTypeSDKCall message:@"startTracking()"];
[[RadarLocationManager sharedInstance] startTrackingWithOptions:options];
Expand Down
2 changes: 2 additions & 0 deletions RadarSDK/RadarAPIClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ typedef void (^_Nonnull RadarSyncLogsAPICompletionHandler)(RadarStatus status);
keyId:(NSString *_Nullable)keyId
attestationError:(NSString *_Nullable)attestationError
encrypted:(BOOL)encrypted
expectedCountryCode:(NSString *_Nullable)expectedCountryCode
expectedStateCode:(NSString *_Nullable)expectedStateCode
completionHandler:(RadarTrackAPICompletionHandler _Nonnull)completionHandler;

- (void)flushReplays:(NSArray<NSDictionary *> *_Nonnull)replays completionHandler:(RadarFlushReplaysAPICompletionHandler _Nonnull)completionHandler;
Expand Down
12 changes: 11 additions & 1 deletion RadarSDK/RadarAPIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ + (NSDictionary *)headersWithPublishableKey:(NSString *)publishableKey {
- (void)getConfigForUsage:(NSString *_Nullable)usage verified:(BOOL)verified completionHandler:(RadarConfigAPICompletionHandler _Nonnull)completionHandler {
NSString *publishableKey = [RadarSettings publishableKey];
if (!publishableKey) {
return;
return completionHandler(RadarStatusErrorPublishableKey, nil);
}

NSMutableString *queryString = [NSMutableString new];
Expand Down Expand Up @@ -185,6 +185,8 @@ - (void)trackWithLocation:(CLLocation *_Nonnull)location
keyId:nil
attestationError:nil
encrypted:NO
expectedCountryCode:nil
expectedStateCode:nil
completionHandler:completionHandler];
}

Expand All @@ -199,6 +201,8 @@ - (void)trackWithLocation:(CLLocation *_Nonnull)location
keyId:(NSString *_Nullable)keyId
attestationError:(NSString *_Nullable)attestationError
encrypted:(BOOL)encrypted
expectedCountryCode:(NSString * _Nullable)expectedCountryCode
expectedStateCode:(NSString * _Nullable)expectedStateCode
completionHandler:(RadarTrackAPICompletionHandler _Nonnull)completionHandler {
NSString *publishableKey = [RadarSettings publishableKey];
if (!publishableKey) {
Expand Down Expand Up @@ -324,6 +328,12 @@ - (void)trackWithLocation:(CLLocation *_Nonnull)location
if (jailbroken) {
[fraudFailureReasons addObject:@"fraud_compromised_jailbroken"];
}
if (expectedCountryCode) {
params[@"expectedCountryCode"] = expectedCountryCode;
}
if (expectedStateCode) {
params[@"expectedStateCode"] = expectedStateCode;
}
}
params[@"appId"] = [[NSBundle mainBundle] bundleIdentifier];

Expand Down
2 changes: 1 addition & 1 deletion RadarSDK/RadarUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ + (NSNumber *)timeZoneOffset {
}

+ (NSString *)sdkVersion {
return @"3.16.0";
return @"3.16.1";
}

+ (NSString *)deviceId {
Expand Down
1 change: 1 addition & 0 deletions RadarSDK/RadarVerificationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef void (^_Nullable RadarVerificationCompletionHandler)(NSString *_Nullable
- (void)startTrackingVerifiedWithInterval:(NSTimeInterval)interval beacons:(BOOL)beacons;
- (void)stopTrackingVerified;
- (void)getVerifiedLocationTokenWithCompletionHandler:(RadarTrackVerifiedCompletionHandler _Nullable)completionHandler;
- (void)setExpectedJurisdictionWithCountryCode:(NSString *)countryCode stateCode:(NSString *)stateCode;
- (void)getAttestationWithNonce:(NSString *)nonce completionHandler:(RadarVerificationCompletionHandler)completionHandler;
- (BOOL)isJailbroken;

Expand Down
14 changes: 14 additions & 0 deletions RadarSDK/RadarVerificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ @interface RadarVerificationManager ()
@property (assign, nonatomic) NSTimeInterval lastTokenSystemUptime;
@property (assign, nonatomic) BOOL lastTokenBeacons;
@property (strong, nonatomic) NSString *lastIPs;
@property (copy, nonatomic) NSString *expectedCountryCode;
@property (copy, nonatomic) NSString *expectedStateCode;

@end

Expand Down Expand Up @@ -103,6 +105,8 @@ - (void)trackVerifiedWithBeacons:(BOOL)beacons completionHandler:(RadarTrackVeri
keyId:keyId
attestationError:attestationError
encrypted:NO
expectedCountryCode:self.expectedCountryCode
expectedStateCode:self.expectedStateCode
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events,
RadarUser *_Nullable user, NSArray<RadarGeofence *> *_Nullable nearbyGeofences,
RadarConfig *_Nullable config, RadarVerifiedLocationToken *_Nullable token) {
Expand Down Expand Up @@ -194,6 +198,11 @@ - (void)startTrackingVerifiedWithInterval:(NSTimeInterval)interval beacons:(BOOL
minInterval = minInterval - 10;
}

// min interval is 10 seconds
if (minInterval < 10) {
minInterval = 10;
}

if (self.scheduled) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:@"Token request already scheduled"];

Expand Down Expand Up @@ -288,6 +297,11 @@ - (void)getVerifiedLocationTokenWithCompletionHandler:(RadarTrackVerifiedComplet
[self trackVerifiedWithBeacons:self.lastTokenBeacons completionHandler:completionHandler];
}

- (void)setExpectedJurisdictionWithCountryCode:(NSString *)countryCode stateCode:(NSString *)stateCode {
self.expectedCountryCode = countryCode;
self.expectedStateCode = stateCode;
}

- (void)getAttestationWithNonce:(NSString *)nonce completionHandler:(RadarVerificationCompletionHandler)completionHandler {
if (@available(iOS 14.0, *)) {
DCAppAttestService *service = [DCAppAttestService sharedService];
Expand Down
4 changes: 3 additions & 1 deletion RadarSDK/RadarVerifiedLocationToken+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
token:(NSString *_Nonnull)token
expiresAt:(NSDate *_Nonnull)expiresAt
expiresIn:(NSTimeInterval)expiresIn
passed:(BOOL)passed;
passed:(BOOL)passed
failureReasons:(NSArray<NSString *> *_Nonnull)failureReasons
_id:(NSString *_Nonnull)_id;
- (instancetype _Nullable)initWithObject:(id _Nonnull)object;

@end
20 changes: 18 additions & 2 deletions RadarSDK/RadarVerifiedLocationToken.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ - (instancetype _Nullable)initWithUser:(RadarUser *_Nonnull)user
token:(NSString *_Nonnull)token
expiresAt:(NSDate *_Nonnull)expiresAt
expiresIn:(NSTimeInterval)expiresIn
passed:(BOOL)passed {
passed:(BOOL)passed
failureReasons:(NSArray<NSString *> * _Nonnull)failureReasons
_id:(NSString * _Nonnull)_id {
self = [super init];
if (self) {
_user = user;
Expand All @@ -27,6 +29,8 @@ - (instancetype _Nullable)initWithUser:(RadarUser *_Nonnull)user
_expiresAt = expiresAt;
_expiresIn = expiresIn;
_passed = passed;
_failureReasons = failureReasons;
__id = _id;
}
return self;
}
Expand All @@ -44,6 +48,8 @@ - (instancetype _Nullable)initWithObject:(id _Nonnull)object {
NSDate *expiresAt;
NSTimeInterval expiresIn = 0;
BOOL passed = NO;
NSArray<NSString *> *failureReasons = @[];
NSString *_id;

id tokenObj = dict[@"token"];
if (tokenObj && [tokenObj isKindOfClass:[NSString class]]) {
Expand Down Expand Up @@ -74,8 +80,18 @@ - (instancetype _Nullable)initWithObject:(id _Nonnull)object {
events = [RadarEvent eventsFromObject:eventsObj];
}

id failureReasonsObj = dict[@"failureReasons"];
if (failureReasonsObj && [failureReasonsObj isKindOfClass:[NSArray class]]) {
failureReasons = (NSArray *)failureReasonsObj;
}

id idObj = dict[@"_id"];
if (idObj && [idObj isKindOfClass:[NSString class]]) {
_id = (NSString *)idObj;
}

if (user && events && token && expiresAt) {
return [[RadarVerifiedLocationToken alloc] initWithUser:user events:events token:token expiresAt:expiresAt expiresIn:expiresIn passed:passed];
return [[RadarVerifiedLocationToken alloc] initWithUser:user events:events token:token expiresAt:expiresAt expiresIn:expiresIn passed:passed failureReasons:failureReasons _id:_id];
}

return nil;
Expand Down

0 comments on commit 63c92df

Please sign in to comment.