rsieiro / RSOAuthEngine

ARC based OAuth engine for MKNetworkKit
http://rodrigo.sharpcube.com
150 stars 33 forks source link

Incorrect signature base string when parameters contains reserved characters #10

Closed sycx closed 12 years ago

sycx commented 12 years ago

All parameters has been Pre-encoded by MKNetworkKit. Need to be decoded before using.

tuo commented 11 years ago

@sycx has a problem. If query parameter contains ampersand (i.e. tv&movie) , then based on @sycx 's solution, it would try decode it first and separate by ampersand, which would cause very strange problem.

As all parameters are encoded from MKNetworkKit, what you can do is just use encode one like following commit:

fee14965ce507675bcb7842fdee5a8e5c2b3c80b

// Only include GET and POST fields if there are no files or data to be posted
if ([request.filesToBePosted count] == 0 && [request.dataToBePosted count] == 0) {
    // Add parameters from the query string
    NSArray *pairs = [url.query componentsSeparatedByString:@"&"];
    [pairs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        NSArray *elements = [obj componentsSeparatedByString:@"="];
        NSString *key = [elements objectAtIndex:0];
        NSString *value = (elements.count > 1) ? [elements objectAtIndex:1] : @"";

        [parameters addObject:[NSDictionary dictionaryWithObjectsAndKeys:key, @"key", value, @"value", nil]];
    }];
rsieiro commented 11 years ago

@tuo you're right. Could you please issue a pull request with that commit, so I can merge it in the code?

Thanks :)