Generating authentication header from azure table through objective-c
Posted
by
user923370
on Stack Overflow
See other posts from Stack Overflow
or by user923370
Published on 2012-05-30T11:54:03Z
Indexed on
2012/05/30
16:40 UTC
Read the original article
Hit count: 215
I'm fetching data from iCloud and for that I need to generate a header (azure table storage).
I used the code below for that and it is generating the headers. But when I use these headers in my project it is showing "make sure that the value of authorization header is formed correctly including the signature."
I googled a lot and tried many codes but in vain.
Can anyone kindly please help me with where I'm going wrong in this code.
-(id)generat{
NSString *messageToSign = [NSString stringWithFormat:@"%@/%@/%@", dateString,AZURE_ACCOUNT_NAME, tableName];
NSString *key = @"asasasasasasasasasasasasasasasasasasasasas==";
const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding];
const char *cData = [messageToSign cStringUsingEncoding:NSUTF8StringEncoding];
unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];
CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)];
NSString *hash = [Base64 encode:HMAC];
NSLog(@"Encoded hash: %@", hash);
NSURL *url=[NSURL URLWithString: @"http://my url"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request addValue:[NSString stringWithFormat:@"SharedKeyLite %@:%@",AZURE_ACCOUNT_NAME, hash] forHTTPHeaderField:@"Authorization"];
[request addValue:dateString forHTTPHeaderField:@"x-ms-date"];
[request addValue:@"application/atom+xml, application/xml"forHTTPHeaderField:@"Accept"];
[request addValue:@"UTF-8" forHTTPHeaderField:@"Accept-Charset"];
NSLog(@"Headers: %@", [request allHTTPHeaderFields]);
NSLog(@"URL: %@", [[request URL] absoluteString]);
return request;
}
-(NSString*)rfc1123String:(NSDate *)date
{
static NSDateFormatter *df = nil;
if(df == nil)
{
df = [[NSDateFormatter alloc] init];
df.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
df.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
df.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'";
}
return [df stringFromDate:date];
}
© Stack Overflow or respective owner