diff --git a/.gitignore b/.gitignore index 6e137049..7e7e245b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Xcode .DS_Store */build/* +_build/ *.pbxuser !default.pbxuser *.mode1v3 @@ -16,6 +17,8 @@ DerivedData .idea/ *.hmap *.xccheckout +*.pyc +xcshareddata/ #CocoaPods Pods diff --git a/OCCommunicationLib/OCCommunicationLib/OCCapabilities.h b/OCCommunicationLib/OCCommunicationLib/OCCapabilities.h index bb8d6042..05a810f6 100644 --- a/OCCommunicationLib/OCCommunicationLib/OCCapabilities.h +++ b/OCCommunicationLib/OCCommunicationLib/OCCapabilities.h @@ -27,7 +27,7 @@ #import -@interface OCCapabilities : NSObject +@interface OCCapabilities : NSObject /*VERSION*/ @property (nonatomic) NSInteger versionMajor; @@ -76,6 +76,7 @@ @property (nonatomic) BOOL isFileUndeleteEnabled; @property (nonatomic) BOOL isFileVersioningEnabled; - +- (void)encodeWithCoder:(NSCoder *)aCoder; +- (id)initWithCoder:(NSCoder *)aDecoder; @end diff --git a/OCCommunicationLib/OCCommunicationLib/OCCapabilities.m b/OCCommunicationLib/OCCommunicationLib/OCCapabilities.m index ce69b333..c31782d6 100644 --- a/OCCommunicationLib/OCCommunicationLib/OCCapabilities.m +++ b/OCCommunicationLib/OCCommunicationLib/OCCapabilities.m @@ -44,6 +44,125 @@ - (id)init { return self; } +#pragma mark - NSCopying +-(id) copyWithZone:(NSZone *)zone { + OCCapabilities *capCopy = [[OCCapabilities alloc]init]; + capCopy.versionMajor = self.versionMajor; + capCopy.versionMinor = self.versionMinor; + capCopy.versionMicro = self.versionMicro; + capCopy.versionString = self.versionString; + capCopy.versionEdition = self.versionEdition; + + capCopy.corePollInterval = self.corePollInterval; + + capCopy.isFilesSharingAPIEnabled = self.isFilesSharingAPIEnabled; + + capCopy.isFilesSharingShareLinkEnabled = self.isFilesSharingShareLinkEnabled; + + capCopy.isFilesSharingPasswordEnforcedEnabled = self.isFilesSharingPasswordEnforcedEnabled; + + capCopy.isFilesSharingExpireDateByDefaultEnabled = self.isFilesSharingExpireDateByDefaultEnabled; + capCopy.isFilesSharingExpireDateEnforceEnabled = self.isFilesSharingExpireDateEnforceEnabled; + capCopy.filesSharingExpireDateDaysNumber = self.filesSharingExpireDateDaysNumber; + + capCopy.isFilesSharingAllowUserSendMailNotificationAboutShareLinkEnabled = self.isFilesSharingAllowUserSendMailNotificationAboutShareLinkEnabled; + capCopy.isFilesSharingAllowPublicUploadsEnabled = self.isFilesSharingAllowPublicUploadsEnabled; + capCopy.isFilesSharingSupportsUploadOnlyEnabled = self.isFilesSharingSupportsUploadOnlyEnabled; + capCopy.isFilesSharingAllowUserCreateMultiplePublicLinksEnabled = self.isFilesSharingAllowUserCreateMultiplePublicLinksEnabled; + + capCopy.isFilesSharingAllowUserSendMailNotificationAboutOtherUsersEnabled = self.isFilesSharingAllowUserSendMailNotificationAboutOtherUsersEnabled; + capCopy.isFilesSharingReSharingEnabled = self.isFilesSharingReSharingEnabled; + + capCopy.isFilesSharingAllowUserSendSharesToOtherServersEnabled = self.isFilesSharingAllowUserSendSharesToOtherServersEnabled; + capCopy.isFilesSharingAllowUserReceiveSharesToOtherServersEnabled = self.isFilesSharingAllowUserReceiveSharesToOtherServersEnabled; + + capCopy.isFileBigFileChunkingEnabled = self.isFileBigFileChunkingEnabled; + capCopy.isFileUndeleteEnabled = self.isFileUndeleteEnabled; + capCopy.isFileVersioningEnabled = self.isFileVersioningEnabled; + + return capCopy; +} + +#pragma mark - NSSecureCoding + ++ (BOOL)supportsSecureCoding { + return YES; +} + +- (void)encodeWithCoder:(NSCoder *)aCoder +{ + [aCoder encodeInteger:self.versionMajor forKey:@"versionMajor"]; + [aCoder encodeInteger:self.versionMinor forKey:@"versionMinor"]; + [aCoder encodeInteger:self.versionMicro forKey:@"versionMicro"]; + [aCoder encodeObject:self.versionString forKey:@"versionString"]; + [aCoder encodeObject:self.versionEdition forKey:@"versionEdition"]; + + [aCoder encodeInteger:self.corePollInterval forKey:@"corePollInterval"]; + + [aCoder encodeBool:self.isFilesSharingAPIEnabled forKey:@"isFilesSharingAPIEnabled"]; + + [aCoder encodeBool:self.isFilesSharingShareLinkEnabled forKey:@"isFilesSharingShareLinkEnabled"]; + + [aCoder encodeBool:self.isFilesSharingPasswordEnforcedEnabled forKey:@"isFilesSharingPasswordEnforcedEnabled"]; + + [aCoder encodeBool:self.isFilesSharingExpireDateByDefaultEnabled forKey:@"isFilesSharingExpireDateByDefaultEnabled"]; + [aCoder encodeBool:self.isFilesSharingExpireDateEnforceEnabled forKey:@"isFilesSharingExpireDateEnforceEnabled"]; + [aCoder encodeInteger:self.filesSharingExpireDateDaysNumber forKey:@"filesSharingExpireDateDaysNumber"]; + + [aCoder encodeBool:self.isFilesSharingAllowUserSendMailNotificationAboutShareLinkEnabled forKey:@"isFilesSharingAllowUserSendMailNotificationAboutShareLinkEnabled"]; + [aCoder encodeBool:self.isFilesSharingAllowPublicUploadsEnabled forKey:@"isFilesSharingAllowPublicUploadsEnabled"]; + [aCoder encodeBool:self.isFilesSharingSupportsUploadOnlyEnabled forKey:@"isFilesSharingSupportsUploadOnlyEnabled"]; + [aCoder encodeBool:self.isFilesSharingAllowUserCreateMultiplePublicLinksEnabled forKey:@"isFilesSharingAllowUserCreateMultiplePublicLinksEnabled"]; + + [aCoder encodeBool:self.isFilesSharingAllowUserSendMailNotificationAboutOtherUsersEnabled forKey:@"isFilesSharingAllowUserSendMailNotificationAboutOtherUsersEnabled"]; + [aCoder encodeBool:self.isFilesSharingReSharingEnabled forKey:@"isFilesSharingReSharingEnabled"]; + + [aCoder encodeBool:self.isFilesSharingAllowUserSendSharesToOtherServersEnabled forKey:@"isFilesSharingAllowUserSendSharesToOtherServersEnabled"]; + [aCoder encodeBool:self.isFilesSharingAllowUserReceiveSharesToOtherServersEnabled forKey:@"isFilesSharingAllowUserReceiveSharesToOtherServersEnabled"]; + + [aCoder encodeBool:self.isFileBigFileChunkingEnabled forKey:@"isFileBigFileChunkingEnabled"]; + [aCoder encodeBool:self.isFileUndeleteEnabled forKey:@"isFileUndeleteEnabled"]; + [aCoder encodeBool:self.isFileVersioningEnabled forKey:@"isFileVersioningEnabled"]; +} + +- (instancetype)initWithCoder:(NSCoder *)aDecoder +{ + if (self = [self init]) { + self.versionMajor = [aDecoder decodeIntegerForKey:@"versionMajor"]; + self.versionMinor = [aDecoder decodeIntegerForKey:@"versionMinor"]; + self.versionMicro = [aDecoder decodeIntegerForKey:@"versionMicro"]; + self.versionString = [aDecoder decodeObjectForKey:@"versionString"]; + self.versionEdition = [aDecoder decodeObjectForKey:@"versionEdition"]; + + self.corePollInterval = [aDecoder decodeIntegerForKey:@"corePollInterval"]; + + self.isFilesSharingAPIEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingAPIEnabled"]; + + self.isFilesSharingShareLinkEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingShareLinkEnabled"]; + + self.isFilesSharingPasswordEnforcedEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingPasswordEnforcedEnabled"]; + + self.isFilesSharingExpireDateByDefaultEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingExpireDateByDefaultEnabled"]; + self.isFilesSharingExpireDateEnforceEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingExpireDateEnforceEnabled"]; + self.filesSharingExpireDateDaysNumber = [aDecoder decodeIntegerForKey:@"filesSharingExpireDateDaysNumber"]; + + self.isFilesSharingAllowUserSendMailNotificationAboutShareLinkEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingAllowUserSendMailNotificationAboutShareLinkEnabled"]; + self.isFilesSharingAllowPublicUploadsEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingAllowPublicUploadsEnabled"]; + self.isFilesSharingSupportsUploadOnlyEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingSupportsUploadOnlyEnabled"]; + self.isFilesSharingAllowUserCreateMultiplePublicLinksEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingAllowUserCreateMultiplePublicLinksEnabled"]; + + self.isFilesSharingAllowUserSendMailNotificationAboutOtherUsersEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingAllowUserSendMailNotificationAboutOtherUsersEnabled"]; + self.isFilesSharingReSharingEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingReSharingEnabled"]; + + self.isFilesSharingAllowUserSendSharesToOtherServersEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingAllowUserSendSharesToOtherServersEnabled"]; + self.isFilesSharingAllowUserReceiveSharesToOtherServersEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingAllowUserReceiveSharesToOtherServersEnabled"]; + + self.isFileBigFileChunkingEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingReSharingEnabled"]; + self.isFileUndeleteEnabled = [aDecoder decodeBoolForKey:@"isFileUndeleteEnabled"]; + self.isFileVersioningEnabled = [aDecoder decodeBoolForKey:@"isFileVersioningEnabled"]; + } + return self; +} @end diff --git a/OCCommunicationLib/OCCommunicationLib/OCCommunication.h b/OCCommunicationLib/OCCommunicationLib/OCCommunication.h index d2c02a40..2c9756bb 100644 --- a/OCCommunicationLib/OCCommunicationLib/OCCommunication.h +++ b/OCCommunicationLib/OCCommunicationLib/OCCommunication.h @@ -25,24 +25,19 @@ #import #import "OCServerFeatures.h" +#import "OCCredentialsDto.h" +#import "OCOAuth2Configuration.h" +#import "OCCredentialsStorage.h" +#import "OCTrustedCertificatesStore.h" -@class OCHTTPRequestOperation; @class AFURLSessionManager; @class AFSecurityPolicy; @class OCCapabilities; +@protocol OCCredentialsStorageDelegate; @interface OCCommunication : NSObject -//Type of credential -typedef enum { - credentialNotSet = -1, - credentialNormal = 0, //user, password - credentialCookie = 1, - credentialOauth = 2 -} kindOfCredentialEnum; - - typedef enum { OCErrorUnknown = 90, //On all errors OCErrorForbiddenCharacters = 100, //On create folder and rename @@ -51,15 +46,27 @@ typedef enum { OCErrorMovingFolderInsideItself = 112, //On move file or folder OCErrorFileToUploadDoesNotExist = 120, //The file that we want upload does not exist OCErrorForbiddenUnknown = 130, //For example, no write permissions to the target folder of an upload - OCErrorForbiddenWithSpecificMessage = 131 // For example, forbidden due to a firewall rule + OCErrorForbiddenWithSpecificMessage = 131, // For example, forbidden due to a firewall rule + OCErrorServerMaintenanceMode = 140, + + OCErrorOAuth2Error = 1000, + OCErrorOAuth2ErrorAccessDenied = 1010, + + OCErrorSslRecoverablePeerUnverified = 1100 + } OCErrorEnum; + //Private properties -@property NSInteger kindOfCredential; -@property (nonatomic, strong) NSString *user; -@property (nonatomic, strong) NSString *password; +@property (nonatomic, strong) OCCredentialsDto *credDto; + @property (nonatomic, strong) NSString *userAgent; +@property (nonatomic, strong) OCOAuth2Configuration *oauth2Configuration; +@property (nonatomic, strong) id credentialsStorage; +@property (nonatomic, strong) id trustedCertificatesStore; + + //Public properties @property (nonatomic, strong) NSMutableArray *downloadTaskNetworkQueueArray; @@ -107,43 +114,24 @@ typedef enum { #pragma mark - Credentials + ///----------------------------------- -/// @name Set Credential With User +/// @name Set Credentials ///----------------------------------- /** * Method to set credentials with user and password * - * @param user -> NSString username - * @param password -> NSString password + * @param credentials -> OCCredentialsDto credentials */ -- (void) setCredentialsWithUser:(NSString*) user andPassword:(NSString*) password; - -///----------------------------------- -/// @name Set Credential with cookie -///----------------------------------- - -/** - * Method that set credentials with cookie. - * Used for SAML servers. - * - * @param cookie -> NSString cookie string - */ -- (void) setCredentialsWithCookie:(NSString*) cookie; +- (void) setCredentials:(OCCredentialsDto *) credentials; ///----------------------------------- -/// @name Set Credential with OAuth +/// @name Set User Agent ///----------------------------------- -/** - * Method to set credentials for OAuth with token - * - * @param token -> NSString token - */ -- (void) setCredentialsOauthWithToken:(NSString*) token; - /** * @optional * @@ -151,8 +139,14 @@ typedef enum { * * @param userAgent -> String with the user agent. Ex. "iOS-ownCloud" */ -- (void) setUserAgent:(NSString *)userAgent; +- (void) setValueOfUserAgent:(NSString *) userAgent; + + +- (void) setValueOauth2Configuration:(OCOAuth2Configuration *)oauth2Configuration; + +- (void) setValueCredentialsStorage:(id)credentialsStorage; +- (void) setValueTrustedCertificatesStore:(id)trustedCertificatesStore; /* * Method to update the a request with the current credentials @@ -490,11 +484,44 @@ typedef enum { successRequest:(void(^)(NSHTTPURLResponse *response, NSString *serverVersion, NSString *redirectedServer)) success failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failure; +///----------------------------------- +/// @name getUserDataOfServer +///----------------------------------- + +/** + * Method to get the User data. + * + * @param path -> NSString server path + * + * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue. + */ +- (void) getUserDataOfServer:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication + success:(void(^)(NSHTTPURLResponse *response, NSData *responseData, NSString *redirectedServer))success + failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest; + +///----------------------------------- +/// @name getUserDisplayNameOfServer +///----------------------------------- + +/** + * Method to get the User display name. + * + * @param path -> NSString server path + * + * @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; + + ///----------------------------------- /// @name requestForUserNameByCookie ///----------------------------------- /** + * DEPRECATED use - getUserDataOfServer:onCommunication: or getUserDisplayNameOfServer:onCommunication: instead + * * Method to get the User name by the cookie of the session. Used with SAML servers. * * @param cookieString -> NSString The cookie of the session @@ -507,14 +534,15 @@ typedef enum { - (void) getUserNameByCookie:(NSString *) cookieString ofServerPath:(NSString *)path onCommunication: (OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *response, NSData *responseData, NSString *redirectedServer))success - failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failure; + failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failure +__deprecated_msg("Use - getUserDataOfServer:onCommunication: or getUserDisplayNameOfServer:onCommunication: instead"); ///----------------------------------- /// @name Get Features Supported By Server ///----------------------------------- /** - * DEPRECATED use + getFeaturesSupportedByServerForVersion: instead + * DEPRECATED use - getFeaturesSupportedByServerForVersion: instead * * Method get the features supported by the path server using the version string. * @@ -536,7 +564,8 @@ typedef enum { - (void) getFeaturesSupportedByServer:(NSString*) path onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, BOOL hasShareSupport, BOOL hasShareeSupport, BOOL hasCookiesSupport, BOOL hasForbiddenCharactersSupport, BOOL hasCapabilitiesSupport, BOOL hasFedSharesOptionShareSupport, NSString *redirectedServer)) success - failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failure __deprecated_msg("Use + getFeaturesSupportedByServerForVersion: instead"); + failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failure +__deprecated_msg("Use - getFeaturesSupportedByServerForVersion: instead"); ///----------------------------------- diff --git a/OCCommunicationLib/OCCommunicationLib/OCCommunication.m b/OCCommunicationLib/OCCommunicationLib/OCCommunication.m index 6aaca946..184c770a 100644 --- a/OCCommunicationLib/OCCommunicationLib/OCCommunication.m +++ b/OCCommunicationLib/OCCommunicationLib/OCCommunication.m @@ -24,7 +24,6 @@ // #import "OCCommunication.h" -#import "OCHTTPRequestOperation.h" #import "UtilsFramework.h" #import "OCXMLParser.h" #import "OCXMLSharedParser.h" @@ -39,6 +38,7 @@ #import "OCCapabilities.h" #import "OCServerFeatures.h" + @interface OCCommunication () @property (nonatomic, strong) NSString *currentServerVersion; @@ -57,9 +57,6 @@ -(id) init { //Init the Donwload queue array self.downloadTaskNetworkQueueArray = [NSMutableArray new]; - //Credentials not set yet - self.kindOfCredential = credentialNotSet; - [self setSecurityPolicyManagers:[self createSecurityPolicy]]; self.isCookiesAvailable = YES; @@ -115,9 +112,6 @@ -(id) initWithUploadSessionManager:(AFURLSessionManager *) uploadSessionManager self.isCookiesAvailable = YES; self.isForbiddenCharactersAvailable = NO; - //Credentials not set yet - self.kindOfCredential = credentialNotSet; - [self setSecurityPolicyManagers:[self createSecurityPolicy]]; self.uploadSessionManager = uploadSessionManager; @@ -135,9 +129,6 @@ -(id) initWithUploadSessionManager:(AFURLSessionManager *) uploadSessionManager //Init the Donwload queue array self.downloadTaskNetworkQueueArray = [NSMutableArray new]; - //Credentials not set yet - self.kindOfCredential = credentialNotSet; - [self setSecurityPolicyManagers:[self createSecurityPolicy]]; self.uploadSessionManager = uploadSessionManager; @@ -160,20 +151,27 @@ - (void)setSecurityPolicyManagers:(AFSecurityPolicy *)securityPolicy { #pragma mark - Setting Credentials -- (void) setCredentialsWithUser:(NSString*) user andPassword:(NSString*) password { - self.kindOfCredential = credentialNormal; - self.user = user; - self.password = password; +- (void) setCredentials:(OCCredentialsDto *) credentials { + + self.credDto = credentials; +} + + +- (void) setValueOfUserAgent:(NSString *) userAgent { + self.userAgent = userAgent; } -- (void) setCredentialsWithCookie:(NSString*) cookie { - self.kindOfCredential = credentialCookie; - self.password = cookie; + +- (void) setValueOauth2Configuration:(OCOAuth2Configuration *)oauth2Configuration { + self.oauth2Configuration = oauth2Configuration; } -- (void) setCredentialsOauthWithToken:(NSString*) token { - self.kindOfCredential = credentialOauth; - self.password = token; +- (void) setValueCredentialsStorage:(id)credentialsStorage { + self.credentialsStorage = credentialsStorage; +} + +- (void) setValueTrustedCertificatesStore:(id)trustedCertificatesStore { + self.trustedCertificatesStore = trustedCertificatesStore; } ///----------------------------------- @@ -193,22 +191,22 @@ - (id) getRequestWithCredentials:(id) request { if ([request isKindOfClass:[NSMutableURLRequest class]]) { NSMutableURLRequest *myRequest = (NSMutableURLRequest *)request; - switch (self.kindOfCredential) { - case credentialNotSet: + switch (self.credDto.authenticationMethod) { + case AuthenticationMethodNONE: + case AuthenticationMethodUNKNOWN: //Without credentials break; - case credentialNormal: + case AuthenticationMethodBASIC_HTTP_AUTH: { - NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", self.user, self.password]; + NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", self.credDto.userName, self.credDto.accessToken]; [myRequest addValue:[NSString stringWithFormat:@"Basic %@", [UtilsFramework AFBase64EncodedStringFromString:basicAuthCredentials]] forHTTPHeaderField:@"Authorization"]; break; } - case credentialCookie: - //NSLog(@"Cookie: %@", self.password); - [myRequest addValue:self.password forHTTPHeaderField:@"Cookie"]; + case AuthenticationMethodSAML_WEB_SSO: + [myRequest addValue:self.credDto.accessToken forHTTPHeaderField:@"Cookie"]; break; - case credentialOauth: - [myRequest addValue:[NSString stringWithFormat:@"Bearer %@", self.password] forHTTPHeaderField:@"Authorization"]; + case AuthenticationMethodBEARER_TOKEN: + [myRequest addValue:[NSString stringWithFormat:@"Bearer %@", self.credDto.accessToken] forHTTPHeaderField:@"Authorization"]; break; default: break; @@ -223,18 +221,19 @@ - (id) getRequestWithCredentials:(id) request { } else if([request isKindOfClass:[OCWebDAVClient class]]) { OCWebDAVClient *myRequest = (OCWebDAVClient *)request; - switch (self.kindOfCredential) { - case credentialNotSet: + switch (self.credDto.authenticationMethod) { + case AuthenticationMethodNONE: + case AuthenticationMethodUNKNOWN: //Without credentials break; - case credentialNormal: - [myRequest setAuthorizationHeaderWithUsername:self.user password:self.password]; + case AuthenticationMethodBASIC_HTTP_AUTH: + [myRequest setAuthorizationHeaderWithUsername:self.credDto.userName password:self.credDto.accessToken]; break; - case credentialCookie: - [myRequest setAuthorizationHeaderWithCookie:self.password]; + case AuthenticationMethodSAML_WEB_SSO: + [myRequest setAuthorizationHeaderWithCookie:self.credDto.accessToken]; break; - case credentialOauth: - [myRequest setAuthorizationHeaderWithToken:[NSString stringWithFormat:@"Bearer %@", self.password]]; + case AuthenticationMethodBEARER_TOKEN: + [myRequest setAuthorizationHeaderWithToken:[NSString stringWithFormat:@"Bearer %@", self.credDto.accessToken]]; break; default: break; @@ -244,7 +243,7 @@ - (id) getRequestWithCredentials:(id) request { [myRequest setUserAgent:self.userAgent]; } - return request; + return myRequest; } else { NSLog(@"We do not know witch kind of object is"); @@ -628,6 +627,71 @@ - (void) getServerVersionWithPath:(NSString*) path onCommunication:(OCCommunicat } + +///----------------------------------- +/// @name Get UserData +///----------------------------------- + +- (void) getUserDataOfServer:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication + success:(void(^)(NSHTTPURLResponse *response, NSData *responseData, NSString *redirectedServer))success + failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest { + + OCWebDAVClient *request = [OCWebDAVClient new]; + request = [self getRequestWithCredentials:request]; + + + [request requestUserDataOfServer:path onCommunication:sharedOCCommunication + success:^(NSHTTPURLResponse *response, id responseObject) { + success(response, responseObject, request.redirectedServer); + } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) { + failureRequest(response,error, request.redirectedServer); + }]; +} + +///----------------------------------- +/// @name Get User Display Name +///----------------------------------- + +- (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 { + + OCWebDAVClient *request = [OCWebDAVClient new]; + request = [self getRequestWithCredentials:request]; + + [request requestUserDataOfServer:path onCommunication:sharedOCCommunication + success:^(NSHTTPURLResponse *response, id responseObject) { + + NSError *jsonError = nil; + NSString *displayName = @""; + + NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:responseObject options:kNilOptions error:&jsonError]; + + if (jsonError) { + + NSLog(@"json error: %@", jsonError); + } else { + + NSDictionary *ocsDict = [jsonDict objectForKey:k_json_ocs]; + + NSDictionary *userDataDict = [ocsDict objectForKey:k_json_ocs_data]; + + displayName = [userDataDict objectForKey:k_json_ocs_data_display_name]; + } + + for(NSString *key in [jsonDict allKeys]) { + NSLog(@"%@",[jsonDict objectForKey:key]); + } + + success(response, displayName, request.redirectedServer); + + } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) { + failureRequest(response,error, request.redirectedServer); + NSLog(@"Display name not updated"); + }]; +} + + ///----------------------------------- /// @name Get UserName by cookie ///----------------------------------- @@ -1413,7 +1477,7 @@ - (NSURLSessionTask *) getRemoteThumbnailByServer:(NSString*)serverPath ofFilePa request = [self getRequestWithCredentials:request]; - OCHTTPRequestOperation *operation = [request getRemoteThumbnailByServer:serverPath ofFilePath:filePath withWidth:fileWidth andHeight:fileHeight onCommunication:sharedOCComunication + NSURLSessionDataTask *sessionDataTask = [request getRemoteThumbnailByServer:serverPath ofFilePath:filePath withWidth:fileWidth andHeight:fileHeight onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) { NSData *responseData = (NSData*) responseObject; @@ -1423,9 +1487,9 @@ - (NSURLSessionTask *) getRemoteThumbnailByServer:(NSString*)serverPath ofFilePa failureRequest(response, error, request.redirectedServer); }]; - [operation resume]; + [sessionDataTask resume]; - return operation; + return sessionDataTask; } #pragma mark - Clear Cache diff --git a/OCCommunicationLib/OCCommunicationLib/OCCredentialsDto.h b/OCCommunicationLib/OCCommunicationLib/OCCredentialsDto.h new file mode 100644 index 00000000..4df82de2 --- /dev/null +++ b/OCCommunicationLib/OCCommunicationLib/OCCredentialsDto.h @@ -0,0 +1,58 @@ +// +// OCCredentialsDto.h +// ownCloud iOS library +// +// Created by Noelia Alvarez on 27/10/14. +// +// Copyright (C) 2017, ownCloud GmbH. ( http://www.owncloud.org/ ) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// + +#import + +typedef NS_ENUM (NSUInteger, AuthenticationMethod){ + AuthenticationMethodUNKNOWN = 0, + AuthenticationMethodNONE = 1, + AuthenticationMethodBASIC_HTTP_AUTH = 2, + AuthenticationMethodBEARER_TOKEN = 3, + AuthenticationMethodSAML_WEB_SSO = 4, +}; + +@interface OCCredentialsDto : NSObject + +@property (nonatomic, copy) NSString *userId; +@property (nonatomic, copy) NSString *baseURL; +@property (nonatomic, copy) NSString *userName; +@property (nonatomic, copy) NSString *accessToken; // password for basic auth, cookies for SAML, access token for OAuth2... +@property (nonatomic) AuthenticationMethod authenticationMethod; + +//optionals credentials used with oauth2 +@property (nonatomic, copy) NSString *refreshToken; +@property (nonatomic, copy) NSString *expiresIn; +@property (nonatomic, copy) NSString *tokenType; + +@property (nonatomic, copy) NSString *userDisplayName; + + +- (void)encodeWithCoder:(NSCoder *)aCoder; +- (id)initWithCoder:(NSCoder *)aDecoder; + +@end diff --git a/OCCommunicationLib/OCCommunicationLib/OCCredentialsDto.m b/OCCommunicationLib/OCCommunicationLib/OCCredentialsDto.m new file mode 100644 index 00000000..764b7b7f --- /dev/null +++ b/OCCommunicationLib/OCCommunicationLib/OCCredentialsDto.m @@ -0,0 +1,105 @@ +// +// OCCredentialsDto.m +// ownCloud iOS library +// +// Created by Noelia Alvarez on 27/10/14. +// +// Copyright (C) 2017, ownCloud GmbH. ( http://www.owncloud.org/ ) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "OCCredentialsDto.h" + +@implementation OCCredentialsDto + +- (id)initWithCredentialsDto:(OCCredentialsDto *)oCredDto{ + + self = [super init]; + if (self) { + // Custom initialization + _userId = oCredDto.userId; + _baseURL = oCredDto.baseURL; + _userName = oCredDto.userName; + _accessToken = oCredDto.accessToken; + _refreshToken = oCredDto.refreshToken; + _expiresIn = oCredDto.expiresIn; + _tokenType = oCredDto.tokenType; + _authenticationMethod = oCredDto.authenticationMethod; + _userDisplayName = oCredDto.userDisplayName; + } + + return self; +} + + +#pragma mark - NSCopying + +-(id) copyWithZone:(NSZone *)zone { + OCCredentialsDto *credDtoCopy = [[OCCredentialsDto alloc]init]; + credDtoCopy.userId = self.userId; + credDtoCopy.baseURL = self.baseURL; + credDtoCopy.userName = self.userName; + credDtoCopy.accessToken = self.accessToken; + credDtoCopy.refreshToken = self.refreshToken; + credDtoCopy.expiresIn = self.expiresIn; + credDtoCopy.tokenType = self.tokenType; + credDtoCopy.authenticationMethod = self.authenticationMethod; + credDtoCopy.userDisplayName = self.userDisplayName; + + return credDtoCopy; +} + +#pragma mark - NSSecureCoding + ++ (BOOL)supportsSecureCoding { + return YES; +} + +- (void)encodeWithCoder:(NSCoder *)aCoder +{ + [aCoder encodeObject:self.userId forKey:@"userId"]; + [aCoder encodeObject:self.baseURL forKey:@"baseURL"]; + [aCoder encodeObject:self.userName forKey:@"userName"]; + [aCoder encodeObject:self.accessToken forKey:@"accessToken"]; + [aCoder encodeObject:self.refreshToken forKey:@"refreshToken"]; + [aCoder encodeObject:self.expiresIn forKey:@"expiresIn"]; + [aCoder encodeObject:self.tokenType forKey:@"tokenType"]; + [aCoder encodeInteger:self.authenticationMethod forKey:@"authenticationMethod"]; + [aCoder encodeObject:self.userDisplayName forKey:@"userDisplayName"]; +} + +- (instancetype)initWithCoder:(NSCoder *)aDecoder +{ + if (self = [super init]) { + self.userId = [aDecoder decodeObjectForKey:@"userId"]; + self.baseURL = [aDecoder decodeObjectForKey:@"baseURL"]; + self.userName = [aDecoder decodeObjectForKey:@"userName"]; + self.accessToken = [aDecoder decodeObjectForKey:@"accessToken"]; + self.refreshToken = [aDecoder decodeObjectForKey:@"refreshToken"]; + self.expiresIn = [aDecoder decodeObjectForKey:@"tokenType"]; + self.tokenType = [aDecoder decodeObjectForKey:@"tokenType"]; + self.authenticationMethod = [aDecoder decodeIntegerForKey:@"authenticationMethod"]; + self.userDisplayName = [aDecoder decodeObjectForKey:@"userDisplayName"]; + + } + return self; +} + +@end diff --git a/OCCommunicationLib/OCCommunicationLib/OCErrorMsg.h b/OCCommunicationLib/OCCommunicationLib/OCErrorMsg.h index 435a8322..afea6383 100644 --- a/OCCommunicationLib/OCCommunicationLib/OCErrorMsg.h +++ b/OCCommunicationLib/OCCommunicationLib/OCErrorMsg.h @@ -24,14 +24,17 @@ // +#define kOCErrorServerBadRequest 400 #define kOCErrorServerUnauthorized 401 -//In the server we received a 403 also when the server is enforce to set a password. #define kOCErrorServerForbidden 403 #define kOCErrorServerPathNotFound 404 #define kOCErrorServerMethodNotPermitted 405 #define kOCErrorProxyAuth 407 #define kOCErrorServerTimeout 408 +#define kOCErrorServerConflict 409 #define kOCErrorServerInternalError 500 +#define kOCErrorServerNotImplemented 501 +#define kOCErrorServerBadGateway 502 #define kOCErrorServerMaintenanceError 503 #define kOCErrorServerInsufficientStorage 507 diff --git a/OCCommunicationLib/OCCommunicationLib/OCFrameworkConstants.h b/OCCommunicationLib/OCCommunicationLib/OCFrameworkConstants.h index 7abafaf7..c640d781 100644 --- a/OCCommunicationLib/OCCommunicationLib/OCFrameworkConstants.h +++ b/OCCommunicationLib/OCCommunicationLib/OCFrameworkConstants.h @@ -37,6 +37,20 @@ #define k_domain_error_code @"com.owncloud" +//URL for webdav +//#define k_url_webdav_server @"remote.php/odav/" +#define k_url_webdav_server @"remote.php/webdav/" +#define k_url_webdav_server_without_last_slash @"remote.php/webdav" + +//URL path for list of files in web interface +#define k_url_path_list_of_files_in_web @"index.php/apps/files" + +//URL to access user data API +#define k_api_user_url_json @"ocs/v1.php/cloud/user?format=json" +#define k_json_ocs @"ocs" +#define k_json_ocs_data @"data" +#define k_json_ocs_data_display_name @"display-name" + //Url to access to Shared API to create #define k_url_acces_shared_api @"ocs/v1.php/apps/files_sharing/api/v1/shares" diff --git a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCHTTPRequestOperation.h b/OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCCredentialsStorage.h similarity index 76% rename from OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCHTTPRequestOperation.h rename to OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCCredentialsStorage.h index 986f1408..e6493b3e 100644 --- a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCHTTPRequestOperation.h +++ b/OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCCredentialsStorage.h @@ -1,8 +1,10 @@ // -// OCHTTPRequestOperation.h -// Owncloud iOs Client +// OCCredentialsStorage.h +// ownCloud iOS library // -// Copyright (C) 2016, ownCloud GmbH. ( http://www.owncloud.org/ ) +// Created by Noelia Alvarez on 30/08/2017. +// +// Copyright (C) 2017, ownCloud GmbH. ( http://www.owncloud.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -23,11 +25,13 @@ // THE SOFTWARE. // +#import -@interface OCHTTPRequestOperation : NSURLSessionDataTask +@class OCCredentialsDto; -@property (nonatomic, strong) NSString *localSource; +@protocol OCCredentialsStorageDelegate +- (void)saveCredentials:(OCCredentialsDto *)credDto; @end diff --git a/OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCOAuth2Configuration.h b/OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCOAuth2Configuration.h new file mode 100644 index 00000000..1a5a6440 --- /dev/null +++ b/OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCOAuth2Configuration.h @@ -0,0 +1,40 @@ +// +// OCOAuth2Configuration.h +// ownCloud iOS library +// +// Created by Noelia Alvarez on 28/08/2017. +// +// Copyright (C) 2017, ownCloud GmbH. ( http://www.owncloud.org/ ) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import + +@interface OCOAuth2Configuration : NSObject + +@property (nonatomic, copy) NSString *clientId; +@property (nonatomic, copy) NSString *clientSecret; +@property (nonatomic, copy) NSString *redirectUri; +@property (nonatomic, copy) NSString *authorizationEndpoint; +@property (nonatomic, copy) NSString *tokenEndpoint; + +- (id)initWithClientId:(NSString *)clientId clientSecret:(NSString *)clientSecret redirectUri:(NSString *)redirectUri authorizationEndpoint:(NSString *)authorizationEndpoint tokenEndpoint:(NSString *)tokenEndpoint; + +@end diff --git a/OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCOAuth2Configuration.m b/OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCOAuth2Configuration.m new file mode 100644 index 00000000..0d1ad210 --- /dev/null +++ b/OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCOAuth2Configuration.m @@ -0,0 +1,47 @@ +// +// OCOAuth2Configuration.m +// ownCloud iOS library +// +// Created by Noelia Alvarez on 28/08/2017. +// +// Copyright (C) 2017, ownCloud GmbH. ( http://www.owncloud.org/ ) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "OCOAuth2Configuration.h" + +@implementation OCOAuth2Configuration + + +- (id)initWithClientId:(NSString *)clientId clientSecret:(NSString *)clientSecret redirectUri:(NSString *)redirectUri authorizationEndpoint:(NSString *)authorizationEndpoint tokenEndpoint:(NSString *)tokenEndpoint { + + self = [super init]; + if (self) { + // Custom initialization + _clientId = clientId; + _clientSecret = clientSecret; + _redirectUri = redirectUri; + _authorizationEndpoint = authorizationEndpoint; + _tokenEndpoint = tokenEndpoint; + } + return self; +} + +@end diff --git a/OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCOAuth2Manager.h b/OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCOAuth2Manager.h new file mode 100644 index 00000000..9ee05e4f --- /dev/null +++ b/OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCOAuth2Manager.h @@ -0,0 +1,85 @@ +// +// OCOAuth2Manager.h +// ownCloud iOS library +// +// Created by Noelia Alvarez on 28/08/2017. +// +// Copyright (C) 2017, ownCloud GmbH. ( http://www.owncloud.org/ ) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import +#import "OCCredentialsDto.h" +#import "OCCommunication.h" +#import "OCOAuth2Configuration.h" +#import "UtilsFramework.h" +#import "OCFrameworkConstants.h" +#import "OCCredentialsDto.h" +#import "OCTrustedCertificatesStore.h" + + +@interface OCOAuth2Manager : NSObject + + +@property (nonatomic, strong) id trustedCertificatesStore; + + +- (NSURL *) getOAuth2URLToGetAuthCodeByOAuth2Configuration:(OCOAuth2Configuration *)oauth2Configuration + withServerPath:(NSString *)serverPath; + + +/** + * Method to get the auth data by the auth code + * + * @param baseURL -> NSString with the url of the path obteined from method getOAuth2URLToGetTokenByOAuth2Configuration:withServerPath: + * @param oauth2Configuration -> OCOAuth2Configuration with all the oauth parameters + * @param authCode -> NSString with the auth code + * @param userAgent -> NSString with the custom user agent or nil + * + **/ + +- (void) authDataByOAuth2Configuration:(OCOAuth2Configuration *)oauth2Configuration + withBaseURL:(NSString *)baseURL + authCode:(NSString *)authCode + userAgent:(NSString *)userAgent + withCompletion:(void(^)(OCCredentialsDto *userCredDto, NSError *error))completion; + +/** + * Method to get the new auth data by the oauth refresh token + * + * @param baseURL -> NSString with the url of the path + * Ex: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Music + * + * @param refreshToken -> NSString with the refreshToken + * @param oauth2Configuration -> OCOAuth2Configuration with all the oauth parameters + * @param userAgent -> NSString with the custom user agent or nil + * +**/ + +- (void) refreshAuthDataByOAuth2Configuration:(OCOAuth2Configuration *)oauth2Configuration + withBaseURL:(NSString *)baseURL + refreshToken:(NSString *)refreshToken + userAgent:(NSString *)userAgent + success:(void(^)(OCCredentialsDto *userCredDto))success + failure:(void(^)(NSError *error))failure; + + + +@end diff --git a/OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCOAuth2Manager.m b/OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCOAuth2Manager.m new file mode 100644 index 00000000..88bbf653 --- /dev/null +++ b/OCCommunicationLib/OCCommunicationLib/OCOAuth2Authentication/OCOAuth2Manager.m @@ -0,0 +1,333 @@ +// +// OCOAuth2Manager.m +// ownCloud iOS library +// +// Created by Noelia Alvarez on 28/08/2017. +// +// Copyright (C) 2017, ownCloud GmbH. ( http://www.owncloud.org/ ) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "OCOAuth2Manager.h" + +@implementation OCOAuth2Manager + + + +- (NSURL *) getOAuth2URLToGetAuthCodeByOAuth2Configuration:(OCOAuth2Configuration *)oauth2Configuration + withServerPath:(NSString *)serverPath { + + NSString *baseURL = [NSString stringWithFormat:@"%@%@",serverPath,oauth2Configuration.authorizationEndpoint]; + + NSURLComponents *urlComponents = [[NSURLComponents alloc] initWithString:baseURL]; + NSDictionary *queryDictionary = @{ + @"response_type" : @"code", + @"redirect_uri" : oauth2Configuration.redirectUri, + @"client_id" : oauth2Configuration.clientId + }; + NSMutableArray *queryItems = [NSMutableArray array]; + for (NSString *key in queryDictionary) { + [queryItems addObject:[NSURLQueryItem queryItemWithName:key value:queryDictionary[key]]]; + } + urlComponents.queryItems = queryItems; + NSURL *fullOauthURL = urlComponents.URL; + + return fullOauthURL; +} + ++ (NSURL *) getOAuth2URLToGetTokenByOAuth2Configuration:(OCOAuth2Configuration *)oauth2Configuration + withServerPath:(NSString *)serverPath { + + NSURL *serverPathURL = [[NSURL URLWithString:serverPath] URLByAppendingPathComponent:oauth2Configuration.tokenEndpoint]; + NSURLComponents *urlComponents = [[NSURLComponents alloc] initWithString:serverPathURL.absoluteString]; + + NSURL *fullOAuthURL = urlComponents.URL; + + return fullOAuthURL; +} + + +#pragma mark - access token + +- (void) authDataByOAuth2Configuration:(OCOAuth2Configuration *)oauth2Configuration + withBaseURL:(NSString *)baseURL + authCode:(NSString *)authCode + userAgent:(NSString *)userAgent + withCompletion:(void(^)(OCCredentialsDto *userCredDto, NSError *error))completion { + + NSURL *urlToGetAuthData = [OCOAuth2Manager getOAuth2URLToGetTokenByOAuth2Configuration:oauth2Configuration withServerPath:baseURL]; + + [self authDataRequestByOAuth2Configuration:oauth2Configuration withURL:urlToGetAuthData authCode:authCode userAgent:userAgent withCompletion:^(NSData *data, NSHTTPURLResponse *httpResponse, NSError *error) { + + OCCredentialsDto *returnUserCredentials = nil; + NSError *returnError = nil; + + if (error != nil) { + returnError = error; + } else if (httpResponse != nil && (httpResponse.statusCode <200 || httpResponse.statusCode >= 300)) { + // errored HTTP response from server + returnError = [UtilsFramework getErrorByCodeId:OCErrorOAuth2Error]; //TODO: custom error message + } else if (httpResponse == nil || data == nil) { + // generic OAuth2 error, who knows what happened... + returnError = [UtilsFramework getErrorByCodeId:OCErrorOAuth2Error]; + + } else { + NSDictionary *dictJSON = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]; + if (dictJSON != nil ) { + NSString *errorInJSON = [dictJSON objectForKey:@"error"]; + if (errorInJSON) { + if ([errorInJSON isEqualToString:@"access_denied"]) { + returnError = [UtilsFramework getErrorByCodeId:OCErrorOAuth2ErrorAccessDenied]; + } else { + returnError = [UtilsFramework getErrorByCodeId:OCErrorOAuth2Error]; + } + } else { + returnUserCredentials = [[OCCredentialsDto alloc] init]; + returnUserCredentials.userName = [dictJSON objectForKey:@"user_id"]; + returnUserCredentials.accessToken = [dictJSON objectForKey:@"access_token"]; + returnUserCredentials.refreshToken = [dictJSON objectForKey:@"refresh_token"]; + returnUserCredentials.expiresIn = [dictJSON objectForKey:@"expires_in"]; + returnUserCredentials.tokenType = [dictJSON objectForKey:@"token_type"]; + returnUserCredentials.authenticationMethod = AuthenticationMethodBEARER_TOKEN; + } + } else { + returnError = [UtilsFramework getErrorByCodeId:OCErrorOAuth2Error]; + } + } + + completion(returnUserCredentials,returnError); + + }]; + +} + +- (void) authDataRequestByOAuth2Configuration:(OCOAuth2Configuration *)oauth2Configuration + withURL:(NSURL *)url + authCode:(NSString *)authCode + userAgent:(NSString *)userAgent + withCompletion:(void(^)(NSData *data,NSHTTPURLResponse *httpResponse, NSError *error))completion { + + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + + request = [UtilsFramework getRequestWithCookiesByRequest:request andOriginalUrlServer:url.absoluteString]; + + [request setHTTPMethod:@"POST"]; + if (userAgent != nil) { + [request setValue:userAgent forHTTPHeaderField:@"User-Agent"]; + } + + [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; + + NSString *authId = [NSString stringWithFormat:@"%@:%@",oauth2Configuration.clientId,oauth2Configuration.clientSecret]; + NSString *base64EncodedAuthId = [UtilsFramework AFBase64EncodedStringFromString:authId]; + NSString *authorizationValue = [NSString stringWithFormat:@"Basic %@",base64EncodedAuthId]; + [request setValue:authorizationValue forHTTPHeaderField:@"Authorization"]; + + + NSString *body = [NSString stringWithFormat:@"grant_type=authorization_code&code=%@&redirect_uri=%@&client_id=%@", + authCode, + oauth2Configuration.redirectUri, + oauth2Configuration.clientId + ]; + + [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]]; + + NSURLSession *session = nil; + + session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]]; + + NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + + if (error != nil) { + NSLog(@"Error %@",error.localizedDescription); + completion(data, nil, error); + + } else { + completion(data, (NSHTTPURLResponse*)response, error); + } + }]; + + [task resume]; + +} + + +#pragma mark - Refresh token + +- (void) refreshAuthDataByOAuth2Configuration:(OCOAuth2Configuration *)oauth2Configuration + withBaseURL:(NSString *)baseURL + refreshToken:(NSString *)refreshToken + userAgent:(NSString *)userAgent + success:(void(^)(OCCredentialsDto *userCredDto))success + failure:(void(^)(NSError *error))failure { + + //[UtilsFramework deleteAllCookies]; + + [self refreshAuthDataRequestByOAuth2Configuration:oauth2Configuration withBaseURL:baseURL refreshToken:refreshToken userAgent:userAgent + + success:^(NSHTTPURLResponse *response, NSError *error, NSData *data) { + + NSDictionary *dictJSON; + OCCredentialsDto *userCredDto = [OCCredentialsDto new]; + + if (data != nil) { + + NSError *errorJSON = nil; + NSLog(@"data = %@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); + dictJSON = [NSJSONSerialization JSONObjectWithData:data + options:kNilOptions + error:&errorJSON]; + if (errorJSON == nil) { + if (dictJSON[@"user_id"] != nil && + dictJSON[@"access_token"] != nil && + dictJSON[@"refresh_token"] != nil ) { + + userCredDto.userName = dictJSON[@"user_id"]; + userCredDto.accessToken = dictJSON[@"access_token"]; + userCredDto.refreshToken = dictJSON[@"refresh_token"]; + userCredDto.expiresIn = dictJSON[@"expires_in"]; + userCredDto.tokenType = dictJSON[@"token_type"]; + userCredDto.authenticationMethod = AuthenticationMethodBEARER_TOKEN; + + success(userCredDto); + + } else { + + NSError *error = [UtilsFramework getErrorByCodeId:OCErrorOAuth2Error]; + + failure(error); + } + } + + } else { + failure(error); + } + + } failure:^(NSHTTPURLResponse *response, NSError *error) { + failure(error); + }]; + +} + +- (void) refreshAuthDataRequestByOAuth2Configuration:(OCOAuth2Configuration *)oauth2Configuration + withBaseURL:(NSString *)baseURL + refreshToken:(NSString *)refreshToken + userAgent:(NSString *)userAgent + success:(void(^)(NSHTTPURLResponse *response, NSError *error, NSData *data))success + failure:(void(^)(NSHTTPURLResponse *response, NSError *error))failure { + + + NSURL *urlToGetToken = [[NSURL URLWithString:baseURL] URLByAppendingPathComponent:oauth2Configuration.tokenEndpoint]; + + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlToGetToken]; + + request = [UtilsFramework getRequestWithCookiesByRequest:request andOriginalUrlServer:baseURL]; + + [request setHTTPMethod:@"POST"]; + if (userAgent != nil) { + [request setValue:userAgent forHTTPHeaderField:@"User-Agent"]; + } + + [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; + + NSString *authId = [NSString stringWithFormat:@"%@:%@",oauth2Configuration.clientId,oauth2Configuration.clientSecret]; + NSString *base64EncodedAuthId = [UtilsFramework AFBase64EncodedStringFromString:authId]; + NSString *authorizationValue = [NSString stringWithFormat:@"Basic %@",base64EncodedAuthId]; + [request setValue:authorizationValue forHTTPHeaderField:@"Authorization"]; + + NSString *body = [NSString stringWithFormat:@"grant_type=refresh_token&client_id=%@&refresh_token=%@",oauth2Configuration.clientId,refreshToken]; + + [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]]; + + NSURLSession *session = nil; + + session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]]; + + NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + + if (data != nil) { + success((NSHTTPURLResponse*)response, error, data); + } else { + NSLog(@"Error %@",error.localizedDescription); + failure((NSHTTPURLResponse*)response, error); + } + }]; + + [task resume]; +} + + +#pragma mark - methods from NSURLSessionDelegate + +// Delegate method called when the server responded with an authentication challenge. +// Since iOS is so great, it is also called when the server certificate is not trusted, so that the client +// can decide what to do about it. +// +// In this case we only expect to receive an authentication challenge if the server holds a certificate signed +// by an authority that is not trusted by iOS system. In this case, we need to check the list of certificates +// that were explicitly accepted by the user before, and allow the request to go on if the current one matches +// one of them (and not in other case). +// + +- (void) URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler { + + // For the case that the call is due to server certificate not trusted by iOS, we compare the certificate in the + // authentication challenge with the certificates that were previously accepted by the user in the OC app. If + // it match any of them, we allow to go on. + + if (self.trustedCertificatesStore != nil && [self.trustedCertificatesStore isTrustedServerCertificateIn:challenge]) { + // trusted + NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; + completionHandler(NSURLSessionAuthChallengeUseCredential,credential); + } else { + // If this method was called due to untrusted server certificate and this was not accepted by the user before, + // or if it was called due to a different authentication challenge, default handling will lead the task to fail. + completionHandler(NSURLSessionAuthChallengePerformDefaultHandling,nil); + } +} + + +/// MARK : methods from NSURLSessionTaskDelegate + +// Delegate method called when the server responsed with a redirection +// +// In this case we need to grant that redirections are just followed, but not with the request proposed by the system. +// The requests to access token endpoint are POSTs, and iOS proposes GETs for the redirections +// + +- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task + willPerformHTTPRedirection:(NSHTTPURLResponse *)response + newRequest:(NSURLRequest *)request + completionHandler:(void (^)(NSURLRequest * _Nullable))completionHandler { + + NSLog(@"DetectAuthenticationMethod: redirect detected in URLSessionTaskDelegate implementation"); + + if (task.currentRequest) { + NSMutableURLRequest *newRequest = [task.currentRequest mutableCopy]; // let's resuse the last request performed by the task (it's a POST) ... + newRequest.URL = request.URL; // ... and then override the URL with the redirected one proposed by the system + + completionHandler(newRequest); //follow + } else { + completionHandler(nil); // we don't know where to redirect, something was really wrong -> stop + } +} + + +@end diff --git a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCHTTPRequestOperation.m b/OCCommunicationLib/OCCommunicationLib/OCTrustedCertificatesStore.h similarity index 60% rename from OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCHTTPRequestOperation.m rename to OCCommunicationLib/OCCommunicationLib/OCTrustedCertificatesStore.h index 5287739f..fdfe5d7a 100644 --- a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCHTTPRequestOperation.m +++ b/OCCommunicationLib/OCCommunicationLib/OCTrustedCertificatesStore.h @@ -1,8 +1,10 @@ // -// OCHTTPRequestOperation.m -// Owncloud iOs Client +// OCTrustedCertificatesStore.h +// ownCloud iOS library // -// Copyright (C) 2016, ownCloud GmbH. ( http://www.owncloud.org/ ) +// Created by David A. Velasco on 28/9/17. +// +// Copyright (C) 2017, ownCloud GmbH. ( http://www.owncloud.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -24,15 +26,23 @@ // -#import "OCHTTPRequestOperation.h" +#ifndef OCTrustedCertificatesStore_h +#define OCTrustedCertificatesStore_h -@interface OCHTTPRequestOperation () -@property (readwrite, nonatomic, strong) NSMutableURLRequest *request; -@end +#import +@protocol OCTrustedCertificatesStore -@implementation OCHTTPRequestOperation -@synthesize request; +/* + * Checks if the challenge passed as a parameter corresponds to server certificate not trusted by iOS system, + * and if it is trusted by the user anyway, searching for it in the app-level store of certificates that + * were previously approved by her. + */ +- (BOOL) isTrustedServerCertificateIn:(NSURLAuthenticationChallenge *) challenge; @end + +#endif /* OCTrustedCertificatesStore_h */ + + diff --git a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.h b/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.h index 299eb65b..429d04ff 100755 --- a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.h +++ b/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.h @@ -27,7 +27,6 @@ #import "AFHTTPSessionManager.h" -#import "OCHTTPRequestOperation.h" @class OCCommunication; @class OCChunkDto; @@ -207,6 +206,7 @@ extern NSString * _Nullable OCWebDAVModificationDateKey; @param localSource is a string with the path of the file to upload @param remoteDestination A remote path, relative to the HTTP client's base URL, to write the data to. + @param retryingNumberOfTimes The number of times that the request will be silently retry @param progress A progress object monitoring the current upload progress. @param success A block callback, to be fired upon successful completion, with NSURLResponse and string of redirected server. @param failure A block callback, to be fired upon the failure of either the request or the parsing of the request's data, with two arguments: the request operation and the network or parsing error that occurred. @@ -215,11 +215,29 @@ extern NSString * _Nullable OCWebDAVModificationDateKey; */ - (NSURLSessionUploadTask * _Nonnull)putWithSessionLocalPath:(NSString * _Nonnull)localSource atRemotePath:(NSString * _Nonnull)remoteDestination onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication progress:(void(^ _Nonnull)(NSProgress * _Nonnull progress))uploadProgress success:(void(^ _Nonnull)(NSURLResponse * _Nonnull, NSString * _Nonnull))success failure:(void(^ _Nonnull)(NSURLResponse * _Nonnull, id _Nonnull, NSError * _Nonnull))failure failureBeforeRequest:(void(^ _Nonnull)(NSError * _Nonnull)) failureBeforeRequest; + +///----------------------------------- +/// @name requestUserData +///----------------------------------- + +/** + * Method to obtain the User data of server + * + * + */ +- (void) requestUserDataOfServer:(NSString * _Nonnull) path + onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication + success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nonnull))success + failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nullable responseObject, NSError * _Nonnull))failure; + + ///----------------------------------- /// @name requestForUserNameByCookie ///----------------------------------- /** + * DEPRECATED use - requestUserDataOfServer:onCommunication: instead + * * Method to obtain the User name by the cookie of the session * * @param NSString the cookie of the session @@ -227,7 +245,8 @@ extern NSString * _Nullable OCWebDAVModificationDateKey; */ - (void) requestUserNameOfServer:(NSString * _Nonnull) path byCookie:(NSString * _Nonnull) cookieString onCommunication: (OCCommunication * _Nonnull)sharedOCCommunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nonnull))success - failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nullable responseObject, NSError * _Nonnull))failure; + failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nullable responseObject, NSError * _Nonnull))failure +__deprecated_msg("Use - requestUserDataOfServer:onCommunication: instead"); ///----------------------------------- @@ -322,7 +341,7 @@ extern NSString * _Nullable OCWebDAVModificationDateKey; ///----------------------------------- /** - * DEPRECATED use - shareFileOrFolderByServerPath:andPath:password:expirationTime:publicUpload:linkName:onCommunication instead + * DEPRECATED use - shareByLinkFileOrFolderByServer:andPath:password:expirationTime:publicUpload:linkName:permissions:onCommunication instead * * Method to share a file or folder with password * @@ -338,14 +357,14 @@ extern NSString * _Nullable OCWebDAVModificationDateKey; onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nonnull))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nullable responseObject, NSError * _Nonnull))failure -__deprecated_msg("Use - shareFileOrFolderByServerPath:andPath:password:expirationTime:publicUpload:linkName:onCommunication instead"); +__deprecated_msg("Use - shareByLinkFileOrFolderByServer:andPath:password:expirationTime:publicUpload:linkName:permissions:onCommunication instead"); ///----------------------------------- /// @name shareFileOrFolderByServer ///----------------------------------- /** - * DEPRECATED use - shareFileOrFolderByServerPath:andPath:password:expirationTime:publicUpload:linkName:onCommunication instead + * DEPRECATED use - shareByLinkFileOrFolderByServer:andPath:password:expirationTime:publicUpload:linkName:permissions:onCommunication instead * * Method to share a file or folder * @@ -360,7 +379,7 @@ __deprecated_msg("Use - shareFileOrFolderByServerPath:andPath:password:expiratio onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nonnull))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nullable responseObject, NSError * _Nonnull))failure -__deprecated_msg("Use - shareFileOrFolderByServerPath:andPath:password:expirationTime:publicUpload:linkName:onCommunication instead"); +__deprecated_msg("Use - shareByLinkFileOrFolderByServer:andPath:password:expirationTime:publicUpload:linkName:permissions:onCommunication instead"); ///----------------------------------- @@ -456,7 +475,7 @@ __deprecated_msg("Use - shareFileOrFolderByServerPath:andPath:password:expiratio ///----------------------------------- /** - * DEPRECATED use - updateShareItem:ofServerPath:withPasswordProtect:andExpirationTime:andPermissions:andLinkName:andLinkName:onCommunication: instead + * DEPRECATED use - updateShareItem:ofServerPath:withPasswordProtect:andExpirationTime:andPublicUpload:andLinkName:andPermissions:onCommunication: instead * * Method to update a share link * @@ -477,7 +496,7 @@ __deprecated_msg("Use - shareFileOrFolderByServerPath:andPath:password:expiratio onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull operation, id _Nullable responseObject, NSError * _Nonnull error))failure -__deprecated_msg("Use - updateShare:ofServerPath:withPasswordProtect:andExpirationTime:andPermissions:andLinkName:onCommunication: instead"); +__deprecated_msg("Use - updateShareItem:ofServerPath:withPasswordProtect:andExpirationTime:andPublicUpload:andLinkName:andPermissions:onCommunication: instead"); ///----------------------------------- /// @name searchUsersAndGroupsWith @@ -533,7 +552,7 @@ __deprecated_msg("Use - updateShare:ofServerPath:withPasswordProtect:andExpirati * @return nsData -> thumbnail of the file with the size requested * */ -- (OCHTTPRequestOperation * _Nonnull) getRemoteThumbnailByServer:(NSString * _Nonnull)serverPath ofFilePath:(NSString * _Nonnull)filePath withWidth:(NSInteger)fileWidth andHeight:(NSInteger)fileHeight onCommunication:(OCCommunication * _Nonnull)sharedOCComunication +- (NSURLSessionDataTask * _Nonnull) getRemoteThumbnailByServer:(NSString * _Nonnull)serverPath ofFilePath:(NSString * _Nonnull)filePath withWidth:(NSInteger)fileWidth andHeight:(NSInteger)fileHeight onCommunication:(OCCommunication * _Nonnull)sharedOCComunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull operation, id _Nullable responseObject, NSError * _Nonnull error))failure; diff --git a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m b/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m index dc20bdb2..a1f9bd4a 100755 --- a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m +++ b/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m @@ -34,12 +34,13 @@ #import "AFURLSessionManager.h" #import "NSString+Encode.h" #import "OCConstants.h" +#import "OCOAuth2Manager.h" -#define k_api_user_url_json @"ocs/v1.php/cloud/user?format=json" #define k_server_information_json @"status.php" #define k_api_header_request @"OCS-APIREQUEST" -#define k_group_sharee_type 1 +#define k_group_sharee_type 1 +#define k_retry_ntimes 2 //Retry ntimes request NSString const *OCWebDAVContentTypeKey = @"getcontenttype"; NSString const *OCWebDAVETagKey = @"getetag"; @@ -91,7 +92,9 @@ - (void)setUserAgent:(NSString *)userAgent{ [self.defaultHeaders setObject:userAgent forKey:@"User-Agent"]; } -- (OCHTTPRequestOperation *)mr_operationWithRequest:(NSMutableURLRequest *)request onCommunication:(OCCommunication *)sharedOCCommunication withUserSessionToken:(NSString*)token success:(void(^)(NSHTTPURLResponse *operation, id response, NSString *token))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error, NSString *token))failure { +#pragma mark - Main network operation token + +- (NSURLSessionDataTask *)mr_operationWithRequest:(NSMutableURLRequest *)request retryingNumberOfTimes:(NSInteger)ntimes onCommunication:(OCCommunication *)sharedOCCommunication withUserSessionToken:(NSString*)token success:(void(^)(NSHTTPURLResponse *operation, id response, NSString *token))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error, NSString *token))failure { //If is not nil is a redirection so we keep the original url server if (!self.originalUrlServer) { @@ -105,18 +108,68 @@ - (OCHTTPRequestOperation *)mr_operationWithRequest:(NSMutableURLRequest *)reque [UtilsFramework deleteAllCookies]; } - OCHTTPRequestOperation *operation = (OCHTTPRequestOperation*) [sharedOCCommunication.networkSessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { + __block NSURLSessionDataTask *sessionDataTask; + + sessionDataTask = [sharedOCCommunication.networkSessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { if (!error) { success((NSHTTPURLResponse*)response,responseObject, token); } else { - failure((NSHTTPURLResponse*)response, responseObject, error, token); + if (((NSHTTPURLResponse*)response).statusCode == 401 && + sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN) { + if (ntimes <= 0) { + if (failure) { + failure((NSHTTPURLResponse*)response, responseObject, error, token); + } + } else { + + //get refresh token + OCOAuth2Manager* oAuth2Manager = [OCOAuth2Manager new]; + oAuth2Manager.trustedCertificatesStore = sharedOCCommunication.trustedCertificatesStore; + [oAuth2Manager refreshAuthDataByOAuth2Configuration:sharedOCCommunication.oauth2Configuration + withBaseURL:sharedOCCommunication.credDto.baseURL + refreshToken:sharedOCCommunication.credDto.refreshToken + userAgent:sharedOCCommunication.userAgent + success:^(OCCredentialsDto *userCredDto) { + + //set and store new credentials + + userCredDto.userId = sharedOCCommunication.credDto.userId; + userCredDto.baseURL = sharedOCCommunication.credDto.baseURL; + userCredDto.userDisplayName = sharedOCCommunication.credDto.userDisplayName; + [sharedOCCommunication setCredentials:userCredDto]; + + [request setValue:[NSString stringWithFormat:@"Bearer %@", userCredDto.accessToken] forHTTPHeaderField:@"Authorization"]; + + + if (sharedOCCommunication.credentialsStorage != nil) { + [sharedOCCommunication.credentialsStorage saveCredentials:sharedOCCommunication.credDto]; + } + + sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:(ntimes -1) + onCommunication:sharedOCCommunication + withUserSessionToken:token + success:success + failure:failure + ]; + [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; + [sessionDataTask resume]; + + } failure:^(NSError *error) { + failure(nil, nil, error, nil); + + }]; + } + } else { + failure((NSHTTPURLResponse*)response, responseObject, error, token); + } } }]; - return operation; + return sessionDataTask; } -- (OCHTTPRequestOperation *)mr_operationWithRequest:(NSMutableURLRequest *)request onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *, id))success failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure { +#pragma mark - Main network operation +- (NSURLSessionDataTask *)mr_operationWithRequest:(NSMutableURLRequest *)request retryingNumberOfTimes:(NSInteger)ntimes onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *, id))success failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure { //If is not nil is a redirection so we keep the original url server if (!self.originalUrlServer) { @@ -130,17 +183,61 @@ - (OCHTTPRequestOperation *)mr_operationWithRequest:(NSMutableURLRequest *)reque [UtilsFramework deleteAllCookies]; } + __block NSURLSessionDataTask *sessionDataTask; - OCHTTPRequestOperation *operation = (OCHTTPRequestOperation*) [sharedOCCommunication.networkSessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { - if (!error) { + sessionDataTask = [sharedOCCommunication.networkSessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { + if (!error) { success((NSHTTPURLResponse*)response,responseObject); } else { - failure((NSHTTPURLResponse*)response, responseObject, error); + + if (((NSHTTPURLResponse*)response).statusCode == 401 && sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN) { + if (ntimes <= 0) { + if (failure) { + failure((NSHTTPURLResponse*)response, responseObject, error); + } + } else { + + //get refresh token + OCOAuth2Manager* oAuth2Manager = [OCOAuth2Manager new]; + oAuth2Manager.trustedCertificatesStore = sharedOCCommunication.trustedCertificatesStore; + [oAuth2Manager refreshAuthDataByOAuth2Configuration:sharedOCCommunication.oauth2Configuration + withBaseURL:sharedOCCommunication.credDto.baseURL + refreshToken:sharedOCCommunication.credDto.refreshToken + userAgent:sharedOCCommunication.userAgent + success:^(OCCredentialsDto *userCredDto) { + + //set and store new credentials + + userCredDto.userId = sharedOCCommunication.credDto.userId; + userCredDto.baseURL = sharedOCCommunication.credDto.baseURL; + userCredDto.userDisplayName = sharedOCCommunication.credDto.userDisplayName; + [sharedOCCommunication setCredentials:userCredDto]; + [request setValue:[NSString stringWithFormat:@"Bearer %@", userCredDto.accessToken] forHTTPHeaderField:@"Authorization"]; + + if (sharedOCCommunication.credentialsStorage != nil) { + [sharedOCCommunication.credentialsStorage saveCredentials:sharedOCCommunication.credDto]; + } + + sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:(ntimes - 1) + onCommunication:sharedOCCommunication + success:success + failure:failure + ]; + [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; + [sessionDataTask resume]; + + } failure:^(NSError *error) { + failure(nil,nil,error); + }]; + } + } else { + failure((NSHTTPURLResponse*)response, responseObject, error); + + } } }]; - return operation; - + return sessionDataTask; } - (NSMutableURLRequest *)requestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters { @@ -181,9 +278,9 @@ - (void)movePath:(NSString *)source toPath:(NSString *)destination NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:source parameters:nil]; [request setValue:destination forHTTPHeaderField:@"Destination"]; [request setValue:@"T" forHTTPHeaderField:@"Overwrite"]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } - (void)deletePath:(NSString *)path @@ -193,9 +290,9 @@ - (void)deletePath:(NSString *)path _requestMethod = @"DELETE"; NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } @@ -220,9 +317,9 @@ - (void)mr_listPath:(NSString *)path depth:(NSUInteger)depth onCommunication: [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } - (void)mr_listPath:(NSString *)path depth:(NSUInteger)depth withUserSessionToken:(NSString*)token onCommunication: @@ -246,9 +343,9 @@ - (void)mr_listPath:(NSString *)path depth:(NSUInteger)depth withUserSessionToke [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication withUserSessionToken:token success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication withUserSessionToken:token success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } - (void)propertiesOfPath:(NSString *)path @@ -272,7 +369,97 @@ - (void)listPath:(NSString *)path [self mr_listPath:path depth:1 withUserSessionToken:token onCommunication:sharedOCCommunication success:success failure:failure]; } -- (NSURLSessionDownloadTask *)downloadWithSessionPath:(NSString *)remoteSource toPath:(NSString *)localDestination defaultPriority:(BOOL)defaultPriority onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))downloadProgress success:(void(^)(NSURLResponse *response, NSURL *filePath))success failure:(void(^)(NSURLResponse *response, NSError *error))failure{ + +#pragma mark - download requests + +- (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSMutableURLRequest *)request + toPath:(NSString *)localDestination + defaultPriority:(BOOL)defaultPriority + retryingNumberOfTimes:(NSInteger)ntimes + onCommunication:(OCCommunication *)sharedOCCommunication + progress:(void(^)(NSProgress *progress))downloadProgress + success:(void(^)(NSURLResponse *response, NSURL *filePath))success failure:(void(^)(NSURLResponse *response, NSError *error))failure { + + NSURL *localDestinationUrl = [NSURL fileURLWithPath:localDestination]; + + __block NSURLSessionDownloadTask *downloadTask = [sharedOCCommunication.downloadSessionManager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull progress) { + downloadProgress(progress); + } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) { + + if (((NSHTTPURLResponse*)response).statusCode == 401) { + return nil; + } else { + return localDestinationUrl; + } + } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) { + + if (!error) { + success(response,filePath); + } else { + if (((NSHTTPURLResponse*)response).statusCode == 401 && sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN) { + if (ntimes <= 0) { + if (failure) { + failure(response, error); + } + } else { + //get refresh token + OCOAuth2Manager* oAuth2Manager = [OCOAuth2Manager new]; + oAuth2Manager.trustedCertificatesStore = sharedOCCommunication.trustedCertificatesStore; + [oAuth2Manager refreshAuthDataByOAuth2Configuration:sharedOCCommunication.oauth2Configuration + withBaseURL:sharedOCCommunication.credDto.baseURL + refreshToken:sharedOCCommunication.credDto.refreshToken + userAgent:sharedOCCommunication.userAgent + success:^(OCCredentialsDto *userCredDto) { + + //set and store new credentials + + userCredDto.userId = sharedOCCommunication.credDto.userId; + userCredDto.baseURL = sharedOCCommunication.credDto.baseURL; + userCredDto.userDisplayName = sharedOCCommunication.credDto.userDisplayName; + [sharedOCCommunication setCredentials:userCredDto]; + + [request setValue:[NSString stringWithFormat:@"Bearer %@", userCredDto.accessToken] forHTTPHeaderField:@"Authorization"]; + + if (sharedOCCommunication.credentialsStorage != nil) { + [sharedOCCommunication.credentialsStorage saveCredentials:sharedOCCommunication.credDto]; + } + + downloadTask = [self downloadTaskWithRequest:request + toPath:localDestination + defaultPriority:defaultPriority + retryingNumberOfTimes:(ntimes -1) + onCommunication:sharedOCCommunication + progress:downloadProgress + success:success + failure:failure]; + + [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.downloadSessionManager]; + [downloadTask resume]; + + } failure:^(NSError *error) { + failure(response, error); + }]; + } + + + } else { + failure(response, error); + } + } + }]; + + return downloadTask; +} + + + +- (NSURLSessionDownloadTask *)downloadWithSessionPath:(NSString *)remoteSource + toPath:(NSString *)localDestination + defaultPriority:(BOOL)defaultPriority + onCommunication:(OCCommunication *)sharedOCCommunication + progress:(void(^)(NSProgress *progress))downloadProgress + success:(void(^)(NSURLResponse *response, NSURL *filePath))success + failure:(void(^)(NSURLResponse *response, NSError *error))failure { NSMutableURLRequest *request = [self requestWithMethod:@"GET" path:remoteSource parameters:nil]; @@ -284,30 +471,22 @@ - (NSURLSessionDownloadTask *)downloadWithSessionPath:(NSString *)remoteSource t //We add the cookies of that URL request = [UtilsFramework getRequestWithCookiesByRequest:request andOriginalUrlServer:self.originalUrlServer]; - NSURL *localDestinationUrl = [NSURL fileURLWithPath:localDestination]; - - NSURLSessionDownloadTask *downloadTask = [sharedOCCommunication.downloadSessionManager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull progress) { - downloadProgress(progress); - } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) { - return localDestinationUrl; - } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) { - if (error) { - failure(response, error); - } else { - success(response,filePath); - } - }]; - + NSURLSessionDownloadTask *downloadTask = [self downloadTaskWithRequest:request + toPath:localDestination + defaultPriority:defaultPriority + retryingNumberOfTimes:k_retry_ntimes + onCommunication:sharedOCCommunication + progress:downloadProgress + success:success + failure:failure]; + [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.downloadSessionManager]; - if (defaultPriority) { [downloadTask resume]; } - - return downloadTask; - + return downloadTask; } - (void)makeCollection:(NSString *)path onCommunication: @@ -316,12 +495,86 @@ - (void)makeCollection:(NSString *)path onCommunication: failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure { _requestMethod = @"MKCOL"; NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } -- (NSURLSessionUploadTask *)putWithSessionLocalPath:(NSString *)localSource atRemotePath:(NSString *)remoteDestination onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))uploadProgress success:(void(^)(NSURLResponse *, NSString *))success failure:(void(^)(NSURLResponse *, id, NSError *))failure failureBeforeRequest:(void(^)(NSError *)) failureBeforeRequest { +#pragma mark - upload requests + +- (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSMutableURLRequest *)request + fromFileURL:(NSURL *)fileURL + retryingNumberOfTimes:(NSInteger)ntimes + onCommunication:(OCCommunication *)sharedOCCommunication + progress:(void(^)(NSProgress *progress))uploadProgress + success:(void(^)(NSURLResponse *, NSString *))success + failure:(void(^)(NSURLResponse *, id, NSError *))failure { + + __block NSURLSessionUploadTask *uploadTask = [sharedOCCommunication.uploadSessionManager uploadTaskWithRequest:request fromFile:fileURL progress:^(NSProgress * _Nonnull progress) { + uploadProgress(progress); + } completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { + if (!error) { + success(response,responseObject); + } else { + if ( ((NSHTTPURLResponse*)response).statusCode == 401 && + sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN ){ + if (ntimes <= 0) { + if (failure) { + failure(response, responseObject, error); + } + } else { + //get refresh token + OCOAuth2Manager* oAuth2Manager = [OCOAuth2Manager new]; + oAuth2Manager.trustedCertificatesStore = sharedOCCommunication.trustedCertificatesStore; + [oAuth2Manager refreshAuthDataByOAuth2Configuration:sharedOCCommunication.oauth2Configuration + withBaseURL:sharedOCCommunication.credDto.baseURL + refreshToken:sharedOCCommunication.credDto.refreshToken + userAgent:sharedOCCommunication.userAgent + success:^(OCCredentialsDto *userCredDto) { + + //set and store new credentials + + userCredDto.userId = sharedOCCommunication.credDto.userId; + userCredDto.baseURL = sharedOCCommunication.credDto.baseURL; + userCredDto.userDisplayName = sharedOCCommunication.credDto.userDisplayName; + [sharedOCCommunication setCredentials:userCredDto]; + + [request setValue:[NSString stringWithFormat:@"Bearer %@", userCredDto.accessToken] forHTTPHeaderField:@"Authorization"]; + + if (sharedOCCommunication.credentialsStorage != nil) { + [sharedOCCommunication.credentialsStorage saveCredentials:sharedOCCommunication.credDto]; + } + + uploadTask = [self uploadTaskWithRequest:request + fromFileURL:fileURL + retryingNumberOfTimes:(ntimes -1) + onCommunication:sharedOCCommunication + progress:uploadProgress + success:success + failure:failure]; + [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.uploadSessionManager]; + [uploadTask resume]; + + } failure:^(NSError *error) { + failure(response, responseObject, error); + }]; + } + } else { + failure(response, responseObject, error); + } + } + }]; + + return uploadTask; +} + +- (NSURLSessionUploadTask *)putWithSessionLocalPath:(NSString *)localSource + atRemotePath:(NSString *)remoteDestination + onCommunication:(OCCommunication *)sharedOCCommunication + progress:(void(^)(NSProgress *progress))uploadProgress + success:(void(^)(NSURLResponse *, NSString *))success + failure:(void(^)(NSURLResponse *, id, NSError *))failure + failureBeforeRequest:(void(^)(NSError *)) failureBeforeRequest { NSFileManager *fileManager = [NSFileManager defaultManager]; @@ -357,39 +610,58 @@ - (NSURLSessionUploadTask *)putWithSessionLocalPath:(NSString *)localSource atRe sharedOCCommunication.uploadSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer]; - NSURLSessionUploadTask *uploadTask = [sharedOCCommunication.uploadSessionManager uploadTaskWithRequest:request fromFile:file progress:^(NSProgress * _Nonnull progress) { - uploadProgress(progress); - } completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { - if (error) { - failure(response, responseObject, error); - } else { - success(response,responseObject); - } - }]; + NSURLSessionUploadTask *uploadTask = [self uploadTaskWithRequest:request + fromFileURL:file + retryingNumberOfTimes:k_retry_ntimes + onCommunication:sharedOCCommunication + progress:uploadProgress + success:success + failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.uploadSessionManager]; [uploadTask resume]; + return uploadTask; } } -- (void) requestUserNameOfServer:(NSString * _Nonnull) path byCookie:(NSString * _Nonnull) cookieString onCommunication: -(OCCommunication * _Nonnull)sharedOCCommunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nonnull))success - failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nullable responseObject, NSError * _Nonnull))failure { + +- (void) requestUserDataOfServer:(NSString * _Nonnull) path + onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication + success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nonnull))success + failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nullable responseObject, NSError * _Nonnull))failure { NSString *apiUserUrl = nil; apiUserUrl = [NSString stringWithFormat:@"%@%@", path, k_api_user_url_json]; - NSLog(@"api user name call: %@", apiUserUrl); + _requestMethod = @"GET"; + + NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path: apiUserUrl parameters: nil]; + [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]; +} + + +- (void) requestUserNameOfServer:(NSString * _Nonnull) path + byCookie:(NSString * _Nonnull) cookieString + onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication + success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nonnull))success + failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nullable responseObject, NSError * _Nonnull))failure { + + NSString *apiUserUrl = nil; + apiUserUrl = [NSString stringWithFormat:@"%@%@", path, k_api_user_url_json]; _requestMethod = @"GET"; NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path: apiUserUrl parameters: nil]; [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } - (void) getStatusOfTheServer:(NSString *)serverPath onCommunication: @@ -404,9 +676,9 @@ - (void) getStatusOfTheServer:(NSString *)serverPath onCommunication: request.HTTPShouldHandleCookies = false; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } - (void)listSharedByServer:(NSString *)serverPath @@ -420,9 +692,9 @@ - (void)listSharedByServer:(NSString *)serverPath NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } - (void)listSharedByServer:(NSString *)serverPath andPath:(NSString *) path @@ -438,9 +710,9 @@ - (void)listSharedByServer:(NSString *)serverPath andPath:(NSString *) path NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } @@ -487,9 +759,9 @@ - (void)shareByLinkFileOrFolderByServer:(NSString * _Nonnull)serverPath [request setHTTPBody:[self.postStringForShare dataUsingEncoding:NSUTF8StringEncoding]]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } - (void)shareByLinkFileOrFolderByServer:(NSString *)serverPath andPath:(NSString *) filePath andPassword:(NSString *)password @@ -504,9 +776,9 @@ - (void)shareByLinkFileOrFolderByServer:(NSString *)serverPath andPath:(NSString _postStringForShare = [NSString stringWithFormat: @"path=%@&shareType=3&password=%@",filePath,password]; [request setHTTPBody:[_postStringForShare dataUsingEncoding:NSUTF8StringEncoding]]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } - (void)shareByLinkFileOrFolderByServer:(NSString *)serverPath andPath:(NSString *) filePath @@ -521,9 +793,9 @@ - (void)shareByLinkFileOrFolderByServer:(NSString *)serverPath andPath:(NSString _postStringForShare = [NSString stringWithFormat: @"path=%@&shareType=3",filePath]; [request setHTTPBody:[_postStringForShare dataUsingEncoding:NSUTF8StringEncoding]]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } - (void)shareWith:(NSString *)userOrGroup shareeType:(NSInteger)shareeType inServer:(NSString *) serverPath andPath:(NSString *) filePath andPermissions:(NSInteger) permissions onCommunication:(OCCommunication *)sharedOCCommunication @@ -538,9 +810,9 @@ - (void)shareWith:(NSString *)userOrGroup shareeType:(NSInteger)shareeType inSer self.postStringForShare = [NSString stringWithFormat: @"path=%@&shareType=%ld&shareWith=%@&permissions=%ld",filePath, (long)shareeType, userOrGroup, (long)permissions]; [request setHTTPBody:[_postStringForShare dataUsingEncoding:NSUTF8StringEncoding]]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } @@ -554,9 +826,9 @@ - (void)unShareFileOrFolderByServer:(NSString *)serverPath NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } @@ -570,9 +842,9 @@ - (void)isShareFileOrFolderByServer:(NSString *)serverPath NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } - (void) updateShareItem:(NSInteger)shareId @@ -612,9 +884,9 @@ - (void) updateShareItem:(NSInteger)shareId [request setHTTPBody:[_postStringForShare dataUsingEncoding:NSUTF8StringEncoding]]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } - (void) updateShareItem:(NSInteger)shareId @@ -642,9 +914,9 @@ - (void) updateShareItem:(NSInteger)shareId [request setHTTPBody:[_postStringForShare dataUsingEncoding:NSUTF8StringEncoding]]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } - (void) searchUsersAndGroupsWith:(NSString *)searchString forPage:(NSInteger)page with:(NSInteger)resultsPerPage ofServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success @@ -665,9 +937,9 @@ - (void) searchUsersAndGroupsWith:(NSString *)searchString forPage:(NSInteger)pa NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } - (void) getCapabilitiesOfServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success @@ -679,9 +951,9 @@ - (void) getCapabilitiesOfServer:(NSString*)serverPath onCommunication:(OCCommun NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - [operation resume]; + [sessionDataTask resume]; } @@ -689,7 +961,7 @@ - (void) getCapabilitiesOfServer:(NSString*)serverPath onCommunication:(OCCommun #pragma mark - Remote thumbnails -- (OCHTTPRequestOperation *) getRemoteThumbnailByServer:(NSString*)serverPath ofFilePath:(NSString*)filePath withWidth:(NSInteger)fileWidth andHeight:(NSInteger)fileHeight onCommunication:(OCCommunication *)sharedOCCommunication +- (NSURLSessionDataTask *) getRemoteThumbnailByServer:(NSString*)serverPath ofFilePath:(NSString*)filePath withWidth:(NSInteger)fileWidth andHeight:(NSInteger)fileHeight onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{ _requestMethod = @"GET"; @@ -699,10 +971,10 @@ - (OCHTTPRequestOperation *) getRemoteThumbnailByServer:(NSString*)serverPath of NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil]; - OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure]; + NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure]; [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager]; - return operation; + return sessionDataTask; } diff --git a/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.m b/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.m index 6c20022a..ecedbfec 100644 --- a/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.m +++ b/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.m @@ -238,6 +238,17 @@ + (NSError *) getErrorByCodeId:(int) errorCode { error = [NSError errorWithDomain:k_domain_error_code code:kOCErrorServerForbidden userInfo:details]; break; } + + case OCErrorServerMaintenanceMode: + case kOCErrorServerMaintenanceError: + { + NSMutableDictionary* details = [NSMutableDictionary dictionary]; + [details setValue:NSLocalizedString(@"maintenance_mode_on_server_message", nil) forKey:NSLocalizedDescriptionKey]; + + error = [NSError errorWithDomain:k_domain_error_code code:kOCErrorServerForbidden userInfo:details]; + break; + } + case OCErrorForbiddenUnknown: { NSMutableDictionary* details = [NSMutableDictionary dictionary]; @@ -246,6 +257,25 @@ + (NSError *) getErrorByCodeId:(int) errorCode { error = [NSError errorWithDomain:k_domain_error_code code:OCErrorForbiddenUnknown userInfo:details]; break; } + + case OCErrorOAuth2ErrorAccessDenied: + { + NSMutableDictionary* details = [NSMutableDictionary dictionary]; + [details setValue:NSLocalizedString(@"oauth2_error_access_denied", nil) forKey:NSLocalizedDescriptionKey]; + + error = [NSError errorWithDomain:k_domain_error_code code:OCErrorOAuth2ErrorAccessDenied userInfo:details]; + break; + } + + case OCErrorOAuth2Error: + { + NSMutableDictionary* details = [NSMutableDictionary dictionary]; + [details setValue:NSLocalizedString(@"oauth2_error", nil) forKey:NSLocalizedDescriptionKey]; + + error = [NSError errorWithDomain:k_domain_error_code code:OCErrorOAuth2Error userInfo:details]; + break; + } + default: { NSMutableDictionary* details = [NSMutableDictionary dictionary]; @@ -465,7 +495,10 @@ + (NSMutableURLRequest *) getRequestWithCookiesByRequest: (NSMutableURLRequest * * */ + (void) deleteAllCookies { + NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; + NSLog(@"Deleting cookie storage: %@", cookieStorage); + for (NSHTTPCookie *each in cookieStorage.cookies) { [cookieStorage deleteCookie:each]; } @@ -634,10 +667,10 @@ + (BOOL) isPermissionToReadCreateUpdate:(NSInteger) permissionValue { BOOL canCreate = [self isPermissionToCanCreate:permissionValue]; BOOL canChange = [self isPermissionToCanChange:permissionValue]; - BOOL canEdit = (canCreate && canChange && canRead); return canEdit; - } + + @end diff --git a/OCCommunicationLib/OCCommunicationLibTests/OCCommunicationLibTests.m b/OCCommunicationLib/OCCommunicationLibTests/OCCommunicationLibTests.m index 9d6791d6..c36b946a 100644 --- a/OCCommunicationLib/OCCommunicationLibTests/OCCommunicationLibTests.m +++ b/OCCommunicationLib/OCCommunicationLibTests/OCCommunicationLibTests.m @@ -68,9 +68,15 @@ - (void)setUp [super setUp]; _sharedOCCommunication = [[OCCommunication alloc] init]; - [_sharedOCCommunication setCredentialsWithUser:k_user andPassword:k_password]; + OCCredentialsDto* credentials = [[OCCredentialsDto alloc] init]; + credentials.authenticationMethod = AuthenticationMethodBASIC_HTTP_AUTH; + credentials.userName = k_user; + credentials.accessToken = k_password; + [_sharedOCCommunication setCredentials:credentials]; [_sharedOCCommunication setSecurityPolicyManagers:[_sharedOCCommunication createSecurityPolicy]]; + //TODO: set oauthconfiguration an credentialsStorage + //Create Tests folder [self createFolderWithName:k_path_test_folder]; diff --git a/OCCommunicationLib/ownCloud iOS library.xcodeproj/project.pbxproj b/OCCommunicationLib/ownCloud iOS library.xcodeproj/project.pbxproj index 0b1e5443..d668b06e 100644 --- a/OCCommunicationLib/ownCloud iOS library.xcodeproj/project.pbxproj +++ b/OCCommunicationLib/ownCloud iOS library.xcodeproj/project.pbxproj @@ -11,6 +11,8 @@ 1345E4601884213400153F14 /* OCXMLShareByLinkParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 1345E45F1884213400153F14 /* OCXMLShareByLinkParser.m */; }; 13AA8636187C211900A10927 /* OCSharedDto.m in Sources */ = {isa = PBXBuildFile; fileRef = 13AA8635187C211900A10927 /* OCSharedDto.m */; }; 13AA8640187C3B9700A10927 /* OCXMLParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 13AA863F187C3B9700A10927 /* OCXMLParser.m */; }; + 4033BE531F5429F900D76200 /* OCOAuth2Manager.m in Sources */ = {isa = PBXBuildFile; fileRef = 4033BE521F5429F900D76200 /* OCOAuth2Manager.m */; }; + 4033BE561F54385900D76200 /* OCOAuth2Configuration.m in Sources */ = {isa = PBXBuildFile; fileRef = 4033BE551F54385900D76200 /* OCOAuth2Configuration.m */; }; 40D4039D1E955C020003A855 /* OCServerFeatures.m in Sources */ = {isa = PBXBuildFile; fileRef = 40D4039C1E955C020003A855 /* OCServerFeatures.m */; }; 59A5B71E191907F100724BE3 /* AFHTTPSessionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 59A5B70E191907F100724BE3 /* AFHTTPSessionManager.m */; }; 59A5B71F191907F100724BE3 /* AFNetworkReachabilityManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 59A5B711191907F100724BE3 /* AFNetworkReachabilityManager.m */; }; @@ -18,6 +20,7 @@ 59A5B722191907F100724BE3 /* AFURLRequestSerialization.m in Sources */ = {isa = PBXBuildFile; fileRef = 59A5B717191907F100724BE3 /* AFURLRequestSerialization.m */; }; 59A5B723191907F100724BE3 /* AFURLResponseSerialization.m in Sources */ = {isa = PBXBuildFile; fileRef = 59A5B719191907F100724BE3 /* AFURLResponseSerialization.m */; }; 59A5B724191907F100724BE3 /* AFURLSessionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 59A5B71B191907F100724BE3 /* AFURLSessionManager.m */; }; + 7F6F496D1F46C70C009F8813 /* OCCredentialsDto.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F6F496C1F46C70C009F8813 /* OCCredentialsDto.m */; }; EA05999A1BB96D14002C2864 /* OCShareUser.m in Sources */ = {isa = PBXBuildFile; fileRef = EA0599991BB96D14002C2864 /* OCShareUser.m */; }; EA73DC831B1C48EA00C3AC21 /* OCXMLServerErrorsParser.m in Sources */ = {isa = PBXBuildFile; fileRef = EA73DC821B1C48EA00C3AC21 /* OCXMLServerErrorsParser.m */; }; EA7CC89B183E11E600B6A4B4 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA7CC89A183E11E600B6A4B4 /* Foundation.framework */; }; @@ -33,8 +36,6 @@ EA7CC929183E14A100B6A4B4 /* NSDate+ISO8601.m in Sources */ = {isa = PBXBuildFile; fileRef = EA7CC91E183E14A100B6A4B4 /* NSDate+ISO8601.m */; }; EA7CC92A183E14A100B6A4B4 /* NSDate+RFC1123.m in Sources */ = {isa = PBXBuildFile; fileRef = EA7CC920183E14A100B6A4B4 /* NSDate+RFC1123.m */; }; EA7CC92B183E14A100B6A4B4 /* NSDate+RFC1123.m in Sources */ = {isa = PBXBuildFile; fileRef = EA7CC920183E14A100B6A4B4 /* NSDate+RFC1123.m */; }; - EA7CC92C183E14A100B6A4B4 /* OCHTTPRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = EA7CC923183E14A100B6A4B4 /* OCHTTPRequestOperation.m */; }; - EA7CC92D183E14A100B6A4B4 /* OCHTTPRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = EA7CC923183E14A100B6A4B4 /* OCHTTPRequestOperation.m */; }; EA7CC92E183E14A100B6A4B4 /* OCWebDAVClient.m in Sources */ = {isa = PBXBuildFile; fileRef = EA7CC925183E14A100B6A4B4 /* OCWebDAVClient.m */; }; EA7CC92F183E14A100B6A4B4 /* OCWebDAVClient.m in Sources */ = {isa = PBXBuildFile; fileRef = EA7CC925183E14A100B6A4B4 /* OCWebDAVClient.m */; }; EA7CC934183E150000B6A4B4 /* OCCommunication.m in Sources */ = {isa = PBXBuildFile; fileRef = EA7CC933183E150000B6A4B4 /* OCCommunication.m */; }; @@ -82,6 +83,11 @@ 13AA8635187C211900A10927 /* OCSharedDto.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = OCSharedDto.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 13AA863E187C3B9700A10927 /* OCXMLParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = OCXMLParser.h; path = OCWebDavClient/Parsers/OCXMLParser.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; 13AA863F187C3B9700A10927 /* OCXMLParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; name = OCXMLParser.m; path = OCWebDavClient/Parsers/OCXMLParser.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 4033BE511F5429F900D76200 /* OCOAuth2Manager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCOAuth2Manager.h; sourceTree = ""; }; + 4033BE521F5429F900D76200 /* OCOAuth2Manager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCOAuth2Manager.m; sourceTree = ""; }; + 4033BE541F54385900D76200 /* OCOAuth2Configuration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OCOAuth2Configuration.h; path = OCCommunicationLib/OCOAuth2Authentication/OCOAuth2Configuration.h; sourceTree = SOURCE_ROOT; }; + 4033BE551F54385900D76200 /* OCOAuth2Configuration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OCOAuth2Configuration.m; path = OCCommunicationLib/OCOAuth2Authentication/OCOAuth2Configuration.m; sourceTree = SOURCE_ROOT; }; + 40B2981A1F57196F008EC53F /* OCCredentialsStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCCredentialsStorage.h; sourceTree = ""; }; 40D4039B1E955C020003A855 /* OCServerFeatures.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCServerFeatures.h; sourceTree = ""; }; 40D4039C1E955C020003A855 /* OCServerFeatures.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCServerFeatures.m; sourceTree = ""; }; 591BFBF31B1C809000AB8D3A /* OCConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = OCConstants.h; path = Utils/OCConstants.h; sourceTree = ""; }; @@ -99,6 +105,9 @@ 59A5B719191907F100724BE3 /* AFURLResponseSerialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFURLResponseSerialization.m; path = ExternalLibs/AFNetworking/AFURLResponseSerialization.m; sourceTree = ""; }; 59A5B71A191907F100724BE3 /* AFURLSessionManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFURLSessionManager.h; path = ExternalLibs/AFNetworking/AFURLSessionManager.h; sourceTree = ""; }; 59A5B71B191907F100724BE3 /* AFURLSessionManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFURLSessionManager.m; path = ExternalLibs/AFNetworking/AFURLSessionManager.m; sourceTree = ""; }; + 7F4E820F1F7D4DFA00C20454 /* OCTrustedCertificatesStore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCTrustedCertificatesStore.h; sourceTree = ""; }; + 7F6F496B1F46C6EB009F8813 /* OCCredentialsDto.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCCredentialsDto.h; sourceTree = ""; }; + 7F6F496C1F46C70C009F8813 /* OCCredentialsDto.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCCredentialsDto.m; sourceTree = ""; }; EA0599981BB96D14002C2864 /* OCShareUser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCShareUser.h; sourceTree = ""; }; EA0599991BB96D14002C2864 /* OCShareUser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCShareUser.m; sourceTree = ""; }; EA73DC811B1C48EA00C3AC21 /* OCXMLServerErrorsParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OCXMLServerErrorsParser.h; path = OCWebDavClient/Parsers/OCXMLServerErrorsParser.h; sourceTree = ""; }; @@ -118,8 +127,6 @@ EA7CC91E183E14A100B6A4B4 /* NSDate+ISO8601.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; name = "NSDate+ISO8601.m"; path = "OCWebDavClient/NSDate+ISO8601.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; EA7CC91F183E14A100B6A4B4 /* NSDate+RFC1123.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = "NSDate+RFC1123.h"; path = "OCWebDavClient/NSDate+RFC1123.h"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; EA7CC920183E14A100B6A4B4 /* NSDate+RFC1123.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; name = "NSDate+RFC1123.m"; path = "OCWebDavClient/NSDate+RFC1123.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; - EA7CC922183E14A100B6A4B4 /* OCHTTPRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = OCHTTPRequestOperation.h; path = OCWebDavClient/OCHTTPRequestOperation.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; - EA7CC923183E14A100B6A4B4 /* OCHTTPRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; name = OCHTTPRequestOperation.m; path = OCWebDavClient/OCHTTPRequestOperation.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; EA7CC924183E14A100B6A4B4 /* OCWebDAVClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = OCWebDAVClient.h; path = OCWebDavClient/OCWebDAVClient.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; EA7CC925183E14A100B6A4B4 /* OCWebDAVClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; name = OCWebDAVClient.m; path = OCWebDavClient/OCWebDAVClient.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; EA7CC932183E150000B6A4B4 /* OCCommunication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = OCCommunication.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; @@ -179,6 +186,18 @@ name = Parsers; sourceTree = ""; }; + 4033BE571F54386400D76200 /* OCOAuth2Authentication */ = { + isa = PBXGroup; + children = ( + 4033BE511F5429F900D76200 /* OCOAuth2Manager.h */, + 4033BE521F5429F900D76200 /* OCOAuth2Manager.m */, + 4033BE541F54385900D76200 /* OCOAuth2Configuration.h */, + 4033BE551F54385900D76200 /* OCOAuth2Configuration.m */, + 40B2981A1F57196F008EC53F /* OCCredentialsStorage.h */, + ); + path = OCOAuth2Authentication; + sourceTree = ""; + }; EA7CC88E183E11E600B6A4B4 = { isa = PBXGroup; children = ( @@ -212,6 +231,9 @@ EA7CC89C183E11E600B6A4B4 /* OCCommunicationLib */ = { isa = PBXGroup; children = ( + 4033BE571F54386400D76200 /* OCOAuth2Authentication */, + 7F6F496B1F46C6EB009F8813 /* OCCredentialsDto.h */, + 7F6F496C1F46C70C009F8813 /* OCCredentialsDto.m */, EAABAA30183E688900909831 /* OCFileDto.h */, EAABAA31183E688900909831 /* OCFileDto.m */, EA0599981BB96D14002C2864 /* OCShareUser.h */, @@ -226,6 +248,7 @@ EA7CC932183E150000B6A4B4 /* OCCommunication.h */, EA7CC933183E150000B6A4B4 /* OCCommunication.m */, EAABAB1218574A7C00909831 /* OCErrorMsg.h */, + 7F4E820F1F7D4DFA00C20454 /* OCTrustedCertificatesStore.h */, EAABAB171858593500909831 /* UploadSupport */, EA7CC91C183E147C00B6A4B4 /* OCWebDavClient */, EA7CC8E7183E133800B6A4B4 /* Utils */, @@ -312,8 +335,6 @@ EA7CC91E183E14A100B6A4B4 /* NSDate+ISO8601.m */, EA7CC91F183E14A100B6A4B4 /* NSDate+RFC1123.h */, EA7CC920183E14A100B6A4B4 /* NSDate+RFC1123.m */, - EA7CC922183E14A100B6A4B4 /* OCHTTPRequestOperation.h */, - EA7CC923183E14A100B6A4B4 /* OCHTTPRequestOperation.m */, EA7CC924183E14A100B6A4B4 /* OCWebDAVClient.h */, EA7CC925183E14A100B6A4B4 /* OCWebDAVClient.m */, ); @@ -427,6 +448,7 @@ 59A5B71F191907F100724BE3 /* AFNetworkReachabilityManager.m in Sources */, EA7CC92E183E14A100B6A4B4 /* OCWebDAVClient.m in Sources */, EAABAB1E1858594A00909831 /* OCChunkDto.m in Sources */, + 4033BE531F5429F900D76200 /* OCOAuth2Manager.m in Sources */, EA73DC831B1C48EA00C3AC21 /* OCXMLServerErrorsParser.m in Sources */, 1345E4601884213400153F14 /* OCXMLShareByLinkParser.m in Sources */, 59A5B720191907F100724BE3 /* AFSecurityPolicy.m in Sources */, @@ -434,6 +456,7 @@ EA7CC934183E150000B6A4B4 /* OCCommunication.m in Sources */, 131C67B9187C3E360009030E /* OCXMLSharedParser.m in Sources */, 13AA8640187C3B9700A10927 /* OCXMLParser.m in Sources */, + 4033BE561F54385900D76200 /* OCOAuth2Configuration.m in Sources */, EA7CC912183E146000B6A4B4 /* UtilsFramework.m in Sources */, EA7CC92A183E14A100B6A4B4 /* NSDate+RFC1123.m in Sources */, 13AA8636187C211900A10927 /* OCSharedDto.m in Sources */, @@ -443,7 +466,7 @@ 59A5B722191907F100724BE3 /* AFURLRequestSerialization.m in Sources */, EA05999A1BB96D14002C2864 /* OCShareUser.m in Sources */, 59A5B723191907F100724BE3 /* AFURLResponseSerialization.m in Sources */, - EA7CC92C183E14A100B6A4B4 /* OCHTTPRequestOperation.m in Sources */, + 7F6F496D1F46C70C009F8813 /* OCCredentialsDto.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -459,7 +482,6 @@ EAABAA33183E688900909831 /* OCFileDto.m in Sources */, EA7CC8B7183E11E600B6A4B4 /* OCCommunicationLibTests.m in Sources */, EA7CC929183E14A100B6A4B4 /* NSDate+ISO8601.m in Sources */, - EA7CC92D183E14A100B6A4B4 /* OCHTTPRequestOperation.m in Sources */, EAABAB2718585C5200909831 /* NSString+Encode.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0;