Skip to content

Instantly share code, notes, and snippets.

@devstator82
Last active December 14, 2015 10:49
Show Gist options
  • Save devstator82/5074563 to your computer and use it in GitHub Desktop.
Save devstator82/5074563 to your computer and use it in GitHub Desktop.
+ (NSString*)authStringWithChannel:(Channel*)channel protocol:(NSString*)protocol
{
NSString* timestamp = [NSString stringWithFormat:@"%d", time(NULL)];
NSString* nonce = nil;
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
nonce = [[NSString alloc] initWithFormat:@"%@", string];
CFRelease(string);
CFRelease(theUUID);
NSString* consumerKey = @"www.inbox2.com";
NSString* consumerSecret = @"blah";
NSString* url = [NSString stringWithFormat:@"https://mail.google.com/mail/b/%@/%@/", channel.address, protocol];
OAConsumer* consumer = [[OAConsumer alloc] initWithKey:consumerKey secret:consumerSecret];
OAToken* token = [[OAToken alloc] initWithKey:channel.authToken secret:channel.authSecret];
OAHMAC_SHA1SignatureProvider* provider = [[OAHMAC_SHA1SignatureProvider alloc] init];
OAMutableURLRequest* request = [[OAMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]
consumer:consumer
token:token
realm:nil
signatureProvider:provider
nonce:nonce
timestamp:timestamp];
NSString* signature = [provider signClearText:[request _signatureBaseString]
withSecret:[NSString stringWithFormat:@"%@&%@", consumer.secret, token.secret]];
NSString* oauth = [NSString stringWithFormat:@"GET %@ oauth_consumer_key=\"%@\",oauth_nonce=\"%@\",oauth_signature=\"%@\",oauth_signature_method=\"%@\",oauth_timestamp=\"%@\",oauth_token=\"%@\",oauth_version=\"1.0\"",
url,
[consumer.key encodedURLParameterString],
nonce,
[signature encodedURLParameterString],
[[provider name] encodedURLParameterString],
timestamp,
[token.key encodedURLParameterString]];
NSData* data = [oauth dataUsingEncoding:NSUTF8StringEncoding];
return [data base64EncodedString2];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment