Skip to content

Commit

Permalink
Merge pull request #270 from radarlabs/track-verified-encrypted
Browse files Browse the repository at this point in the history
add trackVerifiedToken()
  • Loading branch information
nickpatrick authored Aug 22, 2023
2 parents c8e2164 + 4fd1f21 commit f9c70e4
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 9PGY6B643R;
DEVELOPMENT_TEAM = 96GHH65B9D;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
Expand Down Expand Up @@ -368,7 +368,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 9PGY6B643R;
DEVELOPMENT_TEAM = 96GHH65B9D;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
Expand Down
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.8.4'
s.version = '3.8.5'
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
4 changes: 2 additions & 2 deletions RadarSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.8.4;
MARKETING_VERSION = 3.8.5;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1024,7 +1024,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.8.4;
MARKETING_VERSION = 3.8.5;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
OTHER_CFLAGS = "-fembed-bitcode";
Expand Down
22 changes: 21 additions & 1 deletion RadarSDK/Include/Radar.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ typedef NS_ENUM(NSInteger, RadarAddressVerificationStatus) {
};


#pragma mark - Callback typedefs
#pragma mark - Callbacks

/**
Called when a location request succeeds, fails, or times out.
Expand Down Expand Up @@ -185,6 +185,15 @@ typedef void (^_Nullable RadarBeaconCompletionHandler)(RadarStatus status, NSArr
*/
typedef void (^_Nullable RadarTrackCompletionHandler)(RadarStatus status, CLLocation *_Nullable location, NSArray<RadarEvent *> *_Nullable events, RadarUser *_Nullable user);

/**
Called when an track request with token callback succeeds, fails, or times out.
Receives the request status and, if successful, a JSON Web Token (JWT) containing an array of the events generated and the user. Verify the JWT server-side using your secret key.
@see https://radar.com/documentation/sdk/fraud
*/
typedef void (^_Nullable RadarTrackTokenCompletionHandler)(RadarStatus status, NSString *_Nullable token);

/**
Called when a trip update succeeds, fails, or times out.
Expand Down Expand Up @@ -441,6 +450,17 @@ typedef void (^_Nonnull RadarLogConversionCompletionHandler)(RadarStatus status,
*/
+ (void)trackVerifiedWithCompletionHandler:(RadarTrackCompletionHandler _Nullable)completionHandler NS_SWIFT_NAME(trackVerified(completionHandler:));

/**
Tracks the user's location with device integrity information for location verification use cases. Returns a JSON Web Token (JWT). Verify the JWT server-side using your secret key.
@warning Note that you must configure SSL pinning before calling this method.
@param completionHandler An optional completion handler.
@see https://radar.com/documentation/fraud
*/
+ (void)trackVerifiedTokenWithCompletionHandler:(RadarTrackTokenCompletionHandler _Nullable)completionHandler NS_SWIFT_NAME(trackVerifiedToken(completionHandler:));

/**
Starts tracking the user's location in the background with configurable tracking options.
Expand Down
55 changes: 51 additions & 4 deletions RadarSDK/Radar.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ + (void)trackOnceWithDesiredAccuracy:(RadarTrackingOptionsDesiredAccuracy)desire
replayed:NO
beacons:beacons
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events, RadarUser *_Nullable user,
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config) {
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config, NSString *_Nullable token) {
if (status == RadarStatusSuccess) {
[[RadarLocationManager sharedInstance] replaceSyncedGeofences:nearbyGeofences];
}
Expand Down Expand Up @@ -219,7 +219,7 @@ + (void)trackOnceWithLocation:(CLLocation *)location completionHandler:(RadarTra
replayed:NO
beacons:nil
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events, RadarUser *_Nullable user,
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config) {
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config, NSString *_Nullable token) {

if (completionHandler) {
[RadarUtils runOnMainThread:^{
Expand Down Expand Up @@ -260,9 +260,10 @@ + (void)trackVerifiedWithCompletionHandler:(RadarTrackCompletionHandler)completi
attestationString:attestationString
keyId:keyId
attestationError:attestationError
encrypted:YES
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events,
RadarUser *_Nullable user, NSArray<RadarGeofence *> *_Nullable nearbyGeofences,
RadarConfig *_Nullable config) {
RadarConfig *_Nullable config, NSString *_Nullable token) {
if (completionHandler) {
[RadarUtils runOnMainThread:^{
completionHandler(status, location, events, user);
Expand All @@ -274,6 +275,52 @@ + (void)trackVerifiedWithCompletionHandler:(RadarTrackCompletionHandler)completi
}];
}

+ (void)trackVerifiedTokenWithCompletionHandler:(RadarTrackTokenCompletionHandler)completionHandler {
[[RadarAPIClient sharedInstance]
getConfigForUsage:@"verify" verified:YES
completionHandler:^(RadarStatus status, RadarConfig *_Nullable config) {
[[RadarLocationManager sharedInstance]
getLocationWithDesiredAccuracy:RadarTrackingOptionsDesiredAccuracyHigh
completionHandler:^(RadarStatus status, CLLocation *_Nullable location, BOOL stopped) {
if (status != RadarStatusSuccess) {
if (completionHandler) {
[RadarUtils runOnMainThread:^{
completionHandler(status, nil);
}];
}

return;
}

[[RadarVerificationManager sharedInstance]
getAttestationWithNonce:config.nonce
completionHandler:^(NSString *_Nullable attestationString, NSString *_Nullable keyId, NSString *_Nullable attestationError) {
[[RadarAPIClient sharedInstance]
trackWithLocation:location
stopped:RadarState.stopped
foreground:[RadarUtils foreground]
source:RadarLocationSourceForegroundLocation
replayed:NO
beacons:nil
verified:YES
attestationString:attestationString
keyId:keyId
attestationError:attestationError
encrypted:YES
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events,
RadarUser *_Nullable user, NSArray<RadarGeofence *> *_Nullable nearbyGeofences,
RadarConfig *_Nullable config, NSString *_Nullable token) {
if (completionHandler) {
[RadarUtils runOnMainThread:^{
completionHandler(status, token);
}];
}
}];
}];
}];
}];
}

+ (void)startTrackingWithOptions:(RadarTrackingOptions *)options {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelInfo type:RadarLogTypeSDKCall message:@"startTracking()"];
[[RadarLocationManager sharedInstance] startTrackingWithOptions:options];
Expand Down Expand Up @@ -345,7 +392,7 @@ + (void)mockTrackingWithOrigin:(CLLocation *)origin
replayed:NO
beacons:nil
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events, RadarUser *_Nullable user,
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config) {
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config, NSString *_Nullable token) {
if (completionHandler) {
[RadarUtils runOnMainThread:^{
completionHandler(status, location, events, user);
Expand Down
4 changes: 3 additions & 1 deletion RadarSDK/RadarAPIClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ typedef void (^_Nonnull RadarTrackAPICompletionHandler)(RadarStatus status,
NSArray<RadarEvent *> *_Nullable events,
RadarUser *_Nullable user,
NSArray<RadarGeofence *> *_Nullable nearbyGeofences,
RadarConfig *_Nullable config);
RadarConfig *_Nullable config,
NSString *_Nullable token);

typedef void (^_Nonnull RadarTripAPICompletionHandler)(RadarStatus status, RadarTrip *_Nullable trip, NSArray<RadarEvent *> *_Nullable events);

Expand Down Expand Up @@ -86,6 +87,7 @@ typedef void (^_Nonnull RadarSyncLogsAPICompletionHandler)(RadarStatus status);
attestationString:(NSString *_Nullable)attestationString
keyId:(NSString *_Nullable)keyId
attestationError:(NSString *_Nullable)attestationError
encrypted:(BOOL)encrypted
completionHandler:(RadarTrackAPICompletionHandler _Nonnull)completionHandler;

- (void)verifyEventId:(NSString *_Nonnull)eventId verification:(RadarEventVerification)verification verifiedPlaceId:(NSString *_Nullable)verifiedPlaceId;
Expand Down
22 changes: 18 additions & 4 deletions RadarSDK/RadarAPIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ - (void)trackWithLocation:(CLLocation *_Nonnull)location
attestationString:nil
keyId:nil
attestationError:nil
encrypted:NO
completionHandler:completionHandler];
}

Expand All @@ -143,10 +144,11 @@ - (void)trackWithLocation:(CLLocation *_Nonnull)location
attestationString:(NSString *_Nullable)attestationString
keyId:(NSString *_Nullable)keyId
attestationError:(NSString *_Nullable)attestationError
encrypted:(BOOL)encrypted
completionHandler:(RadarTrackAPICompletionHandler _Nonnull)completionHandler {
NSString *publishableKey = [RadarSettings publishableKey];
if (!publishableKey) {
return completionHandler(RadarStatusErrorPublishableKey, nil, nil, nil, nil, nil);
return completionHandler(RadarStatusErrorPublishableKey, nil, nil, nil, nil, nil, nil);
}
NSMutableDictionary *params = [NSMutableDictionary new];
BOOL anonymous = [RadarSettings anonymousTrackingEnabled];
Expand Down Expand Up @@ -257,6 +259,7 @@ - (void)trackWithLocation:(CLLocation *_Nonnull)location
params[@"attestationString"] = attestationString;
params[@"keyId"] = keyId;
params[@"attestationError"] = attestationError;
params[@"encrypted"] = @(encrypted);
}
params[@"appId"] = [[NSBundle mainBundle] bundleIdentifier];

Expand Down Expand Up @@ -314,7 +317,7 @@ - (void)trackWithLocation:(CLLocation *_Nonnull)location

[[RadarDelegateHolder sharedInstance] didFailWithStatus:status];

return completionHandler(status, nil, nil, nil, nil, nil);
return completionHandler(status, nil, nil, nil, nil, nil, nil);
}

[[RadarReplayBuffer sharedInstance] clearBuffer];
Expand All @@ -327,10 +330,21 @@ - (void)trackWithLocation:(CLLocation *_Nonnull)location
id eventsObj = res[@"events"];
id userObj = res[@"user"];
id nearbyGeofencesObj = res[@"nearbyGeofences"];
id tokenObj = res[@"token"];
NSArray<RadarEvent *> *events = [RadarEvent eventsFromObject:eventsObj];
RadarUser *user = [[RadarUser alloc] initWithObject:userObj];
NSArray<RadarGeofence *> *nearbyGeofences = [RadarGeofence geofencesFromObject:nearbyGeofencesObj];

if (encrypted) {
if (!tokenObj) {
return completionHandler(status, nil, nil, nil, nil, nil, nil);
}

NSString *token = (NSString *)tokenObj;

return completionHandler(status, nil, nil, nil, nil, nil, token);
}

if (user) {
BOOL inGeofences = user.geofences && user.geofences.count;
BOOL atPlace = user.place != nil;
Expand Down Expand Up @@ -394,12 +408,12 @@ - (void)trackWithLocation:(CLLocation *_Nonnull)location
[[RadarDelegateHolder sharedInstance] didReceiveEvents:events user:user];
}

return completionHandler(RadarStatusSuccess, res, events, user, nearbyGeofences, config);
return completionHandler(RadarStatusSuccess, res, events, user, nearbyGeofences, config, nil);
}

[[RadarDelegateHolder sharedInstance] didFailWithStatus:status];

completionHandler(RadarStatusErrorServer, nil, nil, nil, nil, nil);
completionHandler(RadarStatusErrorServer, nil, nil, nil, nil, nil, nil);
}];
}

Expand Down
2 changes: 1 addition & 1 deletion RadarSDK/RadarLocationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ - (void)sendLocation:(CLLocation *)location stopped:(BOOL)stopped source:(RadarL
replayed:replayed
beacons:beacons
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events, RadarUser *_Nullable user,
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config) {
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config, NSString *_Nullable token) {
self.sending = NO;

[self updateTrackingFromMeta:config.meta];
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.8.4";
return @"3.8.5";
}

+ (NSString *)deviceId {
Expand Down

0 comments on commit f9c70e4

Please sign in to comment.