Skip to content

Adding progress block for download operations #153

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
7 changes: 5 additions & 2 deletions NXOAuth2Account+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
<pre>
[[NSNotificationCenter defaultCenter] addObserverForName:NXOAuth2AccountStoreDidFailToRequestAccessNotification
object:[NXOAuth2AccountStore sharedStore]
Expand Down Expand Up @@ -157,7 +157,7 @@ NSDictionary *userData = // ...
account.userData = userData;
</pre>

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

Expand All @@ -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.

<pre>
NXOAuth2Request *theRequest = [[NXOAuth2Request alloc] initWithResource:[NSURL URLWithString:@"https://...your service URL..."]
Expand Down
36 changes: 28 additions & 8 deletions Sources/OAuth2Client/NXOAuth2AccessToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,42 @@
@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;

#pragma mark Keychain Support

//TODO: Support alternate KeyChain Locations

+ (id)tokenFromDefaultKeychainWithServiceProviderName:(NSString *)provider;
+ (instancetype)tokenFromDefaultKeychainWithServiceProviderName:(NSString *)provider;
- (void)storeInDefaultKeychainWithServiceProviderName:(NSString *)provider;
- (void)removeFromDefaultKeychainWithServiceProviderName:(NSString *)provider;

Expand Down
20 changes: 10 additions & 10 deletions Sources/OAuth2Client/NXOAuth2AccessToken.m
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -78,20 +78,20 @@ + (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
expiresAt:anExpiryDate
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
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -191,7 +191,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder
}
}

- (id)initWithCoder:(NSCoder *)aDecoder
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
NSString *decodedAccessToken = [aDecoder decodeObjectForKey:@"accessToken"];

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -273,7 +273,7 @@ - (void)removeFromDefaultKeychainWithServiceProviderName:(NSString *)provider;

#else

+ (id)tokenFromDefaultKeychainWithServiceProviderName:(NSString *)provider;
+ (instancetype)tokenFromDefaultKeychainWithServiceProviderName:(NSString *)provider;
{
NSString *serviceName = [[self class] serviceNameWithProvider:provider];

Expand Down
6 changes: 3 additions & 3 deletions Sources/OAuth2Client/NXOAuth2Account.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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) {
Expand Down Expand Up @@ -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"];
Expand Down
2 changes: 1 addition & 1 deletion Sources/OAuth2Client/NXOAuth2AccountStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ typedef void(^NXOAuth2PreparedAuthorizationURLHandler)(NSURL *preparedURL);
NSMutableDictionary *trustedCertificatesHandler;
}

+ (id)sharedStore;
+ (instancetype)sharedStore;

#pragma mark Accessors

Expand Down
4 changes: 2 additions & 2 deletions Sources/OAuth2Client/NXOAuth2AccountStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ @implementation NXOAuth2AccountStore

#pragma mark Lifecycle

+ (id)sharedStore;
+ (instancetype)sharedStore;
{
static NXOAuth2AccountStore *shared;
static dispatch_once_t onceToken;
Expand All @@ -97,7 +97,7 @@ + (id)sharedStore;
return shared;
}

- (id)init;
- (instancetype)init;
{
self = [super init];
if (self) {
Expand Down
48 changes: 24 additions & 24 deletions Sources/OAuth2Client/NXOAuth2Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<NXOAuth2ClientDelegate> *)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<NXOAuth2ClientDelegate> *)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<NXOAuth2ClientDelegate> *)delegate;
- (instancetype)initWithClientID:(NSString *)clientId
clientSecret:(NSString *)clientSecret
authorizeURL:(NSURL *)authorizeURL
tokenURL:(NSURL *)tokenURL
delegate:(NSObject<NXOAuth2ClientDelegate> *)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<NXOAuth2ClientDelegate> *)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<NXOAuth2ClientDelegate> *)delegate;

- (BOOL)openRedirectURL:(NSURL *)URL;

Expand Down
44 changes: 22 additions & 22 deletions Sources/OAuth2Client/NXOAuth2Client.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ @implementation NXOAuth2Client

#pragma mark Lifecycle

- (id)initWithClientID:(NSString *)aClientId
clientSecret:(NSString *)aClientSecret
authorizeURL:(NSURL *)anAuthorizeURL
tokenURL:(NSURL *)aTokenURL
delegate:(NSObject<NXOAuth2ClientDelegate> *)aDelegate;
- (instancetype)initWithClientID:(NSString *)aClientId
clientSecret:(NSString *)aClientSecret
authorizeURL:(NSURL *)anAuthorizeURL
tokenURL:(NSURL *)aTokenURL
delegate:(NSObject<NXOAuth2ClientDelegate> *)aDelegate;
{
return [self initWithClientID:aClientId
clientSecret:aClientSecret
Expand All @@ -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<NXOAuth2ClientDelegate> *)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<NXOAuth2ClientDelegate> *)aDelegate;
{
return [self initWithClientID:aClientId
clientSecret:aClientSecret
Expand All @@ -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<NXOAuth2ClientDelegate> *)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<NXOAuth2ClientDelegate> *)aDelegate;
{
NSAssert(aTokenURL != nil && anAuthorizeURL != nil, @"No token or no authorize URL");
self = [super init];
Expand Down
20 changes: 10 additions & 10 deletions Sources/OAuth2Client/NXOAuth2Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<NXOAuth2ConnectionDelegate> *)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<NXOAuth2ConnectionDelegate> *)delegate;

- (void)cancel;

Expand Down
8 changes: 4 additions & 4 deletions Sources/OAuth2Client/NXOAuth2Connection.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ - (id)initWithRequest:(NSMutableURLRequest *)aRequest
return self;
}

- (id)initWithRequest:(NSMutableURLRequest *)aRequest
requestParameters:(NSDictionary *)someRequestParameters
oauthClient:(NXOAuth2Client *)aClient
delegate:(NSObject<NXOAuth2ConnectionDelegate> *)aDelegate;
- (instancetype)initWithRequest:(NSMutableURLRequest *)aRequest
requestParameters:(NSDictionary *)someRequestParameters
oauthClient:(NXOAuth2Client *)aClient
delegate:(NSObject<NXOAuth2ConnectionDelegate> *)aDelegate;
{
self = [super init];
if (self) {
Expand Down
Loading