Feedback

Has anyone been able to successfully get the OAuth user token using reverse auth? My application has reverse authorization permissions, but it's hard for me to get a valid authentication token. I am using OAuthconsumer, and I'm a little confused about how to change the OAuth call for x_auth_mode extra mode.

I keep getting

Failed to validate oauth signature and token 

Any insight would be greatly appreciated, thanks in advance!

+4
source share
2 answers

Do you know sample code from Sean Cook (Developer at Twitter)? https://github.com/seancook/TWiOS5ReverseAuthExample

Its solution works in more detail than the Twitter documentation ... https://dev.twitter.com/docs/ios/using-reverse-auth

+6
source

I found an example of seancook folded to the extent that the process seems a lot more complicated than it really is. Here is a simple reverse auth entity:

 NSMutableURLRequest *rq = [TDOAuth URLRequestForPath:@"/oauth/request_token" POSTParameters:@{@"x_auth_mode": @"reverse_auth"} host:@"api.twitter.com" consumerKey:APIKey consumerSecret:APISecret accessToken:nil tokenSecret:nil]; [NSURLConnection sendAsynchronousRequest:rq queue:nil completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { id oauth = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; SLRequest *reverseAuth = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"] parameters:@{ @"x_reverse_auth_target": APIKey, @"x_reverse_auth_parameters": oauth }]; reverseAuth.account = account; [reverseAuth performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *urlResponse, NSError *error) { id creds = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; id credsDict = [NSMutableDictionary new]; for (__strong id pair in [creds componentsSeparatedByString:@"&"]) { pair = [pair componentsSeparatedByString:@"="]; credsDict[pair[0]] = pair[1]; } NSLog(@"%@", credsDict); }]; }]; 

My example uses TDOAuth , but any OAuth library will do.

0
source

Source: https://habr.com/ru/post/1387665/


All Articles