microsoft-dpe/wa-toolkit-ios — pull request #29 by darden88 (2011-10-31 05:52:49+00:00)
Title: Updates for Table query request creation

Updates for WAAuthenticationCredential -authenticatedRequestWithURL to correct auth

I investigated the issues for my table authentication issues with Storage Analytics and I found two issues.

The first issue is that the x-ms-version header wasn't being set for table requests, only for queue and blob requests in the above selector. The MSDN page http://msdn.microsoft.com/en-us/library/hh452238.aspx says that x-ms-version is required for all authenticated requests for Storage Analytics.

Next, and the bigger issue, was that the canonacalized resource addressing scheme was off for table queries, like that of Storage Analytics, which use the comp=something query parameter.

In your code, if there was a comp=something query parameter, it would get added to the string which would get signed in the format of /accountname/\tcomp:something. I may have the exact sequence wrong, but the code fragment is this one:

if([arg hasPrefix:@"comp="])
{
arg = [arg stringByReplacingOccurrencesOfString:@"=" withString:@":"];
query = [@"\n" stringByAppendingString:arg];
break;
}

from line 336 in WAAuthenticationCredential.m

The problem is that this is the incorrect format. The format that Azure is expecting is something like this:
/myaccountname/?comp=properties.

This was the primary cause of the auth errors I was receiving. I verified this by going through the AzureStorageClient code in Reflector. If you have the source to the AzureStorageClient or have reflector, you can see how it's created in Microsoft.WindowsAzure.StorageClient.Protocol.CanonicalizationStrategy.GetCanonicalizedResource(Uri, String): String.

They clearly add a question mark in front of comp, don't add tabs, and don't change the equals sign to a colon.

I've checked in these basic changes. I haven't done any testing against non-Storage Analytics queries, but I don't think these changes have any impact. My guess is that table querying for resources with comp querystrings was broken before, but it wasn't noticed.

I also have some basic helper methods for storageAnalytics called fetchStorageAnalytics and setStorageAnalytics if you'd like me to check them in as well. One thing I should point out is that I'm returning data from fetchStorageAnaytics as an NSString rather than that xml file, because I have to parse it in my own code, and I hate iOS's xml handling so I use a different lib that takes an NSString. I ended up writing a fetchStringWithCompletionHandler method similar to fetchXmlWithCompletionHandler and this would have to be checked in as well. You might find that inconsistent with the rest of the app, but that's my basic reasoning for my implementation. Your nice helper methods for dealing with iOS xml are all private :)

Chris Williams