Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oauth #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 64 additions & 2 deletions FoundationKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
399F4CD413C905C70008CC0E /* NSObject+NKAssociatedObjects.m in Sources */ = {isa = PBXBuildFile; fileRef = 399F4CD313C905C70008CC0E /* NSObject+NKAssociatedObjects.m */; };
39EA898C13C98C6C00B6427F /* NKMath.m in Sources */ = {isa = PBXBuildFile; fileRef = 39EA898B13C98C6C00B6427F /* NKMath.m */; };
C582BF8C13C8B77C0012DF67 /* NKLog.m in Sources */ = {isa = PBXBuildFile; fileRef = C582BF8A13C8B77C0012DF67 /* NKLog.m */; };
C5AAAA7613C9A32A00E44CE7 /* NSStringAdditionsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C5AAAA7313C9A31A00E44CE7 /* NSStringAdditionsTests.m */; };
C5AAAA7913C9A33F00E44CE7 /* NSString+NKAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = C5AAAA7813C9A33F00E44CE7 /* NSString+NKAdditions.m */; };
C5AAAA7A13C9A37A00E44CE7 /* libFoundationKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DC410CFF13C39BFD00C90C19 /* libFoundationKit.a */; };
Expand All @@ -24,6 +23,15 @@
C5E31A0913C4EA7E00D9CA76 /* NSMutableDictionary+NKBlocks.m in Sources */ = {isa = PBXBuildFile; fileRef = C5E31A0113C4EA7D00D9CA76 /* NSMutableDictionary+NKBlocks.m */; };
C5EF038913C98ECE00953F2B /* NKSynthesizeSingletonTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C5EF038613C98EC100953F2B /* NKSynthesizeSingletonTests.m */; };
DC410D0313C39BFD00C90C19 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC410D0213C39BFD00C90C19 /* Foundation.framework */; };
DC5A1FD513CF8A370023CCC0 /* NKOAuthConsumer.m in Sources */ = {isa = PBXBuildFile; fileRef = DC5A1FC513CF8A370023CCC0 /* NKOAuthConsumer.m */; };
DC5A1FD613CF8A370023CCC0 /* NKOAuthDataFetcher.m in Sources */ = {isa = PBXBuildFile; fileRef = DC5A1FC713CF8A370023CCC0 /* NKOAuthDataFetcher.m */; };
DC5A1FD713CF8A370023CCC0 /* NKOAuthHMACSHA1SignatureProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = DC5A1FC913CF8A370023CCC0 /* NKOAuthHMACSHA1SignatureProvider.m */; };
DC5A1FD813CF8A370023CCC0 /* NKOAuthMutableURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = DC5A1FCB13CF8A370023CCC0 /* NKOAuthMutableURLRequest.m */; };
DC5A1FD913CF8A370023CCC0 /* NKOAuthPlaintextSignatureProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = DC5A1FCD13CF8A370023CCC0 /* NKOAuthPlaintextSignatureProvider.m */; };
DC5A1FDA13CF8A370023CCC0 /* NKOAuthRequestParameter.m in Sources */ = {isa = PBXBuildFile; fileRef = DC5A1FCF13CF8A370023CCC0 /* NKOAuthRequestParameter.m */; };
DC5A1FDB13CF8A370023CCC0 /* NKOAuthServiceTicket.m in Sources */ = {isa = PBXBuildFile; fileRef = DC5A1FD113CF8A370023CCC0 /* NKOAuthServiceTicket.m */; };
DC5A1FDC13CF8A370023CCC0 /* NKOAuthToken.m in Sources */ = {isa = PBXBuildFile; fileRef = DC5A1FD413CF8A370023CCC0 /* NKOAuthToken.m */; };
DC5A1FE013CF93F00023CCC0 /* NSData+NKBase64.m in Sources */ = {isa = PBXBuildFile; fileRef = DC5A1FDF13CF93F00023CCC0 /* NSData+NKBase64.m */; };
DCB0127213C4AE9400AB692F /* NSError+NKAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DCB0127013C4AE9400AB692F /* NSError+NKAdditions.m */; };
DCF68FBF13C74ADB0057517A /* NSObject+NKSwizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = DCF68FBD13C74ADB0057517A /* NSObject+NKSwizzle.m */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -82,6 +90,25 @@
DC1CF43013C484B800E5BEBC /* NSSet+NKConcise.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSSet+NKConcise.h"; sourceTree = "<group>"; };
DC410CFF13C39BFD00C90C19 /* libFoundationKit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libFoundationKit.a; sourceTree = BUILT_PRODUCTS_DIR; };
DC410D0213C39BFD00C90C19 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
DC5A1FC413CF8A370023CCC0 /* NKOAuthConsumer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NKOAuthConsumer.h; sourceTree = "<group>"; };
DC5A1FC513CF8A370023CCC0 /* NKOAuthConsumer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NKOAuthConsumer.m; sourceTree = "<group>"; };
DC5A1FC613CF8A370023CCC0 /* NKOAuthDataFetcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NKOAuthDataFetcher.h; sourceTree = "<group>"; };
DC5A1FC713CF8A370023CCC0 /* NKOAuthDataFetcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NKOAuthDataFetcher.m; sourceTree = "<group>"; };
DC5A1FC813CF8A370023CCC0 /* NKOAuthHMACSHA1SignatureProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NKOAuthHMACSHA1SignatureProvider.h; sourceTree = "<group>"; };
DC5A1FC913CF8A370023CCC0 /* NKOAuthHMACSHA1SignatureProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NKOAuthHMACSHA1SignatureProvider.m; sourceTree = "<group>"; };
DC5A1FCA13CF8A370023CCC0 /* NKOAuthMutableURLRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NKOAuthMutableURLRequest.h; sourceTree = "<group>"; };
DC5A1FCB13CF8A370023CCC0 /* NKOAuthMutableURLRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NKOAuthMutableURLRequest.m; sourceTree = "<group>"; };
DC5A1FCC13CF8A370023CCC0 /* NKOAuthPlaintextSignatureProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NKOAuthPlaintextSignatureProvider.h; sourceTree = "<group>"; };
DC5A1FCD13CF8A370023CCC0 /* NKOAuthPlaintextSignatureProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NKOAuthPlaintextSignatureProvider.m; sourceTree = "<group>"; };
DC5A1FCE13CF8A370023CCC0 /* NKOAuthRequestParameter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NKOAuthRequestParameter.h; sourceTree = "<group>"; };
DC5A1FCF13CF8A370023CCC0 /* NKOAuthRequestParameter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NKOAuthRequestParameter.m; sourceTree = "<group>"; };
DC5A1FD013CF8A370023CCC0 /* NKOAuthServiceTicket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NKOAuthServiceTicket.h; sourceTree = "<group>"; };
DC5A1FD113CF8A370023CCC0 /* NKOAuthServiceTicket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NKOAuthServiceTicket.m; sourceTree = "<group>"; };
DC5A1FD213CF8A370023CCC0 /* NKOAuthSignatureProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NKOAuthSignatureProvider.h; sourceTree = "<group>"; };
DC5A1FD313CF8A370023CCC0 /* NKOAuthToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NKOAuthToken.h; sourceTree = "<group>"; };
DC5A1FD413CF8A370023CCC0 /* NKOAuthToken.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NKOAuthToken.m; sourceTree = "<group>"; };
DC5A1FDE13CF93F00023CCC0 /* NSData+NKBase64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+NKBase64.h"; sourceTree = "<group>"; };
DC5A1FDF13CF93F00023CCC0 /* NSData+NKBase64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+NKBase64.m"; sourceTree = "<group>"; };
DCB0126F13C4AE9400AB692F /* NSError+NKAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+NKAdditions.h"; sourceTree = "<group>"; };
DCB0127013C4AE9400AB692F /* NSError+NKAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+NKAdditions.m"; sourceTree = "<group>"; };
DCF68FBC13C74ADB0057517A /* NSObject+NKSwizzle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+NKSwizzle.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -128,6 +155,7 @@
C5E319C913C473BD00D9CA76 /* Sources */ = {
isa = PBXGroup;
children = (
DC5A1FC213CF8A220023CCC0 /* OAuth */,
C5E319F513C4E90B00D9CA76 /* Audio */,
C5E319D713C474FE00D9CA76 /* FoundationKit.h */,
C582BF8913C8B77C0012DF67 /* NKLog.h */,
Expand All @@ -137,6 +165,8 @@
C5E319FA13C4EA7C00D9CA76 /* NSArray+NKBlocks.h */,
C5E319FB13C4EA7C00D9CA76 /* NSArray+NKBlocks.m */,
DC1CF42313C483BC00E5BEBC /* NSArray+NKConcise.h */,
DC5A1FDE13CF93F00023CCC0 /* NSData+NKBase64.h */,
DC5A1FDF13CF93F00023CCC0 /* NSData+NKBase64.m */,
C5E319D113C4744800D9CA76 /* NSData+NKCrypto.h */,
C5E319D213C4744800D9CA76 /* NSData+NKCrypto.m */,
C5E319FC13C4EA7C00D9CA76 /* NSDictionary+NKBlocks.h */,
Expand Down Expand Up @@ -213,6 +243,30 @@
name = Frameworks;
sourceTree = "<group>";
};
DC5A1FC213CF8A220023CCC0 /* OAuth */ = {
isa = PBXGroup;
children = (
DC5A1FC413CF8A370023CCC0 /* NKOAuthConsumer.h */,
DC5A1FC513CF8A370023CCC0 /* NKOAuthConsumer.m */,
DC5A1FC613CF8A370023CCC0 /* NKOAuthDataFetcher.h */,
DC5A1FC713CF8A370023CCC0 /* NKOAuthDataFetcher.m */,
DC5A1FC813CF8A370023CCC0 /* NKOAuthHMACSHA1SignatureProvider.h */,
DC5A1FC913CF8A370023CCC0 /* NKOAuthHMACSHA1SignatureProvider.m */,
DC5A1FCA13CF8A370023CCC0 /* NKOAuthMutableURLRequest.h */,
DC5A1FCB13CF8A370023CCC0 /* NKOAuthMutableURLRequest.m */,
DC5A1FCC13CF8A370023CCC0 /* NKOAuthPlaintextSignatureProvider.h */,
DC5A1FCD13CF8A370023CCC0 /* NKOAuthPlaintextSignatureProvider.m */,
DC5A1FCE13CF8A370023CCC0 /* NKOAuthRequestParameter.h */,
DC5A1FCF13CF8A370023CCC0 /* NKOAuthRequestParameter.m */,
DC5A1FD013CF8A370023CCC0 /* NKOAuthServiceTicket.h */,
DC5A1FD113CF8A370023CCC0 /* NKOAuthServiceTicket.m */,
DC5A1FD213CF8A370023CCC0 /* NKOAuthSignatureProvider.h */,
DC5A1FD313CF8A370023CCC0 /* NKOAuthToken.h */,
DC5A1FD413CF8A370023CCC0 /* NKOAuthToken.m */,
);
path = OAuth;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -323,10 +377,18 @@
C5E31A0713C4EA7E00D9CA76 /* NSMutableArray+NKBlocks.m in Sources */,
C5E31A0913C4EA7E00D9CA76 /* NSMutableDictionary+NKBlocks.m in Sources */,
DCF68FBF13C74ADB0057517A /* NSObject+NKSwizzle.m in Sources */,
C582BF8C13C8B77C0012DF67 /* NKLog.m in Sources */,
399F4CD413C905C70008CC0E /* NSObject+NKAssociatedObjects.m in Sources */,
39EA898C13C98C6C00B6427F /* NKMath.m in Sources */,
C5AAAA7913C9A33F00E44CE7 /* NSString+NKAdditions.m in Sources */,
DC5A1FD513CF8A370023CCC0 /* NKOAuthConsumer.m in Sources */,
DC5A1FD613CF8A370023CCC0 /* NKOAuthDataFetcher.m in Sources */,
DC5A1FD713CF8A370023CCC0 /* NKOAuthHMACSHA1SignatureProvider.m in Sources */,
DC5A1FD813CF8A370023CCC0 /* NKOAuthMutableURLRequest.m in Sources */,
DC5A1FD913CF8A370023CCC0 /* NKOAuthPlaintextSignatureProvider.m in Sources */,
DC5A1FDA13CF8A370023CCC0 /* NKOAuthRequestParameter.m in Sources */,
DC5A1FDB13CF8A370023CCC0 /* NKOAuthServiceTicket.m in Sources */,
DC5A1FDC13CF8A370023CCC0 /* NKOAuthToken.m in Sources */,
DC5A1FE013CF93F00023CCC0 /* NSData+NKBase64.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
13 changes: 13 additions & 0 deletions Sources/NSData+NKBase64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Part of FoundationKit http://foundationk.it
//
// Code optimized and adapted from http://www.cocoadev.com/index.pl?BaseSixtyFour

#import <Foundation/Foundation.h>


@interface NSData (NKBase64)

+ (NSData *)dataWithBase64String:(NSString *)string;
- (NSString *)base64String;

@end
122 changes: 122 additions & 0 deletions Sources/NSData+NKBase64.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#import "NSData+NKBase64.h"


static const char _encode64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

@implementation NSData (NKBase64)

+ (NSData *)dataWithBase64String:(NSString *)string {
if ([string length] <= 0) {
return [NSData data];
}

// Build decoding table
char decode64[256];
memset(decode64, CHAR_MAX, 256);
for (int i=0; i<64; i++) {
decode64[(short)_encode64[i]] = i;
}

// Get data from string and init buffer
const char *bytes = [string UTF8String];
NSUInteger numBytes = [string length];

NSUInteger dataLen = ((numBytes + 3) / 4) * 3;
NSUInteger dataOffset = 0;
char data[dataLen];

NSUInteger i = 0;

while (YES) {
char buffer[4];
short bufferOffset;

for (bufferOffset = 0; bufferOffset < 4; i++) {
short c = bytes[i];
if (c == '\0') {
break;
}

else if (isspace(c) || c == '=') {
continue;
}

buffer[bufferOffset] = decode64[c];
if (buffer[bufferOffset++] == CHAR_MAX) {
return nil;
}
}

if (bufferOffset == 0) {
break;
}
else if(bufferOffset == 1) {
return nil;
}

// Decode characters to bytes
data[dataOffset++] = (buffer[0] << 2) | (buffer[1] >> 4);
if (bufferOffset > 2) {
data[dataOffset++] = (buffer[1] << 4) | (buffer[2] >> 2);
}
if (bufferOffset > 3) {
data[dataOffset++] = (buffer[2] << 6) | buffer[3];
}
}

return [NSData dataWithBytes:data length:dataLen];
}

- (NSString *)base64String {
if ([self length] <= 0) {
return @"";
}

// Get data bytes and length
char *bytes = (char *)[self bytes];
NSUInteger numBytes = [self length];

// Output buffer
NSUInteger offset = 0;
NSUInteger outputLen = ((numBytes + 2) / 3) * 4;
char output[outputLen];

// Convert data
NSUInteger i = 0;

while (i < numBytes) {
char buffer[3] = {0};
short bufferLen = 0;

while (bufferLen < 3 && i < numBytes) {
buffer[bufferLen++] = bytes[i++];
}

// Encode bytes to characters
output[offset++] = _encode64[(buffer[0] & 0xFC) >> 2];
output[offset++] = _encode64[((buffer[0] & 0x03) << 4) | ((buffer[1] & 0xF0) >> 4)];

if (bufferLen > 1) {
output[offset++] = _encode64[((buffer[1] & 0x0F) << 2) | ((buffer[2] & 0xC0) >> 6)];
}
else {
output[offset++] = '=';
}

if (bufferLen > 2) {
output[offset++] = _encode64[buffer[2] & 0x3F];
}
else {
output[offset++] = '=';
}
}

// Generate output string
NSString *encoded = [[NSString alloc] initWithBytes:output
length:offset
encoding:NSASCIIStringEncoding];

return encoded;
}

@end
3 changes: 3 additions & 0 deletions Sources/NSString+NKAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
- (NSRange)stringRange;
- (NSString *)trimmed;

- (NSString *)URLEncodedString;
- (NSString *)URLEncodedStringEscapingAllCharacters;

@end
16 changes: 16 additions & 0 deletions Sources/NSString+NKAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,20 @@ - (NSString *)trimmed {
return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}

- (NSString *)URLEncodedString {
return CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(__bridge CFStringRef)self,
NULL,
CFSTR("?=&+"),
kCFStringEncodingUTF8));
}

- (NSString *)URLEncodedStringEscapingAllCharacters {
return CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(__bridge CFStringRef)self,
NULL,
CFSTR(":/=,!$&'()*+;[]@#?"),
kCFStringEncodingUTF8));
}

@end
16 changes: 16 additions & 0 deletions Sources/OAuth/NKOAuthConsumer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Part of FoundationKit http://foundationk.it
//
// Derived from Jon Crosby's MIT-licensed OAuthConsumer: http://oauth.googlecode.com/svn/code/obj-c/OAuthConsumer/

#import <Foundation/Foundation.h>


@interface NKOAuthConsumer : NSObject {
}
@property (copy, readwrite) NSString *key;
@property (copy, readwrite) NSString *secret;

+ (id)consumerWithKey:(NSString *)key secret:(NSString *)secret;
- (id)initWithKey:(NSString *)key secret:(NSString *)secret;

@end
21 changes: 21 additions & 0 deletions Sources/OAuth/NKOAuthConsumer.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#import "NKOAuthConsumer.h"


@implementation NKOAuthConsumer
@synthesize key = key_;
@synthesize secret = secret_;

+ (id)consumerWithKey:(NSString *)key secret:(NSString *)secret {
return [[NKOAuthConsumer alloc] initWithKey:key secret:secret];
}

- (id)initWithKey:(NSString *)key secret:(NSString *)secret {
self = [super init];
if (self) {
self.key = key;
self.secret = secret;
}
return self;
}

@end
18 changes: 18 additions & 0 deletions Sources/OAuth/NKOAuthDataFetcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Part of FoundationKit http://foundationk.it
//
// Derived from Jon Crosby's MIT-licensed OAuthConsumer: http://oauth.googlecode.com/svn/code/obj-c/OAuthConsumer/

#import <Foundation/Foundation.h>
#import "NKOAuthMutableURLRequest.h"
#import "NKOAuthServiceTicket.h"


@interface NKOAuthDataFetcher : NSObject {
}

+ (id)fetcherWithRequest:(NKOAuthMutableURLRequest *)request delegate:(id)dlg didFinishSelector:(SEL)finSlc didFailSelector:(SEL)failSlc;

- (void)fetchDataWithRequest:(NKOAuthMutableURLRequest *)request delegate:(id)dlg didFinishSelector:(SEL)finSlc didFailSelector:(SEL)failSlc;
- (void)fetchData;

@end
Loading