Manos Chorianopoulos

add application data and fix jwt at logout

......@@ -76,6 +76,8 @@ extern NSString* VERIFY_URL;
#define WL_DEVICE_STATUS @"device_status"
#define WL_BEACON_ENABLED @"BEACON_ENABLED"
#define WL_BEACON_TIME_INTERVAL_TO_RESEND @"BEACON_TIME_INTERVAL_TO_RESEND"
#define WL_AUTHENTICATION @"AUTHENTICATION"
#define WL_IS_JWT_ENABLED @"isJWTEnabled"
///////////////////////////////////////////////////////////////////////////////
// Logging
......
......@@ -290,6 +290,9 @@ typedef void (^FailureResponse)(NSURLSessionDataTask * _Nullable task, NSError *
_pendingOperationsQueue.maxConcurrentOperationCount = 1;
_DatabaseLock = @"Database-Lock";
// Get Application Data
[self getAppSettingsWithSuccessBlock:^{} failureBlock:^(NSError *error) {}];
}
return self;
}
......@@ -1199,8 +1202,12 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
if (tableExist == YES) {
NSString *accessToken = @"";
NSString *refreshToken = @"";
NSString *clientId = @"";
NSString *clientSecret = @"";
accessToken = [_sharedService getAccessToken2];
refreshToken = [_sharedService getRefreshToken];
clientId = [_sharedService getClientId];
clientSecret = [_sharedService getClientSecret];
NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
......@@ -1208,6 +1215,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
[data setValue:accessToken forKey:@"access_token"];
[data setValue:refreshToken forKey:@"refresh_token"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL isJWTEnabled = [defaults boolForKey:WL_IS_JWT_ENABLED];
if (isJWTEnabled) {
[data setValue:accessToken forKey:@"access_token"];
[data setValue:refreshToken forKey:@"refresh_token"];
} else {
[data setValue:accessToken forKey:@"token"];
[data setValue:clientId forKey:@"client_id"];
[data setValue:clientSecret forKey:@"client_secret"];
}
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:0 error:NULL];
[self sendContextLogout:jsonData successBlock:^(NSDictionary *contextResponse) {
if (success) {
......@@ -6993,7 +7011,18 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
{
//Create REQUEST
// POST https://engage-stage.warp.ly/oauth/<app_uuid>/logout
NSMutableString *urlString = [NSMutableString stringWithFormat:@"%@/oauth/%@/logout", _baseURL, _appUUID];
// NSMutableString *urlString = [NSMutableString stringWithFormat:@"%@/oauth/%@/logout", _baseURL, _appUUID];
NSMutableString *urlString = [NSMutableString string];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL isJWTEnabled = [defaults boolForKey:WL_IS_JWT_ENABLED];
if (isJWTEnabled) {
// /user/v5/{appUuid}/logout
urlString = [NSMutableString stringWithFormat:@"%@/user/v5/%@/logout", _baseURL, _appUUID];
} else {
urlString = [NSMutableString stringWithFormat:@"%@/oauth/%@/logout", _baseURL, _appUUID];
}
WLLOG(@"[WARP Trace] HTTP URL: %@", urlString);
......@@ -8263,6 +8292,18 @@ static void distanceFunc(sqlite3_context *context, int argc, sqlite3_value **arg
NSLog(@"Beacon scanning is disabled");
}
if ([applicationVariables objectForKey:WL_AUTHENTICATION]) {
NSString *authValue = [applicationVariables objectForKey:WL_AUTHENTICATION];
if (authValue && [authValue isEqualToString:@"JWT"]) {
// AUTHENTICATION key exists and its value is "JWT"
[defaults setBool:YES forKey:WL_IS_JWT_ENABLED];
} else {
[defaults setBool:NO forKey:WL_IS_JWT_ENABLED];
}
} else {
[defaults setBool:NO forKey:WL_IS_JWT_ENABLED];
}
[defaults setObject:[NSDate date] forKey:@"lastFeaturesUpdateTimestamp"];
//Check for device status
......