Skip to content

Commit 93533dd

Browse files
committed
Merge branch 'release/1.2.0'
Conflicts: OAuth2Client.xcodeproj/project.pbxproj
2 parents 5b4a4c3 + fee570e commit 93533dd

13 files changed

+265
-39
lines changed

NXOAuth2Client.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Pod::Spec.new do |s|
22
s.name = 'NXOAuth2Client'
3-
s.version = '1.1.0'
3+
s.version = '1.2.0'
44
s.license = 'BSD'
55
s.summary = 'Client library for OAuth2 (currently built against draft 10 of the OAuth2 spec)'
66
s.homepage = 'https://github.com/nxtbgthng/OAuth2Client'
77
s.author = { 'nxtbgthng' => '[email protected]'}
8-
s.source = { :git => 'https://github.com/nxtbgthng/OAuth2Client.git', :tag => 'v1.1.0' }
8+
s.source = { :git => 'https://github.com/nxtbgthng/OAuth2Client.git', :tag => 'v1.2.0' }
99
s.source_files = 'NXOAuth2Account+Private.h', 'Sources/', 'Sources/OAuth2Client/'
1010
s.frameworks = 'Security'
1111
s.requires_arc = true

OAuth2Client.framework-Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<key>CFBundlePackageType</key>
1414
<string>FMWK</string>
1515
<key>CFBundleShortVersionString</key>
16-
<string>1.1.0</string>
16+
<string>1.2.0</string>
1717
<key>CFBundleSignature</key>
1818
<string>????</string>
1919
<key>CFBundleVersion</key>

OAuth2Client.xcodeproj/project.pbxproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
0867D690FE84028FC02AAC07 /* Project object */ = {
363363
isa = PBXProject;
364364
attributes = {
365-
LastUpgradeCheck = 0440;
365+
LastUpgradeCheck = 0450;
366366
ORGANIZATIONNAME = nxtbgthng;
367367
};
368368
buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "OAuth2Client" */;
@@ -445,7 +445,7 @@
445445
buildSettings = {
446446
ALWAYS_SEARCH_USER_PATHS = NO;
447447
ARCHS = (
448-
armv7,
448+
"$(inherited)",
449449
armv6,
450450
);
451451
CLANG_ENABLE_OBJC_ARC = YES;
@@ -472,7 +472,7 @@
472472
buildSettings = {
473473
ALWAYS_SEARCH_USER_PATHS = NO;
474474
ARCHS = (
475-
armv7,
475+
"$(inherited)",
476476
armv6,
477477
);
478478
CLANG_ENABLE_OBJC_ARC = YES;
@@ -495,10 +495,12 @@
495495
isa = XCBuildConfiguration;
496496
buildSettings = {
497497
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
498+
COMBINE_HIDPI_IMAGES = YES;
498499
GCC_C_LANGUAGE_STANDARD = c99;
499500
GCC_OPTIMIZATION_LEVEL = 0;
500501
GCC_WARN_ABOUT_RETURN_TYPE = YES;
501502
GCC_WARN_UNUSED_VARIABLE = YES;
503+
MACOSX_DEPLOYMENT_TARGET = 10.7;
502504
OTHER_LDFLAGS = "-ObjC";
503505
};
504506
name = Debug;
@@ -507,9 +509,11 @@
507509
isa = XCBuildConfiguration;
508510
buildSettings = {
509511
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
512+
COMBINE_HIDPI_IMAGES = YES;
510513
GCC_C_LANGUAGE_STANDARD = c99;
511514
GCC_WARN_ABOUT_RETURN_TYPE = YES;
512515
GCC_WARN_UNUSED_VARIABLE = YES;
516+
MACOSX_DEPLOYMENT_TARGET = 10.7;
513517
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
514518
OTHER_LDFLAGS = "-ObjC";
515519
};

Sources/NSString+NXOAuth2.m

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ @implementation NSString (NXOAuth2)
1818

1919
+ (NSString *)nxoauth2_stringWithUUID;
2020
{
21-
__autoreleasing NSString *result;
2221
CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
23-
result = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, theUUID);
22+
NSString *result = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, theUUID);
2423
CFRelease(theUUID);
2524
return result;
2625
}
@@ -59,24 +58,19 @@ - (NSDictionary *)nxoauth2_parametersFromEncodedQueryString;
5958

6059
- (NSString *)nxoauth2_URLEncodedString;
6160
{
62-
63-
CFStringRef cfResult = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, //Allocator
64-
(__bridge CFStringRef)self, //Original String
65-
NULL, //Characters to leave unescaped
66-
(CFStringRef)@"!*'();:@&=+$,/?%#[]", //Legal Characters to be escaped
67-
kCFStringEncodingUTF8); //Encoding
68-
__autoreleasing NSString *result = (__bridge_transfer NSString *)cfResult;
69-
return result;
61+
return (__bridge_transfer NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, //Allocator
62+
(__bridge CFStringRef)self, //Original String
63+
NULL, //Characters to leave unescaped
64+
CFSTR("!*'();:@&=+$,/?%#[]"), //Legal Characters to be escaped
65+
kCFStringEncodingUTF8); //Encoding
7066
}
7167

7268
- (NSString *)nxoauth2_URLDecodedString;
7369
{
74-
CFStringRef cfResult = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,
75-
(__bridge CFStringRef)self,
76-
CFSTR(""),
77-
kCFStringEncodingUTF8);
78-
__autoreleasing NSString *result = (__bridge_transfer NSString *)cfResult;
79-
return result;
70+
return (__bridge_transfer NSString *) CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,
71+
(__bridge CFStringRef)self,
72+
CFSTR(""),
73+
kCFStringEncodingUTF8);
8074
}
8175

8276
@end

Sources/OAuth2Client/NXOAuth2AccessToken.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,30 @@
1919
@private
2020
NSString *accessToken;
2121
NSString *refreshToken;
22+
NSString *tokenType;
2223
NSDate *expiresAt;
2324
NSSet *scope;
2425
NSString *responseBody;
2526
}
2627
@property (nonatomic, readonly) NSString *accessToken;
2728
@property (nonatomic, readonly) NSString *refreshToken;
29+
@property (nonatomic, readonly) NSString *tokenType;
2830
@property (nonatomic, readonly) NSDate *expiresAt;
2931
@property (nonatomic, readonly) BOOL doesExpire;
3032
@property (nonatomic, readonly) BOOL hasExpired;
3133
@property (nonatomic, readonly) NSSet *scope;
3234
@property (nonatomic, readonly) NSString *responseBody;
3335

3436
+ (id)tokenWithResponseBody:(NSString *)responseBody;
37+
+ (id)tokenWithResponseBody:(NSString *)responseBody tokenType:(NSString *)tokenType;
3538

3639
- (id)initWithAccessToken:(NSString *)accessToken;
3740
- (id)initWithAccessToken:(NSString *)accessToken refreshToken:(NSString *)refreshToken expiresAt:(NSDate *)expiryDate;
3841
- (id)initWithAccessToken:(NSString *)accessToken refreshToken:(NSString *)refreshToken expiresAt:(NSDate *)expiryDate scope:(NSSet *)scope;
39-
- (id)initWithAccessToken:(NSString *)accessToken refreshToken:(NSString *)refreshToken expiresAt:(NSDate *)expiryDate scope:(NSSet *)scope responseBody:(NSString *)responseBody; // designated
42+
- (id)initWithAccessToken:(NSString *)accessToken refreshToken:(NSString *)refreshToken expiresAt:(NSDate *)expiryDate scope:(NSSet *)scope responseBody:(NSString *)responseBody;
43+
- (id)initWithAccessToken:(NSString *)accessToken refreshToken:(NSString *)refreshToken expiresAt:(NSDate *)expiryDate scope:(NSSet *)scope responseBody:(NSString *)responseBody tokenType:(NSString*)tokenType; // designated
4044

45+
- (void)restoreWithOldToken:(NXOAuth2AccessToken *)oldToken;
4146

4247
#pragma mark Keychain Support
4348

Sources/OAuth2Client/NXOAuth2AccessToken.m

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ @implementation NXOAuth2AccessToken
2121
#pragma mark Lifecycle
2222

2323
+ (id)tokenWithResponseBody:(NSString *)theResponseBody;
24+
{
25+
return [self tokenWithResponseBody:theResponseBody tokenType:nil];
26+
}
27+
28+
+ (id)tokenWithResponseBody:(NSString *)theResponseBody tokenType:(NSString *)tokenType;
2429
{
2530
NSDictionary *jsonDict = nil;
2631
Class jsonSerializationClass = NSClassFromString(@"NSJSONSerialization");
@@ -51,6 +56,11 @@ + (id)tokenWithResponseBody:(NSString *)theResponseBody;
5156
NSString *aRefreshToken = [jsonDict objectForKey:@"refresh_token"];
5257
NSString *scopeString = [jsonDict objectForKey:@"scope"];
5358

59+
// if the response overrides token_type we take it from the response
60+
if ([jsonDict objectForKey:@"token_type"]) {
61+
tokenType = [jsonDict objectForKey:@"token_type"];
62+
}
63+
5464
NSSet *scope = nil;
5565
if (scopeString) {
5666
scope = [NSSet setWithArray:[scopeString componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
@@ -61,10 +71,11 @@ + (id)tokenWithResponseBody:(NSString *)theResponseBody;
6171
expiryDate = [NSDate dateWithTimeIntervalSinceNow:[expiresIn integerValue]];
6272
}
6373
return [[[self class] alloc] initWithAccessToken:anAccessToken
64-
refreshToken:aRefreshToken
65-
expiresAt:expiryDate
66-
scope:scope
67-
responseBody:theResponseBody];
74+
refreshToken:aRefreshToken
75+
expiresAt:expiryDate
76+
scope:scope
77+
responseBody:theResponseBody
78+
tokenType:tokenType];
6879
}
6980

7081
- (id)initWithAccessToken:(NSString *)anAccessToken;
@@ -90,6 +101,16 @@ - (id)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRe
90101
}
91102

92103
- (id)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRefreshToken expiresAt:(NSDate *)anExpiryDate scope:(NSSet *)aScope responseBody:(NSString *)aResponseBody;
104+
{
105+
return [[[self class] alloc] initWithAccessToken:anAccessToken
106+
refreshToken:aRefreshToken
107+
expiresAt:anExpiryDate
108+
scope:aScope
109+
responseBody:aResponseBody
110+
tokenType:nil];
111+
}
112+
113+
- (id)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRefreshToken expiresAt:(NSDate *)anExpiryDate scope:(NSSet *)aScope responseBody:(NSString *)aResponseBody tokenType:(NSString *)aTokenType
93114
{
94115
// a token object without an actual token is not what we want!
95116
NSAssert1(anAccessToken, @"No token from token response: %@", aResponseBody);
@@ -104,10 +125,17 @@ - (id)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRe
104125
expiresAt = [anExpiryDate copy];
105126
scope = aScope ? [aScope copy] : [[NSSet alloc] init];
106127
responseBody = [aResponseBody copy];
128+
tokenType = [aTokenType copy];
107129
}
108130
return self;
109131
}
110132

133+
- (void)restoreWithOldToken:(NXOAuth2AccessToken *)oldToken;
134+
{
135+
if (self.refreshToken == nil) {
136+
refreshToken = oldToken.refreshToken;
137+
}
138+
}
111139

112140

113141
#pragma mark Accessors
@@ -117,6 +145,21 @@ - (id)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRe
117145
@synthesize expiresAt;
118146
@synthesize scope;
119147
@synthesize responseBody;
148+
@synthesize tokenType;
149+
150+
- (NSString*)tokenType
151+
{
152+
if (tokenType == nil || [tokenType isEqualToString:@""]) {
153+
//fall back on OAuth if token type not set
154+
return @"OAuth";
155+
} else if ([tokenType isEqualToString:@"bearer"]) {
156+
//this is for out case sensitive server
157+
//oauth server should be case insensitive so this should make no difference
158+
return @"Bearer";
159+
} else {
160+
return tokenType;
161+
}
162+
}
120163

121164
- (BOOL)doesExpire;
122165
{
@@ -128,10 +171,9 @@ - (BOOL)hasExpired;
128171
return ([[NSDate date] earlierDate:expiresAt] == expiresAt);
129172
}
130173

131-
132174
- (NSString *)description;
133175
{
134-
return [NSString stringWithFormat:@"<NXOAuth2Token token:%@ refreshToken:%@ expiresAt:%@>", self.accessToken, self.refreshToken, self.expiresAt];
176+
return [NSString stringWithFormat:@"<NXOAuth2Token token:%@ refreshToken:%@ expiresAt:%@ tokenType: %@>", self.accessToken, self.refreshToken, self.expiresAt, self.tokenType];
135177
}
136178

137179

@@ -144,6 +186,9 @@ - (void)encodeWithCoder:(NSCoder *)aCoder
144186
[aCoder encodeObject:expiresAt forKey:@"expiresAt"];
145187
[aCoder encodeObject:scope forKey:@"scope"];
146188
[aCoder encodeObject:responseBody forKey:@"responseBody"];
189+
if (tokenType) {
190+
[aCoder encodeObject:tokenType forKey:@"tokenType"];
191+
}
147192
}
148193

149194
- (id)initWithCoder:(NSCoder *)aDecoder
@@ -162,6 +207,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder
162207
expiresAt = [[aDecoder decodeObjectForKey:@"expiresAt"] copy];
163208
scope = [[aDecoder decodeObjectForKey:@"scope"] copy];
164209
responseBody = [[aDecoder decodeObjectForKey:@"responseBody"] copy];
210+
tokenType = [[aDecoder decodeObjectForKey:@"tokenType"] copy];
165211
}
166212
return self;
167213
}

Sources/OAuth2Client/NXOAuth2Account.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,14 @@ - (NXOAuth2Client *)oauthClient;
8080
NSString *clientSecret = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationSecret];
8181
NSURL *authorizeURL = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationAuthorizeURL];
8282
NSURL *tokenURL = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenURL];
83+
NSString *tokenType = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenType];
8384

8485
oauthClient = [[NXOAuth2Client alloc] initWithClientID:clientID
8586
clientSecret:clientSecret
8687
authorizeURL:authorizeURL
8788
tokenURL:tokenURL
8889
accessToken:self.accessToken
90+
tokenType:tokenType
8991
persistent:NO
9092
delegate:self];
9193
}

Sources/OAuth2Client/NXOAuth2AccountStore.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ extern NSString * const kNXOAuth2AccountStoreConfigurationSecret;
3232
extern NSString * const kNXOAuth2AccountStoreConfigurationAuthorizeURL;
3333
extern NSString * const kNXOAuth2AccountStoreConfigurationTokenURL;
3434
extern NSString * const kNXOAuth2AccountStoreConfigurationRedirectURL;
35+
extern NSString * const kNXOAuth2AccountStoreConfigurationScope;
36+
extern NSString * const kNXOAuth2AccountStoreConfigurationTokenType;
3537

3638

3739
#pragma mark Account Type
@@ -75,6 +77,23 @@ typedef void(^NXOAuth2PreparedAuthorizationURLHandler)(NSURL *preparedURL);
7577
redirectURL:(NSURL *)aRedirectURL
7678
forAccountType:(NSString *)anAccountType;
7779

80+
- (void)setClientID:(NSString *)aClientID
81+
secret:(NSString *)aSecret
82+
scope:(NSSet *)theScope
83+
authorizationURL:(NSURL *)anAuthorizationURL
84+
tokenURL:(NSURL *)aTokenURL
85+
redirectURL:(NSURL *)aRedirectURL
86+
forAccountType:(NSString *)anAccountType;
87+
88+
- (void)setClientID:(NSString *)aClientID
89+
secret:(NSString *)aSecret
90+
scope:(NSSet *)theScope
91+
authorizationURL:(NSURL *)anAuthorizationURL
92+
tokenURL:(NSURL *)aTokenURL
93+
redirectURL:(NSURL *)aRedirectURL
94+
tokenType:(NSString *)aTokenType
95+
forAccountType:(NSString *)anAccountType;
96+
7897
- (void)setConfiguration:(NSDictionary *)configuration forAccountType:(NSString *)accountType;
7998

8099
- (NSDictionary *)configurationForAccountType:(NSString *)accountType;
@@ -94,6 +113,7 @@ typedef void(^NXOAuth2PreparedAuthorizationURLHandler)(NSURL *preparedURL);
94113
- (void)requestAccessToAccountWithType:(NSString *)accountType;
95114
- (void)requestAccessToAccountWithType:(NSString *)accountType withPreparedAuthorizationURLHandler:(NXOAuth2PreparedAuthorizationURLHandler)aPreparedAuthorizationURLHandler;
96115
- (void)requestAccessToAccountWithType:(NSString *)accountType username:(NSString *)username password:(NSString *)password;
116+
- (void)requestAccessToAccountWithType:(NSString *)accountType assertionType:(NSURL *)assertionType assertion:(NSString *)assertion;
97117
- (void)removeAccount:(NXOAuth2Account *)account;
98118

99119

0 commit comments

Comments
 (0)