From 126ef18c18c7d4203a70abe9b3c26df1c7ed7ff0 Mon Sep 17 00:00:00 2001 From: Robert Dougan Date: Fri, 10 Oct 2014 20:29:49 +0200 Subject: [PATCH] Fix authorisation issue. Fixes #2. Remove check for authentication in APIRequest so that a request to get the oAuth token works as expected. Also set the oauthtoken in the API client so that the user account data is displayed. --- Classes/AccountPreferences.m | 1 + Classes/PutIOAPI.h | 2 +- Classes/PutIOAPI.m | 2 -- Classes/PutIOAPIRequest.m | 12 ++++++------ Classes/PutIOSync-Info.plist | 6 +----- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Classes/AccountPreferences.m b/Classes/AccountPreferences.m index b7ca14f..70842d8 100644 --- a/Classes/AccountPreferences.m +++ b/Classes/AccountPreferences.m @@ -74,6 +74,7 @@ -(void)accountSetupController:(AccountSetupController *)c didFinishSetupWithOAut [syncInstruction.managedObjectContext deleteObject:syncInstruction]; } [PutIOAPIKeychainManager setKeychainItemPassword:token]; + [[PutIOAPI api] setOAuthAccessToken:token]; // Reset username/email, we need to retrieve those from put.io NSUserDefaults *d = [NSUserDefaults standardUserDefaults]; diff --git a/Classes/PutIOAPI.h b/Classes/PutIOAPI.h index c9ab1e2..f7f7346 100644 --- a/Classes/PutIOAPI.h +++ b/Classes/PutIOAPI.h @@ -11,7 +11,7 @@ @property (readonly) NSString *oAuthClientID; @property (readonly) NSString *oAuthClientSecret; @property (readonly) NSString *oAuthRedirectURI; -@property (readonly) NSString *oAuthAccessToken; +@property (strong) NSString *oAuthAccessToken; @property (readonly) BOOL isAuthenticated; - (instancetype)initWithBaseURL:(NSURL*)baseURL oAuthAccessToken:(NSString*)oAuthAccessToken oAuthClientID:(NSString*)clientID oAuthRedirectURI:(NSString*)redirectURI; diff --git a/Classes/PutIOAPI.m b/Classes/PutIOAPI.m index 13e9ec9..135a683 100644 --- a/Classes/PutIOAPI.m +++ b/Classes/PutIOAPI.m @@ -8,8 +8,6 @@ #define kDefaultClientID @"197" #define kDefaultRedirectURI @"https://matthiasschwab.de/putiosync/callback.html" -static NSString *oAuthAccessToken; - @interface PutIOAPI() { NSOperationQueue *queue; diff --git a/Classes/PutIOAPIRequest.m b/Classes/PutIOAPIRequest.m index 257b2fe..7f9e991 100644 --- a/Classes/PutIOAPIRequest.m +++ b/Classes/PutIOAPIRequest.m @@ -36,11 +36,6 @@ -(NSString *)queryString -(void)main { - if(!self.api.isAuthenticated){ - [self failWithInternalError:PutIOAPIInternalErrorNotAuthorized userMessage:nil]; - return; - } - NSString *requestURLString = [self.api.baseURL absoluteString]; requestURLString = [requestURLString stringByAppendingPathComponent:self.endpoint]; NSMutableDictionary *parameters; @@ -49,7 +44,12 @@ -(void)main }else{ parameters = [self.parameters mutableCopy]; } - parameters[@"oauth_token"] = self.api.oAuthAccessToken; + + // only add the oauth token if we are logged in + if (self.api.oAuthAccessToken) { + parameters[@"oauth_token"] = self.api.oAuthAccessToken; + } + NSString *parameterString = [parameters URLQueryString]; if(self.method == PutIOAPIMethodGET){ requestURLString = [requestURLString stringByAppendingFormat:@"?%@", parameterString]; diff --git a/Classes/PutIOSync-Info.plist b/Classes/PutIOSync-Info.plist index a3f4215..b8add30 100644 --- a/Classes/PutIOSync-Info.plist +++ b/Classes/PutIOSync-Info.plist @@ -30,11 +30,7 @@ CFBundleVersion -<<<<<<< HEAD - 330 -======= - 326 ->>>>>>> release/0.8.2_beta + 366 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion