Vasilis

fixes for bearer

......@@ -713,9 +713,30 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}
} failureBlock:^(NSError *error) {
if (failure) {
NSDictionary* dict = [NSDictionary alloc];
dict = [error userInfo];
NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"];
if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) {
[self refreshToken:^(NSDictionary *response) {
[self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
if (success) {
success(contextResponse);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
}];
}
NSLog(@"Error at change password %@", error );
}
}];
}
......@@ -3047,17 +3068,20 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
if (failureBlock)
failureBlock(error);
};
FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"];
NSString *accessToken = [NSString alloc];
while ([accessTokenSet next]) {
accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue];
}
_httpClient.responseSerializer = [AFJSONResponseSerializer serializer];
_httpClient.requestSerializer = [AFJSONRequestSerializer serializer];
//Set HTTP Headers
time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970];
NSString *accessToken = [NSString alloc];
if ([_db tableExists:@"requestVariables"] == YES) {
FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"];
while ([accessTokenSet next]) {
accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue];
}
[_httpClient.requestSerializer setValue:[@"Bearer " stringByAppendingString:accessToken] forHTTPHeaderField:@"Authorization"];
}
[_httpClient.requestSerializer setValue:_webId forHTTPHeaderField:@"loyalty-web-id"];
[_httpClient.requestSerializer setValue:[NSString stringWithFormat:@"%lu", timestamp] forHTTPHeaderField:@"loyalty-date"];
[_httpClient.requestSerializer setValue:[[NSString stringWithFormat:@"%@%lu", _apiKey, timestamp] SHA256Sum] forHTTPHeaderField:@"loyalty-signature"];
......@@ -3178,19 +3202,20 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
if (failureBlock)
failureBlock(error);
};
_httpClient.responseSerializer = [AFJSONResponseSerializer serializer];
_httpClient.requestSerializer = [AFJSONRequestSerializer serializer];
//Set HTTP Headers
time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970];
NSString *accessToken = [NSString alloc];
if ([_db tableExists:@"requestVariables"] == YES) {
FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"];
while ([accessTokenSet next]) {
accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue];
}
}
_httpClient.responseSerializer = [AFJSONResponseSerializer serializer];
_httpClient.requestSerializer = [AFJSONRequestSerializer serializer];
//Set HTTP Headers
time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970];
[_httpClient.requestSerializer setValue:[@"Bearer " stringByAppendingString:accessToken] forHTTPHeaderField:@"Authorization"];
}
[_httpClient.requestSerializer setValue:_webId forHTTPHeaderField:@"loyalty-web-id"];
[_httpClient.requestSerializer setValue:[NSString stringWithFormat:@"%lu", timestamp] forHTTPHeaderField:@"loyalty-date"];
[_httpClient.requestSerializer setValue:[[NSString stringWithFormat:@"%@%lu", _apiKey, timestamp] SHA256Sum] forHTTPHeaderField:@"loyalty-signature"];
......@@ -3648,7 +3673,6 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
//Set HTTP Headers
time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970];
// [_httpClient.requestSerializer setValue:[@"Bearer " stringByAppendingString:accessToken] forHTTPHeaderField:@"Authorization"];
[_httpClient.requestSerializer setValue:_webId forHTTPHeaderField:@"loyalty-web-id"];
[_httpClient.requestSerializer setValue:[NSString stringWithFormat:@"%lu", timestamp] forHTTPHeaderField:@"loyalty-date"];
[_httpClient.requestSerializer setValue:[[NSString stringWithFormat:@"%@%lu", _apiKey, timestamp] SHA256Sum] forHTTPHeaderField:@"loyalty-signature"];
......