Log in or register to post comments

AuthenticationFailure in Vuforia Web Services

February 9, 2017 - 5:56am #1

Hi All,

This is my first post in Vuforia Support forum.

I am using Vuforia Web Api for upload/Add Target on Cloud Database in iOS. But i am getting "AuthenticationFailure" error in response. I am using NSMutableURLRequest for making call to server and following is the complete Request that i am sending. I double check the documentation guidelines with my code and everything is according to instructions but still getting error. Please take a look into it and help me to resolve it and i am stuck on it from couple of days.

- (IBAction)postBtnTapped:(id)sender {

    NSString *ServerAccessKey = @"9a30562d9d09d0d1ffc8a42e5394393e95cbbf1f";

    NSString *ServerSecretKey = @"003009a1a1c1e04ce51a5085339611aca5852596";


    UIImage *image = [UIImage imageNamed:@"stones.jpg"];

    NSData *imageData = UIImagePNGRepresentation(image);

    NSString *imageDataString = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];


    NSMutableDictionary *params = [[NSMutableDictionary alloc]init];

    [params setObject:@"Stone-Cloud-Target" forKey:@"name"];

    [params setObject:[NSNumber numberWithFloat:image.size.width] forKey:@"width"];

    [params setObject:imageDataString forKey:@"image"];

    [params setObject:[NSNumber numberWithBool:true] forKey:@"active_flag"];   


    NSError *error;

    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params

                                                       options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string



    NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://vws.vuforia.com/targets"]];

    [urlRequest setHTTPMethod:@"POST"];

    [urlRequest setHTTPBody:jsonData];

    NSDate *currDate = [NSDate date];

    NSString *dateStr = [self getUTCFormateDate:currDate];

    NSString *contentmd5 = [self MD5:urlRequest.HTTPBody];


    NSString *StringToSign =[NSString stringWithFormat:@"%@\n%@\n%@\n%@\n%@",urlRequest.HTTPMethod,contentmd5,@"application/json",dateStr,urlRequest.URL];



   NSString *hmacStr = [self hmacsha1:StringToSign key:ServerSecretKey];

    NSString *authStr = [NSString stringWithFormat:@"VWS %@:%@",ServerAccessKey,hmacStr];


    [urlRequest setValue: dateStr forHTTPHeaderField:@"Date"];

    [urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

    [urlRequest setValue:authStr forHTTPHeaderField:@"Authorization"];


    NSURLConnection * myConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self startImmediately:YES];



- (NSString*)MD5:(NSData *) data


    // Create byte array of unsigned chars

    unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];


    // Create 16 byte MD5 hash value, store in buffer

    CC_MD5([data bytes], (CC_LONG)data.length, md5Buffer);


    // Convert unsigned char buffer to NSString of hex values

    NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];

    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)

        [output appendFormat:@"%02x",md5Buffer[i]];


    return output;


-(NSString *)getUTCFormateDate:(NSDate *)localDate



    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];


    NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"GMT"];


    [dateFormatter setTimeZone:timeZone];


    [dateFormatter setDateFormat:@"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'"];


    NSString *dateString = [dateFormatter stringFromDate:localDate];


    return dateString;


- (NSString *)hmacsha1:(NSString *)text key:(NSString *)secrets {


    NSData *secretData = [secrets dataUsingEncoding:NSUTF8StringEncoding];

    NSData *clearTextData = [text dataUsingEncoding:NSUTF8StringEncoding];

    unsigned char result[20];

    CCHmac(kCCHmacAlgSHA1, [secretData bytes], [secretData length], [clearTextData bytes], [clearTextData length], result);


    char base64Result[32];

    size_t theResultLength = 32;

    Base64EncodeData(result, 20, base64Result, &theResultLength);

    NSData *theData = [NSData dataWithBytes:base64Result length:theResultLength];

    NSString *base64EncodedResult = [[NSString alloc] initWithData:theData encoding:NSASCIIStringEncoding];

    return base64EncodedResult;



There is a separate question when i hit this URL "https://developer.vuforia.com/targetmanager/vuforiaUtil/getLoggedInUser". Its response is attached in screen short. Why CloudRecoStatus = "USER_NOT_AUTHORISED" ?

Please help me on this.


Image icon Vuforia.png254.41 KB
Log in or register to post comments