bdbergeron / BDBOAuth1Manager

OAuth 1.0a library for AFNetworking 2.x
MIT License
100 stars 35 forks source link

Replace percent-escaped slashes (%2F) with actual slashes (/) #37

Closed kolpanic closed 9 years ago

kolpanic commented 9 years ago

Work-around for AFNetworking change that breaks Twitter Oauth.

For issue #36.

kolpanic commented 9 years ago

Textual replacement was the only approach I could find for this.

I couldn't find a NSString method that would un-escape just a particular kind of character (i.e. slashes); the only method available would un-escape everything.

bdbergeron commented 9 years ago

Taken care of, in addition to encoding the ? character, with f4288a8. Thanks as always, @kolpanic.

obuseme commented 9 years ago

Has anyone actually tested this? It isn't working for me. Using AFNetworking 2.6.1 and BDBOAuth1Manager 1.6.0, if I provide / in the query, I get a HTTP 401 from the server. I tracked this down because the signature, as generated by this pull request, is generated from a hashed value where slashes (and question marks) are encoded, where since AFNetworking does not encode them in the HTTP body itself, when the server gets the body and attempts to compare the provided signature from the client with one it generates are different, thus 401.

obuseme commented 9 years ago

I was able to fix this behavior by adding the following to - (NSMutableURLRequest *)requestWithMethod:(NSString *)method URLString:(NSString *)URLString parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing *)error in BDBOAuth1RequestSerializer

request.HTTPBody = [[[[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding] bdb_URLEncodeSlashesAndQuestionMarks] dataUsingEncoding:NSUTF8StringEncoding];

I've only really tested that in a couple limited use cases. How's it look? Am I missing anything? Can it be improved?