Skip to content

Instantly share code, notes, and snippets.

@fannheyward
Created March 21, 2012 08:15
Show Gist options
  • Save fannheyward/2145564 to your computer and use it in GitHub Desktop.
Save fannheyward/2145564 to your computer and use it in GitHub Desktop.
Add OAuth Echo methods to TWRequest
#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>
@interface TWRequest (OAuthEcho)
/*
* code example:
*
* NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/account/verify_credentials.json"];
* TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:nil requestMethod:TWRequestMethodGET];
* [request setAccount:account];
* NSDictionary *headerFields = [request oauthEchoHeaderFields];
*
* // NSMutableURL
* NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:apiURL];
* [headerFields enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
* [request setValue:obj forHTTPHeaderField:key];
* }];
*
* // MKNetWorkKit
* MKNetworkEngine *engine = [[[MKNetworkEngine alloc] initWithHostName:@"example.com" customHeaderFields:headerFields];
*
* see:
* https://gist.github.com/1575035
*/
- (NSDictionary *)oauthEchoHeaderFields;
@end
#import "TWRequest+OAuthEcho.h"
@implementation TWRequest (OAuthEcho)
- (NSDictionary *)oauthEchoHeaderFields
{
NSURLRequest *signedURLRequest = [self signedURLRequest];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[dictionary setValue:[[signedURLRequest URL] absoluteString]
forKey:@"X-Auth-Service-Provider"];
[dictionary setValue:[signedURLRequest valueForHTTPHeaderField:@"Authorization"]
forKey:@"X-Verify-Credentials-Authorization"];
return [NSDictionary dictionaryWithDictionary:dictionary];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment