views:

158

answers:

2

Hi All

I'm using OAuth/xAuth in an iPhone twitter app, and having a problem with passwords that contain special characters. For example "password&". First off, I am converting the & into %26 by doing:

NSString *encodedPassword = (NSString *)CFURLCreateStringByAddingPercentEscapes(
                                                                                 NULL,
                                                                                 (CFStringRef)thePassword,
                                                                                 NULL,
                                                                                 (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                                                 kCFStringEncodingUTF8 );

This encodes it fine into "password%26". I am then setting it up as a parameter of an OAMutableURLRequest:

    [request setParameters:[NSArray arrayWithObjects:
                        [OARequestParameter requestParameterWithName:@"x_auth_mode" value:@"client_auth"],
                        [OARequestParameter requestParameterWithName:@"x_auth_username" value:encodedUsername],
                        [OARequestParameter requestParameterWithName:@"x_auth_password" value:encodedPassword],
                        nil]];

Upon sending the request using an OADataFetcher, I receive an NSUrlError:

Error Domain=NSURLErrorDomain Code=-1012 UserInfo=0x4823e00 "Operation could not be completed. (NSURLErrorDomain error -1012.)"

What am I doing wrong here? If I leave the & in the password it crashes my code (the setParamaters array flunks out). Has anyone come across this before using OAuth?

If I have a alphanumeric password everything works fine... Thanks for any guidance!

A: 

OAuthRequestParameter already encodes the name and value; it may be that the & in particular is causing problems. Have you tried using different non-standard characters? It might required modifying the OAuth library itself.

Ben Gottlieb
A: 

I am having the same issue, password has a + sign and just does not work. Tried encoding still does not work. Did you figure it out by any chance? Appreciate if you help out. Thank you.