From 9034e63fe6fa837df1bed1ea07b445f9e85fd93b Mon Sep 17 00:00:00 2001 From: andresmoreno Date: Tue, 7 Oct 2014 23:03:01 +0200 Subject: [PATCH 1/7] Supporting download progress --- Sources/OAuth2Client/NXOAuth2Request.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sources/OAuth2Client/NXOAuth2Request.m b/Sources/OAuth2Client/NXOAuth2Request.m index e44589fd..1f24007b 100644 --- a/Sources/OAuth2Client/NXOAuth2Request.m +++ b/Sources/OAuth2Client/NXOAuth2Request.m @@ -25,6 +25,7 @@ @interface NXOAuth2Request () @property (nonatomic, strong, readwrite) NXOAuth2Connection *connection; @property (nonatomic, strong, readwrite) NXOAuth2Request *me; +@property (nonatomic, copy) NXOAuth2ConnectionSendingProgressHandler progressHandler; #pragma mark Apply Parameters - (void)applyParameters:(NSDictionary *)someParameters onRequest:(NSMutableURLRequest *)aRequest; @end @@ -111,6 +112,7 @@ - (void)performRequestWithSendingProgressHandler:(NXOAuth2ConnectionSendingProgr sendingProgressHandler:progressHandler responseHandler:responseHandler]; self.connection.delegate = self; + self.progressHandler = progressHandler; // Keep request object alive during the request is performing. self.me = self; @@ -149,6 +151,13 @@ - (void)oauthConnection:(NXOAuth2Connection *)connection didFailWithError:(NSErr self.me = nil; } +-(void)oauthConnection:(NXOAuth2Connection *)connectionStbl didReceiveData:(NSData *)data +{ + if (self.progressHandler) + { + self.progressHandler(self.connection.data.length, connectionStbl.expectedContentLength); + } +} #pragma mark Apply Parameters From 4631925c243bb988f44322b50eb8027f3c7d962e Mon Sep 17 00:00:00 2001 From: Robert Theis Date: Wed, 8 Oct 2014 17:58:48 -0700 Subject: [PATCH 2/7] Fix spelling in README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2f63867e..77afd698 100755 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ If an account was added the `userInfo` dictionary of the notification will conta #### On Failure -If the authentication did not succeed, a notification of type `NXOAuth2AccountStoreDidFailToRequestAccessNotification` containing an `NSError` will be send. +If the authentication did not succeed, a notification of type `NXOAuth2AccountStoreDidFailToRequestAccessNotification` containing an `NSError` will be sent.
 [[NSNotificationCenter defaultCenter] addObserverForName:NXOAuth2AccountStoreDidFailToRequestAccessNotification
                                                   object:[NXOAuth2AccountStore sharedStore]
@@ -157,7 +157,7 @@ NSDictionary *userData = // ...
 account.userData = userData;
 
-This payload will be stored together with the accounts in the Keychain. Thus it shouldn't be to big. +This payload will be stored together with the accounts in the Keychain. Thus it shouldn't be too big. ### Invoking a Request @@ -175,7 +175,7 @@ A request using the authentication for a service can be invoked via `NXOAuth2Req #### Getting a signed NSURLRequest -In some circumstances you have to go the *good old way* and use an `NSURLConnection`. Maybe if you to download a large file. Therefore `NXOAuth2Request` gives you the possibility to get an `NSURLRequest` containing the additional information to authenticate that request. +In some circumstances you have to go the *good old way* and use an `NSURLConnection`. Maybe if you want to download a large file. Therefore `NXOAuth2Request` gives you the possibility to get an `NSURLRequest` containing the additional information to authenticate that request.
 NXOAuth2Request *theRequest = [[NXOAuth2Request alloc] initWithResource:[NSURL URLWithString:@"https://...your service URL..."]

From cf4d87f891172ab8f70bf625e2e61aedccf593ce Mon Sep 17 00:00:00 2001
From: Carola Nitz 
Date: Mon, 3 Nov 2014 13:24:53 +0100
Subject: [PATCH 3/7] replaced id by instancetype and adjusted indentation

---
 NXOAuth2Account+Private.h                     |  7 ++-
 Sources/OAuth2Client/NXOAuth2AccessToken.h    | 36 ++++++++++----
 Sources/OAuth2Client/NXOAuth2AccessToken.m    | 20 ++++----
 Sources/OAuth2Client/NXOAuth2Account.m        |  6 +--
 Sources/OAuth2Client/NXOAuth2AccountStore.h   |  2 +-
 Sources/OAuth2Client/NXOAuth2AccountStore.m   |  4 +-
 Sources/OAuth2Client/NXOAuth2Client.h         | 48 +++++++++----------
 Sources/OAuth2Client/NXOAuth2Client.m         | 44 ++++++++---------
 Sources/OAuth2Client/NXOAuth2Connection.h     | 20 ++++----
 Sources/OAuth2Client/NXOAuth2Connection.m     |  8 ++--
 .../OAuth2Client/NXOAuth2FileStreamWrapper.h  | 15 ++++--
 .../OAuth2Client/NXOAuth2FileStreamWrapper.m  | 10 ++--
 Sources/OAuth2Client/NXOAuth2PostBodyPart.h   | 20 ++++++--
 Sources/OAuth2Client/NXOAuth2PostBodyPart.m   | 24 +++++-----
 Sources/OAuth2Client/NXOAuth2PostBodyStream.h |  2 +-
 Sources/OAuth2Client/NXOAuth2PostBodyStream.m |  2 +-
 Sources/OAuth2Client/NXOAuth2Request.h        |  4 +-
 Sources/OAuth2Client/NXOAuth2Request.m        |  2 +-
 18 files changed, 158 insertions(+), 116 deletions(-)

diff --git a/NXOAuth2Account+Private.h b/NXOAuth2Account+Private.h
index f4dd6e74..b512ff38 100644
--- a/NXOAuth2Account+Private.h
+++ b/NXOAuth2Account+Private.h
@@ -15,7 +15,10 @@
 
 @interface NXOAuth2Account (Private)
 
-- (id)initAccountWithOAuthClient:(NXOAuth2Client *)oauthClient accountType:(NSString *)accountType;
-- (id)initAccountWithAccessToken:(NXOAuth2AccessToken *)accessToken accountType:(NSString *)accountType;
+- (instancetype)initAccountWithOAuthClient:(NXOAuth2Client *)oauthClient
+                               accountType:(NSString *)accountType;
+
+- (instancetype)initAccountWithAccessToken:(NXOAuth2AccessToken *)accessToken
+                               accountType:(NSString *)accountType;
 
 @end
diff --git a/Sources/OAuth2Client/NXOAuth2AccessToken.h b/Sources/OAuth2Client/NXOAuth2AccessToken.h
index 72e4c6c8..d165b974 100644
--- a/Sources/OAuth2Client/NXOAuth2AccessToken.h
+++ b/Sources/OAuth2Client/NXOAuth2AccessToken.h
@@ -33,14 +33,34 @@
 @property (nonatomic, readonly) NSSet *scope;
 @property (nonatomic, readonly) NSString *responseBody;
 
-+ (id)tokenWithResponseBody:(NSString *)responseBody;
-+ (id)tokenWithResponseBody:(NSString *)responseBody tokenType:(NSString *)tokenType;
++ (instancetype)tokenWithResponseBody:(NSString *)responseBody;
 
-- (id)initWithAccessToken:(NSString *)accessToken;
-- (id)initWithAccessToken:(NSString *)accessToken refreshToken:(NSString *)refreshToken expiresAt:(NSDate *)expiryDate;
-- (id)initWithAccessToken:(NSString *)accessToken refreshToken:(NSString *)refreshToken expiresAt:(NSDate *)expiryDate scope:(NSSet *)scope;
-- (id)initWithAccessToken:(NSString *)accessToken refreshToken:(NSString *)refreshToken expiresAt:(NSDate *)expiryDate scope:(NSSet *)scope responseBody:(NSString *)responseBody;
-- (id)initWithAccessToken:(NSString *)accessToken refreshToken:(NSString *)refreshToken expiresAt:(NSDate *)expiryDate scope:(NSSet *)scope responseBody:(NSString *)responseBody tokenType:(NSString*)tokenType; // designated
++ (instancetype)tokenWithResponseBody:(NSString *)responseBody
+                            tokenType:(NSString *)tokenType;
+
+- (instancetype)initWithAccessToken:(NSString *)accessToken;
+
+- (instancetype)initWithAccessToken:(NSString *)accessToken
+                       refreshToken:(NSString *)refreshToken
+                          expiresAt:(NSDate *)expiryDate;
+
+- (instancetype)initWithAccessToken:(NSString *)accessToken
+                       refreshToken:(NSString *)refreshToken
+                          expiresAt:(NSDate *)expiryDate
+                              scope:(NSSet *)scope;
+
+- (instancetype)initWithAccessToken:(NSString *)accessToken
+                       refreshToken:(NSString *)refreshToken
+                          expiresAt:(NSDate *)expiryDate
+                              scope:(NSSet *)scope
+                       responseBody:(NSString *)responseBody;
+
+- (instancetype)initWithAccessToken:(NSString *)accessToken
+                       refreshToken:(NSString *)refreshToken
+                          expiresAt:(NSDate *)expiryDate
+                              scope:(NSSet *)scope
+                       responseBody:(NSString *)responseBody
+                          tokenType:(NSString*)tokenType; // designated
 
 - (void)restoreWithOldToken:(NXOAuth2AccessToken *)oldToken;
 
@@ -48,7 +68,7 @@
 
 //TODO: Support alternate KeyChain Locations
 
-+ (id)tokenFromDefaultKeychainWithServiceProviderName:(NSString *)provider;
++ (instancetype)tokenFromDefaultKeychainWithServiceProviderName:(NSString *)provider;
 - (void)storeInDefaultKeychainWithServiceProviderName:(NSString *)provider;
 - (void)removeFromDefaultKeychainWithServiceProviderName:(NSString *)provider;
 
diff --git a/Sources/OAuth2Client/NXOAuth2AccessToken.m b/Sources/OAuth2Client/NXOAuth2AccessToken.m
index bedef7b8..aefe1c9d 100644
--- a/Sources/OAuth2Client/NXOAuth2AccessToken.m
+++ b/Sources/OAuth2Client/NXOAuth2AccessToken.m
@@ -20,12 +20,12 @@ @implementation NXOAuth2AccessToken
 
 #pragma mark Lifecycle
 
-+ (id)tokenWithResponseBody:(NSString *)theResponseBody;
++ (instancetype)tokenWithResponseBody:(NSString *)theResponseBody;
 {
     return [self tokenWithResponseBody:theResponseBody tokenType:nil];
 }
 
-+ (id)tokenWithResponseBody:(NSString *)theResponseBody tokenType:(NSString *)tokenType;
++ (instancetype)tokenWithResponseBody:(NSString *)theResponseBody tokenType:(NSString *)tokenType;
 {
     NSDictionary *jsonDict = nil;
     Class jsonSerializationClass = NSClassFromString(@"NSJSONSerialization");
@@ -78,12 +78,12 @@ + (id)tokenWithResponseBody:(NSString *)theResponseBody tokenType:(NSString *)to
                                            tokenType:tokenType];
 }
 
-- (id)initWithAccessToken:(NSString *)anAccessToken;
+- (instancetype)initWithAccessToken:(NSString *)anAccessToken;
 {
     return [self initWithAccessToken:anAccessToken refreshToken:nil expiresAt:nil];
 }
 
-- (id)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRefreshToken expiresAt:(NSDate *)anExpiryDate;
+- (instancetype)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRefreshToken expiresAt:(NSDate *)anExpiryDate;
 {
     return [[[self class] alloc] initWithAccessToken:anAccessToken
                                         refreshToken:aRefreshToken
@@ -91,7 +91,7 @@ - (id)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRe
                                                scope:nil];
 }
 
-- (id)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRefreshToken expiresAt:(NSDate *)anExpiryDate scope:(NSSet *)aScope;
+- (instancetype)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRefreshToken expiresAt:(NSDate *)anExpiryDate scope:(NSSet *)aScope;
 {
     return [[[self class] alloc] initWithAccessToken:anAccessToken
                                         refreshToken:aRefreshToken
@@ -100,7 +100,7 @@ - (id)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRe
                                         responseBody:nil];
 }
 
-- (id)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRefreshToken expiresAt:(NSDate *)anExpiryDate scope:(NSSet *)aScope responseBody:(NSString *)aResponseBody;
+- (instancetype)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRefreshToken expiresAt:(NSDate *)anExpiryDate scope:(NSSet *)aScope responseBody:(NSString *)aResponseBody;
 {
     return [[[self class] alloc] initWithAccessToken:anAccessToken
                                         refreshToken:aRefreshToken
@@ -110,7 +110,7 @@ - (id)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRe
                                            tokenType:nil];
 }
 
-- (id)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRefreshToken expiresAt:(NSDate *)anExpiryDate scope:(NSSet *)aScope responseBody:(NSString *)aResponseBody tokenType:(NSString *)aTokenType
+- (instancetype)initWithAccessToken:(NSString *)anAccessToken refreshToken:(NSString *)aRefreshToken expiresAt:(NSDate *)anExpiryDate scope:(NSSet *)aScope responseBody:(NSString *)aResponseBody tokenType:(NSString *)aTokenType
 {
     // a token object without an actual token is not what we want!
     NSAssert1(anAccessToken, @"No token from token response: %@", aResponseBody);
@@ -191,7 +191,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder
     }
 }
 
-- (id)initWithCoder:(NSCoder *)aDecoder
+- (instancetype)initWithCoder:(NSCoder *)aDecoder
 {
     NSString *decodedAccessToken = [aDecoder decodeObjectForKey:@"accessToken"];
     
@@ -224,7 +224,7 @@ + (NSString *)serviceNameWithProvider:(NSString *)provider;
 
 #if TARGET_OS_IPHONE
 
-+ (id)tokenFromDefaultKeychainWithServiceProviderName:(NSString *)provider;
++ (instancetype)tokenFromDefaultKeychainWithServiceProviderName:(NSString *)provider;
 {
     NSString *serviceName = [[self class] serviceNameWithProvider:provider];
     NSDictionary *result = nil;
@@ -273,7 +273,7 @@ - (void)removeFromDefaultKeychainWithServiceProviderName:(NSString *)provider;
 
 #else
 
-+ (id)tokenFromDefaultKeychainWithServiceProviderName:(NSString *)provider;
++ (instancetype)tokenFromDefaultKeychainWithServiceProviderName:(NSString *)provider;
 {
     NSString *serviceName = [[self class] serviceNameWithProvider:provider];
     
diff --git a/Sources/OAuth2Client/NXOAuth2Account.m b/Sources/OAuth2Client/NXOAuth2Account.m
index 2355a477..fb23df9f 100644
--- a/Sources/OAuth2Client/NXOAuth2Account.m
+++ b/Sources/OAuth2Client/NXOAuth2Account.m
@@ -41,7 +41,7 @@ @implementation NXOAuth2Account (Private)
 
 #pragma mark Lifecycle
 
-- (id)initAccountWithOAuthClient:(NXOAuth2Client *)anOAuthClient accountType:(NSString *)anAccountType;
+- (instancetype)initAccountWithOAuthClient:(NXOAuth2Client *)anOAuthClient accountType:(NSString *)anAccountType;
 {
     self = [self initAccountWithAccessToken:anOAuthClient.accessToken
                                 accountType:anAccountType];
@@ -51,7 +51,7 @@ - (id)initAccountWithOAuthClient:(NXOAuth2Client *)anOAuthClient accountType:(NS
     return self;
 }
 
-- (id)initAccountWithAccessToken:(NXOAuth2AccessToken *)anAccessToken accountType:(NSString *)anAccountType;
+- (instancetype)initAccountWithAccessToken:(NXOAuth2AccessToken *)anAccessToken accountType:(NSString *)anAccountType;
 {
     self = [super init];
     if (self) {
@@ -202,7 +202,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder
     [aCoder encodeObject:userData forKey:@"userData"];
 }
 
-- (id)initWithCoder:(NSCoder *)aDecoder
+- (instancetype)initWithCoder:(NSCoder *)aDecoder
 {
     if (self = [super init]) {
         userData = [aDecoder decodeObjectForKey:@"userData"];
diff --git a/Sources/OAuth2Client/NXOAuth2AccountStore.h b/Sources/OAuth2Client/NXOAuth2AccountStore.h
index 05945884..0a5bc74a 100644
--- a/Sources/OAuth2Client/NXOAuth2AccountStore.h
+++ b/Sources/OAuth2Client/NXOAuth2AccountStore.h
@@ -75,7 +75,7 @@ typedef void(^NXOAuth2PreparedAuthorizationURLHandler)(NSURL *preparedURL);
     NSMutableDictionary *trustedCertificatesHandler;
 }
 
-+ (id)sharedStore;
++ (instancetype)sharedStore;
 
 #pragma mark Accessors
 
diff --git a/Sources/OAuth2Client/NXOAuth2AccountStore.m b/Sources/OAuth2Client/NXOAuth2AccountStore.m
index 45815ec4..b36a9de1 100644
--- a/Sources/OAuth2Client/NXOAuth2AccountStore.m
+++ b/Sources/OAuth2Client/NXOAuth2AccountStore.m
@@ -87,7 +87,7 @@ @implementation NXOAuth2AccountStore
 
 #pragma mark Lifecycle
 
-+ (id)sharedStore;
++ (instancetype)sharedStore;
 {
     static NXOAuth2AccountStore *shared;
     static dispatch_once_t onceToken;
@@ -97,7 +97,7 @@ + (id)sharedStore;
     return shared;
 }
 
-- (id)init;
+- (instancetype)init;
 {
     self = [super init];
     if (self) {
diff --git a/Sources/OAuth2Client/NXOAuth2Client.h b/Sources/OAuth2Client/NXOAuth2Client.h
index f5295c28..c9b3e3de 100644
--- a/Sources/OAuth2Client/NXOAuth2Client.h
+++ b/Sources/OAuth2Client/NXOAuth2Client.h
@@ -85,30 +85,30 @@ extern NSString * const NXOAuth2ClientConnectionContextTokenRefresh;
 /*!
  * Initializes the Client
  */
-- (id)initWithClientID:(NSString *)clientId
-          clientSecret:(NSString *)clientSecret
-          authorizeURL:(NSURL *)authorizeURL
-              tokenURL:(NSURL *)tokenURL
-              delegate:(NSObject *)delegate;
-
-- (id)initWithClientID:(NSString *)clientId
-          clientSecret:(NSString *)clientSecret
-          authorizeURL:(NSURL *)authorizeURL
-              tokenURL:(NSURL *)tokenURL
-           accessToken:(NXOAuth2AccessToken *)accessToken
-         keyChainGroup:(NSString *)keyChainGroup
-            persistent:(BOOL)shouldPersist
-              delegate:(NSObject *)delegate;
-
-- (id)initWithClientID:(NSString *)clientId
-          clientSecret:(NSString *)clientSecret
-          authorizeURL:(NSURL *)authorizeURL
-              tokenURL:(NSURL *)tokenURL
-           accessToken:(NXOAuth2AccessToken *)accessToken
-             tokenType:(NSString *)tokenType
-         keyChainGroup:(NSString *)keyChainGroup
-            persistent:(BOOL)shouldPersist
-              delegate:(NSObject *)delegate;
+- (instancetype)initWithClientID:(NSString *)clientId
+                    clientSecret:(NSString *)clientSecret
+                    authorizeURL:(NSURL *)authorizeURL
+                        tokenURL:(NSURL *)tokenURL
+                        delegate:(NSObject *)delegate;
+
+- (instancetype)initWithClientID:(NSString *)clientId
+                    clientSecret:(NSString *)clientSecret
+                    authorizeURL:(NSURL *)authorizeURL
+                        tokenURL:(NSURL *)tokenURL
+                     accessToken:(NXOAuth2AccessToken *)accessToken
+                   keyChainGroup:(NSString *)keyChainGroup
+                      persistent:(BOOL)shouldPersist
+                        delegate:(NSObject *)delegate;
+
+- (instancetype)initWithClientID:(NSString *)clientId
+                    clientSecret:(NSString *)clientSecret
+                    authorizeURL:(NSURL *)authorizeURL
+                        tokenURL:(NSURL *)tokenURL
+                     accessToken:(NXOAuth2AccessToken *)accessToken
+                       tokenType:(NSString *)tokenType
+                   keyChainGroup:(NSString *)keyChainGroup
+                      persistent:(BOOL)shouldPersist
+                        delegate:(NSObject *)delegate;
 
 - (BOOL)openRedirectURL:(NSURL *)URL;
 
diff --git a/Sources/OAuth2Client/NXOAuth2Client.m b/Sources/OAuth2Client/NXOAuth2Client.m
index 2dfa0f6e..dd3843e2 100644
--- a/Sources/OAuth2Client/NXOAuth2Client.m
+++ b/Sources/OAuth2Client/NXOAuth2Client.m
@@ -37,11 +37,11 @@ @implementation NXOAuth2Client
 
 #pragma mark Lifecycle
 
-- (id)initWithClientID:(NSString *)aClientId
-          clientSecret:(NSString *)aClientSecret
-          authorizeURL:(NSURL *)anAuthorizeURL
-              tokenURL:(NSURL *)aTokenURL
-              delegate:(NSObject *)aDelegate;
+- (instancetype)initWithClientID:(NSString *)aClientId
+                    clientSecret:(NSString *)aClientSecret
+                    authorizeURL:(NSURL *)anAuthorizeURL
+                        tokenURL:(NSURL *)aTokenURL
+                        delegate:(NSObject *)aDelegate;
 {
     return [self initWithClientID:aClientId
                      clientSecret:aClientSecret
@@ -53,14 +53,14 @@ - (id)initWithClientID:(NSString *)aClientId
                          delegate:aDelegate];
 }
 
-- (id)initWithClientID:(NSString *)aClientId
-          clientSecret:(NSString *)aClientSecret
-          authorizeURL:(NSURL *)anAuthorizeURL
-              tokenURL:(NSURL *)aTokenURL
-           accessToken:(NXOAuth2AccessToken *)anAccessToken
-         keyChainGroup:(NSString *)aKeyChainGroup
-            persistent:(BOOL)shouldPersist
-              delegate:(NSObject *)aDelegate;
+- (instancetype)initWithClientID:(NSString *)aClientId
+                    clientSecret:(NSString *)aClientSecret
+                    authorizeURL:(NSURL *)anAuthorizeURL
+                        tokenURL:(NSURL *)aTokenURL
+                     accessToken:(NXOAuth2AccessToken *)anAccessToken
+                   keyChainGroup:(NSString *)aKeyChainGroup
+                      persistent:(BOOL)shouldPersist
+                        delegate:(NSObject *)aDelegate;
 {
     return [self initWithClientID:aClientId
                      clientSecret:aClientSecret
@@ -73,15 +73,15 @@ - (id)initWithClientID:(NSString *)aClientId
                          delegate:aDelegate];
 }
 
-- (id)initWithClientID:(NSString *)aClientId
-          clientSecret:(NSString *)aClientSecret
-          authorizeURL:(NSURL *)anAuthorizeURL
-              tokenURL:(NSURL *)aTokenURL
-           accessToken:(NXOAuth2AccessToken *)anAccessToken
-             tokenType:(NSString *)aTokenType
-         keyChainGroup:(NSString *)aKeyChainGroup
-            persistent:(BOOL)shouldPersist
-              delegate:(NSObject *)aDelegate;
+- (instancetype)initWithClientID:(NSString *)aClientId
+                    clientSecret:(NSString *)aClientSecret
+                    authorizeURL:(NSURL *)anAuthorizeURL
+                        tokenURL:(NSURL *)aTokenURL
+                     accessToken:(NXOAuth2AccessToken *)anAccessToken
+                       tokenType:(NSString *)aTokenType
+                   keyChainGroup:(NSString *)aKeyChainGroup
+                      persistent:(BOOL)shouldPersist
+                        delegate:(NSObject *)aDelegate;
 {
     NSAssert(aTokenURL != nil && anAuthorizeURL != nil, @"No token or no authorize URL");
     self = [super init];
diff --git a/Sources/OAuth2Client/NXOAuth2Connection.h b/Sources/OAuth2Client/NXOAuth2Connection.h
index ef41164c..c29feb54 100644
--- a/Sources/OAuth2Client/NXOAuth2Connection.h
+++ b/Sources/OAuth2Client/NXOAuth2Connection.h
@@ -87,16 +87,16 @@ typedef void(^NXOAuth2ConnectionSendingProgressHandler)(unsigned long long bytes
 @property (nonatomic, strong) NSDictionary *userInfo;
 @property (nonatomic, strong, readonly) NXOAuth2Client *client;
 
-- (id) initWithRequest:(NSMutableURLRequest *)request
-     requestParameters:(NSDictionary *)requestParameters
-           oauthClient:(NXOAuth2Client *)client
-sendingProgressHandler:(NXOAuth2ConnectionSendingProgressHandler)sendingProgressHandler
-       responseHandler:(NXOAuth2ConnectionResponseHandler)responseHandler;
-
-- (id)initWithRequest:(NSMutableURLRequest *)request
-    requestParameters:(NSDictionary *)requestParameters
-          oauthClient:(NXOAuth2Client *)client
-             delegate:(NSObject *)delegate;
+- (instancetype) initWithRequest:(NSMutableURLRequest *)request
+               requestParameters:(NSDictionary *)requestParameters
+                     oauthClient:(NXOAuth2Client *)client
+          sendingProgressHandler:(NXOAuth2ConnectionSendingProgressHandler)sendingProgressHandler
+                 responseHandler:(NXOAuth2ConnectionResponseHandler)responseHandler;
+
+- (instancetype)initWithRequest:(NSMutableURLRequest *)request
+              requestParameters:(NSDictionary *)requestParameters
+                    oauthClient:(NXOAuth2Client *)client
+                       delegate:(NSObject *)delegate;
 
 - (void)cancel;
 
diff --git a/Sources/OAuth2Client/NXOAuth2Connection.m b/Sources/OAuth2Client/NXOAuth2Connection.m
index a324850b..ef2d2a9f 100644
--- a/Sources/OAuth2Client/NXOAuth2Connection.m
+++ b/Sources/OAuth2Client/NXOAuth2Connection.m
@@ -64,10 +64,10 @@ -  (id)initWithRequest:(NSMutableURLRequest *)aRequest
     return self;
 }
 
-- (id)initWithRequest:(NSMutableURLRequest *)aRequest
-    requestParameters:(NSDictionary *)someRequestParameters
-          oauthClient:(NXOAuth2Client *)aClient
-             delegate:(NSObject *)aDelegate;
+- (instancetype)initWithRequest:(NSMutableURLRequest *)aRequest
+              requestParameters:(NSDictionary *)someRequestParameters
+                    oauthClient:(NXOAuth2Client *)aClient
+                       delegate:(NSObject *)aDelegate;
 {
     self = [super init];
     if (self) {
diff --git a/Sources/OAuth2Client/NXOAuth2FileStreamWrapper.h b/Sources/OAuth2Client/NXOAuth2FileStreamWrapper.h
index 590c8d43..f4542cdd 100755
--- a/Sources/OAuth2Client/NXOAuth2FileStreamWrapper.h
+++ b/Sources/OAuth2Client/NXOAuth2FileStreamWrapper.h
@@ -25,11 +25,18 @@
 @property (nonatomic, copy, readonly) NSString *fileName;
 @property (nonatomic, copy) NSString *contentType; // optional DEFAULT: "application/octettstream"
 
-+ (id)wrapperWithStream:(NSInputStream *)stream contentLength:(unsigned long long)contentLength DEPRECATED_ATTRIBUTE;
-- (id)initWithStream:(NSInputStream *)stream contentLength:(unsigned long long)contentLength DEPRECATED_ATTRIBUTE;
++ (instancetype)wrapperWithStream:(NSInputStream *)stream
+                    contentLength:(unsigned long long)contentLength DEPRECATED_ATTRIBUTE;
 
-+ (id)wrapperWithStream:(NSInputStream *)stream contentLength:(unsigned long long)contentLength fileName:(NSString *)fileName;
-- (id)initWithStream:(NSInputStream *)stream contentLength:(unsigned long long)contentLength fileName:(NSString *)fileName;
+- (instancetype)initWithStream:(NSInputStream *)stream
+                 contentLength:(unsigned long long)contentLength DEPRECATED_ATTRIBUTE;
 
++ (instancetype)wrapperWithStream:(NSInputStream *)stream
+                    contentLength:(unsigned long long)contentLength
+                         fileName:(NSString *)fileName;
+
+- (instancetype)initWithStream:(NSInputStream *)stream
+                 contentLength:(unsigned long long)contentLength
+                      fileName:(NSString *)fileName;
 
 @end
diff --git a/Sources/OAuth2Client/NXOAuth2FileStreamWrapper.m b/Sources/OAuth2Client/NXOAuth2FileStreamWrapper.m
index 11b7678a..c7fb6ec9 100755
--- a/Sources/OAuth2Client/NXOAuth2FileStreamWrapper.m
+++ b/Sources/OAuth2Client/NXOAuth2FileStreamWrapper.m
@@ -18,12 +18,12 @@ @implementation NXOAuth2FileStreamWrapper
 
 #pragma mark Class Methods
 
-+ (id)wrapperWithStream:(NSInputStream *)aStream contentLength:(unsigned long long)aContentLength;
++ (instancetype)wrapperWithStream:(NSInputStream *)aStream contentLength:(unsigned long long)aContentLength;
 {
     return [self wrapperWithStream:aStream contentLength:aContentLength fileName:nil];
 }
 
-+ (id)wrapperWithStream:(NSInputStream *)aStream contentLength:(unsigned long long)aContentLength fileName:(NSString *)aFileName;
++ (instancetype)wrapperWithStream:(NSInputStream *)aStream contentLength:(unsigned long long)aContentLength fileName:(NSString *)aFileName;
 {
     return [[self alloc] initWithStream:aStream contentLength:aContentLength fileName:aFileName];
 }
@@ -31,18 +31,18 @@ + (id)wrapperWithStream:(NSInputStream *)aStream contentLength:(unsigned long lo
 
 #pragma mark Lifecycle
 
-- (id)init;
+- (instancetype)init;
 {
     NSAssert(NO, @"-init should not be used in the NXOAuth2FileStreamWrapper");
     return nil;
 }
 
-- (id)initWithStream:(NSInputStream *)theStream contentLength:(unsigned long long)theContentLength;
+- (instancetype)initWithStream:(NSInputStream *)theStream contentLength:(unsigned long long)theContentLength;
 {
     return [self initWithStream:theStream contentLength:theContentLength fileName:nil];
 }
 
-- (id)initWithStream:(NSInputStream *)aStream contentLength:(unsigned long long)aContentLength fileName:(NSString *)aFileName;
+- (instancetype)initWithStream:(NSInputStream *)aStream contentLength:(unsigned long long)aContentLength fileName:(NSString *)aFileName;
 {
     if (!aFileName) aFileName = @"unknown";
     
diff --git a/Sources/OAuth2Client/NXOAuth2PostBodyPart.h b/Sources/OAuth2Client/NXOAuth2PostBodyPart.h
index d83cf6d2..f0376bab 100644
--- a/Sources/OAuth2Client/NXOAuth2PostBodyPart.h
+++ b/Sources/OAuth2Client/NXOAuth2PostBodyPart.h
@@ -34,12 +34,22 @@
  *    - NSData
  *    - NXOAuth2FileStreamWrapper
  */
-+ (id)partWithName:(NSString *)name content:(id)content;
-- (id)initWithName:(NSString *)name content:(id)content;
++ (instancetype)partWithName:(NSString *)name
+                     content:(id)content;
 
-- (id)initWithHeaders:(NSString *)headers dataContent:(NSData *)data;
-- (id)initWithName:(NSString *)name streamContent:(NSInputStream *)stream streamLength:(unsigned long long)streamLength fileName:(NSString *)fileName;
+- (instancetype)initWithName:(NSString *)name
+                     content:(id)content;
 
-- (id)initWithHeaders:(NSString *)headers streamContent:(NSInputStream *)stream length:(unsigned long long)length; //designated initializer
+- (instancetype)initWithHeaders:(NSString *)headers
+                    dataContent:(NSData *)data;
+
+- (instancetype)initWithName:(NSString *)name
+               streamContent:(NSInputStream *)stream
+                streamLength:(unsigned long long)streamLength
+                    fileName:(NSString *)fileName;
+
+- (instancetype)initWithHeaders:(NSString *)headers
+                  streamContent:(NSInputStream *)stream
+                         length:(unsigned long long)length; //designated initializer
 
 @end
diff --git a/Sources/OAuth2Client/NXOAuth2PostBodyPart.m b/Sources/OAuth2Client/NXOAuth2PostBodyPart.m
index 74d030d6..6c8345a5 100644
--- a/Sources/OAuth2Client/NXOAuth2PostBodyPart.m
+++ b/Sources/OAuth2Client/NXOAuth2PostBodyPart.m
@@ -17,9 +17,9 @@
 
 
 @interface NXOAuth2PostBodyPart(Private)
-- (id)initWithName:(NSString *)name dataContent:(NSData *)data;
-- (id)initWithName:(NSString *)name fileContent:(NSString *)path;
-- (id)initWithName:(NSString *)name stringContent:(NSString *)string;
+- (instancetype)initWithName:(NSString *)name dataContent:(NSData *)data;
+- (instancetype)initWithName:(NSString *)name fileContent:(NSString *)path;
+- (instancetype)initWithName:(NSString *)name stringContent:(NSString *)string;
 @end
 
 
@@ -27,12 +27,12 @@ @implementation NXOAuth2PostBodyPart
 
 #pragma mark Lifecycle
 
-+ (id)partWithName:(NSString *)name content:(id)content;
++ (instancetype)partWithName:(NSString *)name content:(id)content;
 {
     return [[self alloc] initWithName:name content:content];
 }
 
-- (id)initWithName:(NSString *)name content:(id)content;
+- (instancetype)initWithName:(NSString *)name content:(id)content;
 {
     if ([content isKindOfClass:[NSString class]]) {
         return [self initWithName:name stringContent:content];
@@ -50,7 +50,7 @@ - (id)initWithName:(NSString *)name content:(id)content;
     }
 }
 
-- (id)initWithName:(NSString *)name streamContent:(NSInputStream *)stream streamLength:(unsigned long long)streamLength fileName:(NSString *)fileName;
+- (instancetype)initWithName:(NSString *)name streamContent:(NSInputStream *)stream streamLength:(unsigned long long)streamLength fileName:(NSString *)fileName;
 {
     NSMutableString *headers = [NSMutableString string];
     [headers appendFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", name, fileName];
@@ -60,7 +60,7 @@ - (id)initWithName:(NSString *)name streamContent:(NSInputStream *)stream stream
     return [self initWithHeaders:headers streamContent:stream length:streamLength];
 }
 
-- (id)initWithName:(NSString *)name streamContent:(NSInputStream *)stream streamLength:(unsigned long long)streamLength fileName:(NSString *)fileName contentType:(NSString *)contentType;
+- (instancetype)initWithName:(NSString *)name streamContent:(NSInputStream *)stream streamLength:(unsigned long long)streamLength fileName:(NSString *)fileName contentType:(NSString *)contentType;
 {
     NSMutableString *headers = [NSMutableString string];
     [headers appendFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", name, fileName];
@@ -70,7 +70,7 @@ - (id)initWithName:(NSString *)name streamContent:(NSInputStream *)stream stream
     return [self initWithHeaders:headers streamContent:stream length:streamLength];
 }
 
-- (id)initWithName:(NSString *)name dataContent:(NSData *)data;
+- (instancetype)initWithName:(NSString *)name dataContent:(NSData *)data;
 {
     NSMutableString *headers = [NSMutableString string];
     [headers appendFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"unknown\"\r\n", name];
@@ -80,7 +80,7 @@ - (id)initWithName:(NSString *)name dataContent:(NSData *)data;
     return [self initWithHeaders:headers dataContent:data];
 }
 
-- (id)initWithName:(NSString *)name fileContent:(NSString *)path;
+- (instancetype)initWithName:(NSString *)name fileContent:(NSString *)path;
 {
     NSMutableString *headers = [NSMutableString string];
     [headers appendFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", name, [path lastPathComponent]];
@@ -100,7 +100,7 @@ - (id)initWithName:(NSString *)name fileContent:(NSString *)path;
                           length:[fileSize unsignedLongLongValue]];
 }
 
-- (id)initWithName:(NSString *)name stringContent:(NSString *)string;
+- (instancetype)initWithName:(NSString *)name stringContent:(NSString *)string;
 {
     NSMutableString *headers = [NSMutableString string];
     [headers appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n", name];
@@ -108,14 +108,14 @@ - (id)initWithName:(NSString *)name stringContent:(NSString *)string;
     return [self initWithHeaders:headers dataContent:[string dataUsingEncoding:NSUTF8StringEncoding]];
 }
 
-- (id)initWithHeaders:(NSString *)headers dataContent:(NSData *)data;
+- (instancetype)initWithHeaders:(NSString *)headers dataContent:(NSData *)data;
 {
     return [self initWithHeaders: headers
                    streamContent: [NSInputStream inputStreamWithData:data]
                           length: [data length]];
 }
 
-- (id)initWithHeaders:(NSString *)headers streamContent:(NSInputStream *)stream length:(unsigned long long)length;
+- (instancetype)initWithHeaders:(NSString *)headers streamContent:(NSInputStream *)stream length:(unsigned long long)length;
 {
     self = [super init];
     if(self) {
diff --git a/Sources/OAuth2Client/NXOAuth2PostBodyStream.h b/Sources/OAuth2Client/NXOAuth2PostBodyStream.h
index 9745db28..c08ea013 100644
--- a/Sources/OAuth2Client/NXOAuth2PostBodyStream.h
+++ b/Sources/OAuth2Client/NXOAuth2PostBodyStream.h
@@ -25,7 +25,7 @@
     unsigned long long numBytesTotal;
 }
 
-- (id)initWithParameters:(NSDictionary *)postParameters;
+- (instancetype)initWithParameters:(NSDictionary *)postParameters;
 
 @property (readonly) NSString *boundary;
 @property (readonly) unsigned long long length;
diff --git a/Sources/OAuth2Client/NXOAuth2PostBodyStream.m b/Sources/OAuth2Client/NXOAuth2PostBodyStream.m
index 8b156d84..92855402 100644
--- a/Sources/OAuth2Client/NXOAuth2PostBodyStream.m
+++ b/Sources/OAuth2Client/NXOAuth2PostBodyStream.m
@@ -26,7 +26,7 @@ @implementation NXOAuth2PostBodyStream
 
 #pragma mark Lifecycle
 
-- (id)initWithParameters:(NSDictionary *)postParameters;
+- (instancetype)initWithParameters:(NSDictionary *)postParameters;
 {
     self = [self init];
     if (self) {
diff --git a/Sources/OAuth2Client/NXOAuth2Request.h b/Sources/OAuth2Client/NXOAuth2Request.h
index 3bc2c270..aa601af5 100644
--- a/Sources/OAuth2Client/NXOAuth2Request.h
+++ b/Sources/OAuth2Client/NXOAuth2Request.h
@@ -40,7 +40,9 @@
 
 #pragma mark Lifecycle
 
-- (id)initWithResource:(NSURL *)url method:(NSString *)method parameters:(NSDictionary *)parameter;
+- (instancetype)initWithResource:(NSURL *)url
+                          method:(NSString *)method
+                      parameters:(NSDictionary *)parameter;
 
 
 #pragma mark Accessors
diff --git a/Sources/OAuth2Client/NXOAuth2Request.m b/Sources/OAuth2Client/NXOAuth2Request.m
index 680546c3..ad8564bd 100644
--- a/Sources/OAuth2Client/NXOAuth2Request.m
+++ b/Sources/OAuth2Client/NXOAuth2Request.m
@@ -51,7 +51,7 @@ + (void)performMethod:(NSString *)aMethod
 
 #pragma mark Lifecycle
 
-- (id)initWithResource:(NSURL *)aResource method:(NSString *)aMethod parameters:(NSDictionary *)someParameters;
+- (instancetype)initWithResource:(NSURL *)aResource method:(NSString *)aMethod parameters:(NSDictionary *)someParameters;
 {
     self = [super init];
     if (self) {

From 0f0d88b64d29057f9186b09b18676d0f3fe86405 Mon Sep 17 00:00:00 2001
From: andresmoreno 
Date: Wed, 17 Dec 2014 09:53:39 +0100
Subject: [PATCH 4/7] Refactor change for backward-compatibility.

---
 Sources/OAuth2Client/NXOAuth2Request.h |  3 +++
 Sources/OAuth2Client/NXOAuth2Request.m | 19 ++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/Sources/OAuth2Client/NXOAuth2Request.h b/Sources/OAuth2Client/NXOAuth2Request.h
index 3bc2c270..bb290676 100644
--- a/Sources/OAuth2Client/NXOAuth2Request.h
+++ b/Sources/OAuth2Client/NXOAuth2Request.h
@@ -62,6 +62,9 @@
 - (void)performRequestWithSendingProgressHandler:(NXOAuth2ConnectionSendingProgressHandler)progressHandler
                                  responseHandler:(NXOAuth2ConnectionResponseHandler)responseHandler;
 
+- (void)performRequestWithProgressHandler:(NXOAuth2ConnectionSendingProgressHandler)progressHandler
+                          responseHandler:(NXOAuth2ConnectionResponseHandler)responseHandler;
+
 
 #pragma mark Cancel
 
diff --git a/Sources/OAuth2Client/NXOAuth2Request.m b/Sources/OAuth2Client/NXOAuth2Request.m
index 1f24007b..54ae6cd9 100644
--- a/Sources/OAuth2Client/NXOAuth2Request.m
+++ b/Sources/OAuth2Client/NXOAuth2Request.m
@@ -112,12 +112,29 @@ - (void)performRequestWithSendingProgressHandler:(NXOAuth2ConnectionSendingProgr
                                            sendingProgressHandler:progressHandler
                                                   responseHandler:responseHandler];
     self.connection.delegate = self;
-    self.progressHandler = progressHandler;
     
     // Keep request object alive during the request is performing.
     self.me = self;
 }
 
+- (void)performRequestWithProgressHandler:(NXOAuth2ConnectionSendingProgressHandler)progressHandler
+                          responseHandler:(NXOAuth2ConnectionResponseHandler)responseHandler;
+{
+    NSAssert(self.me == nil, @"This object an only perform one request at the same time.");
+    
+    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.resource];
+    [request setHTTPMethod:self.requestMethod];
+    self.connection = [[NXOAuth2Connection alloc] initWithRequest:request
+                                                requestParameters:self.parameters
+                                                      oauthClient:self.account.oauthClient
+                                           sendingProgressHandler:progressHandler
+                                                  responseHandler:responseHandler];
+    self.connection.delegate = self;
+    self.progressHandler = progressHandler;
+    
+    // Keep request object alive during the request is performing.
+    self.me = self;
+}
 
 #pragma mark Cancel
 

From 304fc37b4fbea270db245b766031c5b311b21aa1 Mon Sep 17 00:00:00 2001
From: Andres Brun Moreno 
Date: Tue, 3 Mar 2015 22:14:58 +0100
Subject: [PATCH 5/7] removing pch

---
 Sources/OAuth2Client_Prefix.pch | 16 ----------------
 1 file changed, 16 deletions(-)
 delete mode 100644 Sources/OAuth2Client_Prefix.pch

diff --git a/Sources/OAuth2Client_Prefix.pch b/Sources/OAuth2Client_Prefix.pch
deleted file mode 100644
index cd5276b3..00000000
--- a/Sources/OAuth2Client_Prefix.pch
+++ /dev/null
@@ -1,16 +0,0 @@
-//
-//  OAuth2Client
-//
-//  Created by Ullrich Schäfer on 27.08.10.
-//
-//  Copyright 2010 nxtbgthng. All rights reserved. 
-//
-//  Licenced under the new BSD-licence.
-//  See README.md in this repository for 
-//  the full licence.
-//
-//
-
-#ifdef __OBJC__
-#import 
-#endif

From 0926ef5e0d97f4170a0874a962ee34912b51212e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andre=CC=81s=20Brun=20Moreno?= 
Date: Tue, 10 Mar 2015 15:46:35 +0100
Subject: [PATCH 6/7] Refactoring new performRequest method

---
 Sources/OAuth2Client/NXOAuth2Request.m | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/Sources/OAuth2Client/NXOAuth2Request.m b/Sources/OAuth2Client/NXOAuth2Request.m
index 5b29912e..c65fa731 100644
--- a/Sources/OAuth2Client/NXOAuth2Request.m
+++ b/Sources/OAuth2Client/NXOAuth2Request.m
@@ -120,20 +120,8 @@ - (void)performRequestWithSendingProgressHandler:(NXOAuth2ConnectionSendingProgr
 - (void)performRequestWithProgressHandler:(NXOAuth2ConnectionSendingProgressHandler)progressHandler
                           responseHandler:(NXOAuth2ConnectionResponseHandler)responseHandler;
 {
-    NSAssert(self.me == nil, @"This object an only perform one request at the same time.");
-    
-    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.resource];
-    [request setHTTPMethod:self.requestMethod];
-    self.connection = [[NXOAuth2Connection alloc] initWithRequest:request
-                                                requestParameters:self.parameters
-                                                      oauthClient:self.account.oauthClient
-                                           sendingProgressHandler:progressHandler
-                                                  responseHandler:responseHandler];
-    self.connection.delegate = self;
     self.progressHandler = progressHandler;
-    
-    // Keep request object alive during the request is performing.
-    self.me = self;
+    [self performRequestWithSendingProgressHandler:progressHandler responseHandler:responseHandler];
 }
 
 #pragma mark Cancel

From 701b1885311db434a37138e3538a35574dd17bf2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andre=CC=81s=20Brun=20Moreno?= 
Date: Tue, 10 Mar 2015 15:46:58 +0100
Subject: [PATCH 7/7] Revert "removing pch"

This reverts commit 304fc37b4fbea270db245b766031c5b311b21aa1.
---
 Sources/OAuth2Client_Prefix.pch | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 Sources/OAuth2Client_Prefix.pch

diff --git a/Sources/OAuth2Client_Prefix.pch b/Sources/OAuth2Client_Prefix.pch
new file mode 100644
index 00000000..cd5276b3
--- /dev/null
+++ b/Sources/OAuth2Client_Prefix.pch
@@ -0,0 +1,16 @@
+//
+//  OAuth2Client
+//
+//  Created by Ullrich Schäfer on 27.08.10.
+//
+//  Copyright 2010 nxtbgthng. All rights reserved. 
+//
+//  Licenced under the new BSD-licence.
+//  See README.md in this repository for 
+//  the full licence.
+//
+//
+
+#ifdef __OBJC__
+#import 
+#endif