From 4ccc4e7f8102cc34c38166a3cd0bab5bca719fbc Mon Sep 17 00:00:00 2001 From: nasli Date: Thu, 16 Nov 2017 13:24:43 +0100 Subject: [PATCH 1/7] Fix remove local cookies after status request --- .../OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m b/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m index a1f9bd4a..e832c684 100755 --- a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m +++ b/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m @@ -673,8 +673,6 @@ - (void) getStatusOfTheServer:(NSString *)serverPath onCommunication: _requestMethod = @"GET"; NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path: urlString parameters: nil]; - - request.HTTPShouldHandleCookies = false; NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; From 6ce0bd463f2f0e8e0269dadf23aac7b37ac64dc6 Mon Sep 17 00:00:00 2001 From: nasli Date: Mon, 27 Nov 2017 15:00:22 +0100 Subject: [PATCH 2/7] Fix update sharee permissions --- .../OCWebDavClient/OCWebDAVClient.m | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m b/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m index e832c684..b055338f 100755 --- a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m +++ b/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m @@ -741,19 +741,14 @@ - (void)shareByLinkFileOrFolderByServer:(NSString * _Nonnull)serverPath if (linkName) { self.postStringForShare = [NSString stringWithFormat:@"%@&name=%@",self.postStringForShare,linkName]; } - if ([publicUpload isEqualToString:@"true"]) { - - if (permissions != 0) { - self.postStringForShare = [NSString stringWithFormat:@"%@&permissions=%d",self.postStringForShare,(int)permissions]; - } else { - self.postStringForShare = [NSString stringWithFormat:@"%@&publicUpload=%@",self.postStringForShare,@"true"]; - } - + + if (permissions != 0) { + self.postStringForShare = [NSString stringWithFormat:@"%@&permissions=%d",self.postStringForShare,(int)permissions]; + } else if ([publicUpload isEqualToString:@"true"]) { + self.postStringForShare = [NSString stringWithFormat:@"%@&publicUpload=%@",self.postStringForShare,@"true"]; } else if ([publicUpload isEqualToString:@"false"]) { - self.postStringForShare = [NSString stringWithFormat:@"%@&publicUpload=%@",self.postStringForShare,@"false"]; } - [request setHTTPBody:[self.postStringForShare dataUsingEncoding:NSUTF8StringEncoding]]; @@ -858,7 +853,7 @@ - (void) updateShareItem:(NSInteger)shareId NSParameterAssert(success); - _requestMethod = @"PUT"; + _requestMethod = @"PUT"; NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil]; @@ -870,12 +865,10 @@ - (void) updateShareItem:(NSInteger)shareId self.postStringForShare = [NSString stringWithFormat:@"expireDate=%@",expirationTime]; }else if (linkName) { self.postStringForShare = [NSString stringWithFormat:@"name=%@",linkName]; - } if ([publicUpload isEqualToString:@"true"]) { - if (permissions != 0) { - self.postStringForShare = [NSString stringWithFormat:@"permissions=%d",(int)permissions]; - } else { - self.postStringForShare = [NSString stringWithFormat:@"publicUpload=%@",@"true"]; - } + } if (permissions != 0) { + self.postStringForShare = [NSString stringWithFormat:@"permissions=%d",(int)permissions]; + } else if ([publicUpload isEqualToString:@"true"]) { + self.postStringForShare = [NSString stringWithFormat:@"publicUpload=%@",@"true"]; } else if ([publicUpload isEqualToString:@"false"]) { self.postStringForShare = [NSString stringWithFormat:@"publicUpload=%@",@"false"]; } From d7a85c1d82e00639f81d9672707a71705df08153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Gonz=C3=A1lez?= Date: Thu, 30 Nov 2017 15:19:54 +0100 Subject: [PATCH 3/7] Added serveruserid parameter in request --- OCCommunicationLib/OCCommunicationLib/OCCommunication.h | 4 ++-- OCCommunicationLib/OCCommunicationLib/OCCommunication.m | 7 +++++-- .../OCCommunicationLib/OCFrameworkConstants.h | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/OCCommunicationLib/OCCommunicationLib/OCCommunication.h b/OCCommunicationLib/OCCommunicationLib/OCCommunication.h index 2c9756bb..af15c95e 100644 --- a/OCCommunicationLib/OCCommunicationLib/OCCommunication.h +++ b/OCCommunicationLib/OCCommunicationLib/OCCommunication.h @@ -511,8 +511,8 @@ typedef enum { * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue. */ - (void) getUserDisplayNameOfServer:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication - success:(void(^)(NSHTTPURLResponse *response, NSString *displayName, NSString *redirectedServer))success - failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest; + success:(void(^)(NSHTTPURLResponse *response, NSString *serverUserId, NSString *displayName, NSString *redirectedServer))success + failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest ; ///----------------------------------- diff --git a/OCCommunicationLib/OCCommunicationLib/OCCommunication.m b/OCCommunicationLib/OCCommunicationLib/OCCommunication.m index 184c770a..77ebf0a8 100644 --- a/OCCommunicationLib/OCCommunicationLib/OCCommunication.m +++ b/OCCommunicationLib/OCCommunicationLib/OCCommunication.m @@ -653,7 +653,7 @@ - (void) getUserDataOfServer:(NSString *)path onCommunication:(OCCommunication * ///----------------------------------- - (void) getUserDisplayNameOfServer:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication - success:(void(^)(NSHTTPURLResponse *response, NSString *displayName, NSString *redirectedServer))success + success:(void(^)(NSHTTPURLResponse *response, NSString *serverUserId, NSString *displayName, NSString *redirectedServer))success failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest { OCWebDAVClient *request = [OCWebDAVClient new]; @@ -664,6 +664,7 @@ - (void) getUserDisplayNameOfServer:(NSString *)path onCommunication:(OCCommunic NSError *jsonError = nil; NSString *displayName = @""; + NSString *serverUserId = @""; NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:responseObject options:kNilOptions error:&jsonError]; @@ -677,13 +678,15 @@ - (void) getUserDisplayNameOfServer:(NSString *)path onCommunication:(OCCommunic NSDictionary *userDataDict = [ocsDict objectForKey:k_json_ocs_data]; displayName = [userDataDict objectForKey:k_json_ocs_data_display_name]; + + serverUserId = [userDataDict objectForKey:k_json_ocs_data_user_id]; } for(NSString *key in [jsonDict allKeys]) { NSLog(@"%@",[jsonDict objectForKey:key]); } - success(response, displayName, request.redirectedServer); + success(response, serverUserId, displayName, request.redirectedServer); } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) { failureRequest(response,error, request.redirectedServer); diff --git a/OCCommunicationLib/OCCommunicationLib/OCFrameworkConstants.h b/OCCommunicationLib/OCCommunicationLib/OCFrameworkConstants.h index c640d781..a6d4dd5d 100644 --- a/OCCommunicationLib/OCCommunicationLib/OCFrameworkConstants.h +++ b/OCCommunicationLib/OCCommunicationLib/OCFrameworkConstants.h @@ -50,6 +50,7 @@ #define k_json_ocs @"ocs" #define k_json_ocs_data @"data" #define k_json_ocs_data_display_name @"display-name" +#define k_json_ocs_data_user_id @"id" //Url to access to Shared API to create #define k_url_acces_shared_api @"ocs/v1.php/apps/files_sharing/api/v1/shares" From e45b3d28abd1d813bd484dcd60685c7ee4d62adb Mon Sep 17 00:00:00 2001 From: nasli Date: Tue, 12 Dec 2017 14:10:45 +0100 Subject: [PATCH 4/7] Fix update unsopported Xcode version in travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 220f9327..9c9b30fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode8.2 +osx_image: xcode8.3 #xcode_project: OCCommunicationLib/ownCloud iOS library.xcodeproj #xcode_scheme: ownCloud iOS library #xcode_sdk: iphonesimulator From 22272c2564d1cb84c48c3b2ca081239d53c0fdd3 Mon Sep 17 00:00:00 2001 From: nasli Date: Thu, 14 Dec 2017 11:19:53 +0100 Subject: [PATCH 5/7] Clean cookies before add new ones in sharedStore --- .../OCWebDavClient/OCWebDAVClient.m | 17 +++++++++++++++-- .../OCCommunicationLib/Utils/UtilsFramework.m | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m b/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m index b055338f..6a68b44c 100755 --- a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m +++ b/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m @@ -101,6 +101,9 @@ - (NSURLSessionDataTask *)mr_operationWithRequest:(NSMutableURLRequest *)request self.originalUrlServer = [request.URL absoluteString]; } + NSLog(@"Before adding cookies, Main Request with token"); +// NSLog(@"Before adding cookies, Main Request with token for userId:%@ username:%@ url:%@ headers-> %@ ",sharedOCCommunication.credDto.userId, sharedOCCommunication.credDto.userName,request.URL, request.allHTTPHeaderFields); + if (sharedOCCommunication.isCookiesAvailable) { //We add the cookies of that URL request = [UtilsFramework getRequestWithCookiesByRequest:request andOriginalUrlServer:self.originalUrlServer]; @@ -108,6 +111,8 @@ - (NSURLSessionDataTask *)mr_operationWithRequest:(NSMutableURLRequest *)request [UtilsFramework deleteAllCookies]; } + //NSLog(@"Main Request with token for userId:%@ username:%@ url:%@ headers-> %@ ",sharedOCCommunication.credDto.userId, sharedOCCommunication.credDto.userName,request.URL, request.allHTTPHeaderFields); + __block NSURLSessionDataTask *sessionDataTask; sessionDataTask = [sharedOCCommunication.networkSessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { @@ -176,6 +181,9 @@ - (NSURLSessionDataTask *)mr_operationWithRequest:(NSMutableURLRequest *)request self.originalUrlServer = [request.URL absoluteString]; } + NSLog(@"Before adding cookies"); + //NSLog(@"Before adding cookies, Request for userId:%@ username:%@ url:%@ headers-> %@ ",sharedOCCommunication.credDto.userId, sharedOCCommunication.credDto.userName,request.URL, request.allHTTPHeaderFields); + if (sharedOCCommunication.isCookiesAvailable) { //We add the cookies of that URL request = [UtilsFramework getRequestWithCookiesByRequest:request andOriginalUrlServer:self.originalUrlServer]; @@ -183,6 +191,8 @@ - (NSURLSessionDataTask *)mr_operationWithRequest:(NSMutableURLRequest *)request [UtilsFramework deleteAllCookies]; } + // NSLog(@"Request for userId:%@ username:%@ url:%@ headers-> %@ ",sharedOCCommunication.credDto.userId, sharedOCCommunication.credDto.userName,request.URL, request.allHTTPHeaderFields); + __block NSURLSessionDataTask *sessionDataTask; sessionDataTask = [sharedOCCommunication.networkSessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { @@ -316,7 +326,6 @@ - (void)mr_listPath:(NSString *)path depth:(NSUInteger)depth onCommunication: [request setHTTPBody:[@"" dataUsingEncoding:NSUTF8StringEncoding]]; [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"]; - NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; [sessionDataTask resume]; @@ -342,7 +351,6 @@ - (void)mr_listPath:(NSString *)path depth:(NSUInteger)depth withUserSessionToke [request setHTTPBody:[@"" dataUsingEncoding:NSUTF8StringEncoding]]; [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"]; - NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication withUserSessionToken:token success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; [sessionDataTask resume]; @@ -599,6 +607,9 @@ - (NSURLSessionUploadTask *)putWithSessionLocalPath:(NSString *)localSource self.originalUrlServer = [request.URL absoluteString]; } + NSLog(@"Before adding cookies, Request put"); +// NSLog(@"Before adding cookies, Request put for userId:%@ username:%@ url:%@ headers-> %@ ",sharedOCCommunication.credDto.userId, sharedOCCommunication.credDto.userName,request.URL, request.allHTTPHeaderFields); + if (sharedOCCommunication.isCookiesAvailable) { //We add the cookies of that URL request = [UtilsFramework getRequestWithCookiesByRequest:request andOriginalUrlServer:self.originalUrlServer]; @@ -606,6 +617,8 @@ - (NSURLSessionUploadTask *)putWithSessionLocalPath:(NSString *)localSource [UtilsFramework deleteAllCookies]; } + // NSLog(@"Request put for userId:%@ username:%@ url:%@ headers-> %@ ",sharedOCCommunication.credDto.userId, sharedOCCommunication.credDto.userName,request.URL, request.allHTTPHeaderFields); + NSURL *file = [NSURL fileURLWithPath:localSource]; sharedOCCommunication.uploadSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer]; diff --git a/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.m b/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.m index ecedbfec..241f9e60 100644 --- a/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.m +++ b/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.m @@ -479,6 +479,7 @@ + (NSMutableURLRequest *) getRequestWithCookiesByRequest: (NSMutableURLRequest * NSArray *cookieStorage = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:originalUrlServer]]; NSDictionary *cookieHeaders = [NSHTTPCookie requestHeaderFieldsWithCookies:cookieStorage]; + [request setValue:@"" forHTTPHeaderField:@"Cookie"]; for (NSString *key in cookieHeaders) { [request addValue:cookieHeaders[key] forHTTPHeaderField:key]; } From 9bc53f3ac174148b84285fd0a8a414e7eb0b41f7 Mon Sep 17 00:00:00 2001 From: nasli Date: Wed, 20 Dec 2017 11:14:29 +0100 Subject: [PATCH 6/7] Fix crash trying to refresh a token without user --- .../OCWebDavClient/OCWebDAVClient.m | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m b/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m index 6a68b44c..f0a5b44d 100755 --- a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m +++ b/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m @@ -119,8 +119,9 @@ - (NSURLSessionDataTask *)mr_operationWithRequest:(NSMutableURLRequest *)request if (!error) { success((NSHTTPURLResponse*)response,responseObject, token); } else { - if (((NSHTTPURLResponse*)response).statusCode == 401 && - sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN) { + if (((NSHTTPURLResponse*)response).statusCode == 401 + && sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN + && sharedOCCommunication.credDto.userId != nil) { if (ntimes <= 0) { if (failure) { failure((NSHTTPURLResponse*)response, responseObject, error, token); @@ -200,7 +201,9 @@ - (NSURLSessionDataTask *)mr_operationWithRequest:(NSMutableURLRequest *)request success((NSHTTPURLResponse*)response,responseObject); } else { - if (((NSHTTPURLResponse*)response).statusCode == 401 && sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN) { + if (((NSHTTPURLResponse*)response).statusCode == 401 + && sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN + && sharedOCCommunication.credDto.userId != nil) { if (ntimes <= 0) { if (failure) { failure((NSHTTPURLResponse*)response, responseObject, error); @@ -404,7 +407,9 @@ - (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSMutableURLRequest *)req if (!error) { success(response,filePath); } else { - if (((NSHTTPURLResponse*)response).statusCode == 401 && sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN) { + if (((NSHTTPURLResponse*)response).statusCode == 401 + && sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN + && sharedOCCommunication.credDto.userId != nil) { if (ntimes <= 0) { if (failure) { failure(response, error); @@ -524,8 +529,9 @@ - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSMutableURLRequest *)request if (!error) { success(response,responseObject); } else { - if ( ((NSHTTPURLResponse*)response).statusCode == 401 && - sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN ){ + if ( ((NSHTTPURLResponse*)response).statusCode == 401 + && sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN + && sharedOCCommunication.credDto.userId != nil){ if (ntimes <= 0) { if (failure) { failure(response, responseObject, error); From ea2188d01d178188f6607bb8c7cf1fc02d3685db Mon Sep 17 00:00:00 2001 From: nasli Date: Thu, 21 Dec 2017 12:11:15 +0100 Subject: [PATCH 7/7] Update changelog and version number --- Doc_Changelog.md | 12 +++++++++++- README.md | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Doc_Changelog.md b/Doc_Changelog.md index 57bbc5a3..95dc844b 100644 --- a/Doc_Changelog.md +++ b/Doc_Changelog.md @@ -1,4 +1,14 @@ -## What's new in 2.1.0 version +## What's new in 2.2.0 version +- Added OAuth2 support with automatic refresh of new tokens +- Added support to new public share link option that allows you to share a folder with only the option of uploading files to it +- Added methods to get user data and features supported by server +- Fix updating share link permissions +- Improved cookies handling +- Improved OCErrors +- Updated travis file + + +## 2.1.0 version - Added support multiple share links - Added new method to get supported server features by version - Improve error handling diff --git a/README.md b/README.md index d7e4a7a5..696b3087 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ownCloud iOS Library v 2.1.0 +# ownCloud iOS Library v 2.2.0 ### Introduction Using ownCloud iOS library it will be the easiest way to communicate with ownCloud servers. @@ -116,6 +116,6 @@ ownCloud iOS library uses some classes based in https://github.com/zwaldowski/D ### Compatibility -ownCloud iOS library supports iOS 8, iOS 9 and iOS10 and works in Xcode 8. +ownCloud iOS library supports iOS 9 and iOS10 and works in Xcode 8. ownCloud iOS library supports ownCloud server from version 4.5.