From b176e9bf1a9cad65be25011659e90c2cd0fed104 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Mon, 5 Aug 2019 11:02:39 +0530 Subject: [PATCH 01/10] initial code and changes related to file upload --- MASFoundation.xcodeproj/project.pbxproj | 36 +++++ MASFoundation/Classes/MAS.h | 5 + MASFoundation/Classes/MAS.m | 51 +++++++ MASFoundation/Classes/MASConstants.h | 16 ++ .../NSMutableURLRequest+MASPrivate.h | 1 + .../NSMutableURLRequest+MASPrivate.m | 4 + .../services/network/MASNetworkingService.h | 6 + .../services/network/MASNetworkingService.m | 91 +++++++++++ .../network/internal/MASSecurityPolicy.m | 24 ++- .../internal/MASSessionDataTaskOperation.h | 2 + .../internal/MASSessionDataTaskOperation.m | 33 +++- .../internal/MASSessionTaskOperation.m | 6 + .../network/internal/MASURLSessionManager.h | 2 + .../network/internal/MASURLSessionManager.m | 19 +++ .../network/requests/MASPostFormURLRequest.h | 20 +++ .../network/requests/MASPostFormURLRequest.m | 67 ++++++++ .../network/requests/MASPostURLRequest.m | 5 +- .../services/network/requests/MASURLRequest.m | 1 + .../Classes/models/Network/MASFileRequest.h | 19 +++ .../Classes/models/Network/MASFileRequest.m | 13 ++ .../models/Network/MASFileRequestBuilder.h | 32 ++++ .../models/Network/MASFileRequestBuilder.m | 13 ++ .../models/Network/MASMultiPartFormData.h | 63 ++++++++ .../Network/MASMultiPartRequestSerializer.h | 23 +++ .../Network/MASMultiPartRequestSerializer.m | 144 ++++++++++++++++++ .../MASIURLResponseSerialization.m | 1 + 26 files changed, 689 insertions(+), 8 deletions(-) create mode 100644 MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h create mode 100644 MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m create mode 100644 MASFoundation/Classes/models/Network/MASFileRequest.h create mode 100644 MASFoundation/Classes/models/Network/MASFileRequest.m create mode 100644 MASFoundation/Classes/models/Network/MASFileRequestBuilder.h create mode 100644 MASFoundation/Classes/models/Network/MASFileRequestBuilder.m create mode 100644 MASFoundation/Classes/models/Network/MASMultiPartFormData.h create mode 100644 MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h create mode 100644 MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index 1bb90265..eb19eb0d 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -185,6 +185,15 @@ C81CC3CD1FC2EA190058718E /* MASBrowserBasedAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */; }; C81CC3D01FC2EFBB0058718E /* UIAlertController+MAS.h in Headers */ = {isa = PBXBuildFile; fileRef = C81CC3CE1FC2EFBB0058718E /* UIAlertController+MAS.h */; }; C81CC3D11FC2EFBB0058718E /* UIAlertController+MAS.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CF1FC2EFBB0058718E /* UIAlertController+MAS.m */; }; + C850970C22D48E7E002182A0 /* MASFileRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = C850970A22D48E7E002182A0 /* MASFileRequest.h */; }; + C850970D22D48E7E002182A0 /* MASFileRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C850970B22D48E7E002182A0 /* MASFileRequest.m */; }; + C8C32B0D22D706B900D64DF0 /* MASMultiPartFormData.h in Headers */ = {isa = PBXBuildFile; fileRef = C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */; settings = {ATTRIBUTES = (Public, ); }; }; + C8C32B1022D7163100D64DF0 /* MASMultiPartRequestSerializer.h in Headers */ = {isa = PBXBuildFile; fileRef = C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */; }; + C8C32B1122D7163100D64DF0 /* MASMultiPartRequestSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */; }; + C8C32B1822D88BF100D64DF0 /* MASPostFormURLRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = C8C32B1622D88BF100D64DF0 /* MASPostFormURLRequest.h */; }; + C8C32B1922D88BF100D64DF0 /* MASPostFormURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C8C32B1722D88BF100D64DF0 /* MASPostFormURLRequest.m */; }; + C8CEAFD222D48D32000B6C8A /* MASFileRequestBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = C8CEAFD022D48D32000B6C8A /* MASFileRequestBuilder.h */; }; + C8CEAFD322D48D32000B6C8A /* MASFileRequestBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = C8CEAFD122D48D32000B6C8A /* MASFileRequestBuilder.m */; }; CB0B58591E258C2A00BC0163 /* MASAuthorizationResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = CB0B58571E258C2A00BC0163 /* MASAuthorizationResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; CB0B585A1E258C2A00BC0163 /* MASAuthorizationResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = CB0B58581E258C2A00BC0163 /* MASAuthorizationResponse.m */; }; CB1907EF1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = CB1907ED1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h */; }; @@ -560,6 +569,15 @@ C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASBrowserBasedAuthentication.m; sourceTree = ""; }; C81CC3CE1FC2EFBB0058718E /* UIAlertController+MAS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIAlertController+MAS.h"; sourceTree = ""; }; C81CC3CF1FC2EFBB0058718E /* UIAlertController+MAS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIAlertController+MAS.m"; sourceTree = ""; }; + C850970A22D48E7E002182A0 /* MASFileRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASFileRequest.h; sourceTree = ""; }; + C850970B22D48E7E002182A0 /* MASFileRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASFileRequest.m; sourceTree = ""; }; + C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASMultiPartFormData.h; sourceTree = ""; }; + C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASMultiPartRequestSerializer.h; sourceTree = ""; }; + C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASMultiPartRequestSerializer.m; sourceTree = ""; }; + C8C32B1622D88BF100D64DF0 /* MASPostFormURLRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASPostFormURLRequest.h; sourceTree = ""; }; + C8C32B1722D88BF100D64DF0 /* MASPostFormURLRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASPostFormURLRequest.m; sourceTree = ""; }; + C8CEAFD022D48D32000B6C8A /* MASFileRequestBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASFileRequestBuilder.h; sourceTree = ""; }; + C8CEAFD122D48D32000B6C8A /* MASFileRequestBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASFileRequestBuilder.m; sourceTree = ""; }; CB0B58571E258C2A00BC0163 /* MASAuthorizationResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASAuthorizationResponse.h; sourceTree = ""; }; CB0B58581E258C2A00BC0163 /* MASAuthorizationResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASAuthorizationResponse.m; sourceTree = ""; }; CB1907ED1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MASIKeyChainStore+MASPrivate.h"; sourceTree = ""; }; @@ -897,6 +915,8 @@ CB5E4C671C1D21FB001B3B8A /* MASPostURLRequest.m */, CB5E4C6E1C1D250D001B3B8A /* MASPutURLRequest.h */, CB5E4C6F1C1D250D001B3B8A /* MASPutURLRequest.m */, + C8C32B1622D88BF100D64DF0 /* MASPostFormURLRequest.h */, + C8C32B1722D88BF100D64DF0 /* MASPostFormURLRequest.m */, ); path = requests; sourceTree = ""; @@ -1227,6 +1247,13 @@ 699C17901F9585BC008C1B11 /* MASRequest.m */, 699C17921F9585BC008C1B11 /* MASRequestBuilder.h */, 699C17931F9585BD008C1B11 /* MASRequestBuilder.m */, + C8CEAFD022D48D32000B6C8A /* MASFileRequestBuilder.h */, + C8CEAFD122D48D32000B6C8A /* MASFileRequestBuilder.m */, + C850970A22D48E7E002182A0 /* MASFileRequest.h */, + C850970B22D48E7E002182A0 /* MASFileRequest.m */, + C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */, + C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */, + C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */, ); path = Network; sourceTree = ""; @@ -1530,6 +1557,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + C8C32B0D22D706B900D64DF0 /* MASMultiPartFormData.h in Headers */, CB2A4048209A341A00F988AA /* MASMultiFactorHandler.h in Headers */, CB1FD14B1FB23701000AFA25 /* MASSharedStorage.h in Headers */, 69B7DF6A1F9675600056DD3A /* MASRequestBuilder.h in Headers */, @@ -1550,6 +1578,7 @@ CBD25B0C1E78C47C00DFB47F /* JWTBase64Coder.h in Headers */, A419B3A11C176259008DC88C /* NSData+MAS.h in Headers */, A488CE751C0B97FD00B8B961 /* MASService.h in Headers */, + C8CEAFD222D48D32000B6C8A /* MASFileRequestBuilder.h in Headers */, CB6491FB1FE9DAF300281288 /* MQTTSSLSecurityPolicy.h in Headers */, CBD25B0B1E78C47C00DFB47F /* JWT.h in Headers */, CBD25B091E78C47C00DFB47F /* JWTCoding.h in Headers */, @@ -1624,6 +1653,7 @@ CB3173E01F1FFF2C00C85E47 /* MASNetworkMonitor.h in Headers */, A4150EE71BF16E5B00037E27 /* MASFileService.h in Headers */, A46F49C41C2F5FC500A4C370 /* MASIHTTPRequestOperation.h in Headers */, + C8C32B1822D88BF100D64DF0 /* MASPostFormURLRequest.h in Headers */, A46F49E51C2F5FC500A4C370 /* UIProgressView+MASINetworking.h in Headers */, A4150E711BF1643900037E27 /* NSMutableURLRequest+MASPrivate.h in Headers */, A46F49BC1C2F5FC500A4C370 /* fmemopen.h in Headers */, @@ -1675,6 +1705,7 @@ A47F126C1C1D6B4B0008E3F2 /* MASURLRequest.h in Headers */, CB9B1211210949E1008A2075 /* MASASN1Decoder.h in Headers */, 10D2D49E1C1686ED00DF8AC4 /* MASGroup+MASPrivate.h in Headers */, + C8C32B1022D7163100D64DF0 /* MASMultiPartRequestSerializer.h in Headers */, CB5E4C681C1D21FB001B3B8A /* MASPostURLRequest.h in Headers */, A4150ED41BF16D9A00037E27 /* MASNetworkingService.h in Headers */, CB2357961F0EFDEA00D4C420 /* MASSessionTaskOperation.h in Headers */, @@ -1694,6 +1725,7 @@ 10E027A61F72B10100EAB103 /* RNEncryptor.h in Headers */, CB6491E01FE9DAF300281288 /* MQTTCFSocketEncoder.h in Headers */, CBD25AFB1E78C47C00DFB47F /* JWTClaimsSet.h in Headers */, + C850970C22D48E7E002182A0 /* MASFileRequest.h in Headers */, CB6491F11FE9DAF300281288 /* MQTTProperties.h in Headers */, 69B7DF6C1F96756B0056DD3A /* MASRequest+MASPrivate.h in Headers */, A417BA511BF033C300EC9BCB /* CLLocation+MASPrivate.h in Headers */, @@ -1851,6 +1883,7 @@ CB99754F1EDF5837006CEBB1 /* MASAuthCredentialsAuthorizationCode.m in Sources */, A488CE761C0B97FD00B8B961 /* MASService.m in Sources */, A42A86A11BBDA27F00AE98AC /* NSError+MASPrivate.m in Sources */, + C8CEAFD322D48D32000B6C8A /* MASFileRequestBuilder.m in Sources */, A450BC0C1BE1570C0030491F /* NSNotificationCenter+MASPrivate.m in Sources */, A46F49F41C2F5FC500A4C370 /* MASIOrderedDictionary.m in Sources */, CB1907F01C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.m in Sources */, @@ -1905,6 +1938,7 @@ 107389F81C7118F800B7E87E /* MASMQTTClient.m in Sources */, 10E027A31F72B10100EAB103 /* RNCryptorEngine.m in Sources */, CBD25AFC1E78C47C00DFB47F /* JWTClaimsSet.m in Sources */, + C8C32B1122D7163100D64DF0 /* MASMultiPartRequestSerializer.m in Sources */, CBD25AF11E78C47C00DFB47F /* JWTAlgorithmRSBase.m in Sources */, CBD25AEF1E78C47C00DFB47F /* JWTAlgorithmHSBase.m in Sources */, CBD25AF81E78C47C00DFB47F /* JWTCryptoSecurity.m in Sources */, @@ -1949,6 +1983,7 @@ A4831AB21BD1A551007B4AE6 /* MASFile.m in Sources */, CB0B585A1E258C2A00BC0163 /* MASAuthorizationResponse.m in Sources */, CB5E4C651C1D1B56001B3B8A /* MASGetURLRequest.m in Sources */, + C8C32B1922D88BF100D64DF0 /* MASPostFormURLRequest.m in Sources */, CB6491FA1FE9DAF300281288 /* MQTTSessionSynchron.m in Sources */, A4831AB01BD1A551007B4AE6 /* MASDevice.m in Sources */, CBD25B001E78C47C00DFB47F /* JWTClaimsSetVerifier.m in Sources */, @@ -1990,6 +2025,7 @@ A46F49D61C2F5FC500A4C370 /* MASIURLResponseSerialization.m in Sources */, CB1907F91C17950700A5EF16 /* MASAccessService.m in Sources */, CBD25B0A1E78C47C00DFB47F /* JWTCoding.m in Sources */, + C850970D22D48E7E002182A0 /* MASFileRequest.m in Sources */, CBD25B101E78C47C00DFB47F /* JWTErrorDescription.m in Sources */, CB5E4C6D1C1D2467001B3B8A /* MASDeleteURLRequest.m in Sources */, A46F49CE1C2F5FC500A4C370 /* MASINetworkReachabilityManager.m in Sources */, diff --git a/MASFoundation/Classes/MAS.h b/MASFoundation/Classes/MAS.h index cf7c56b0..8719ae97 100644 --- a/MASFoundation/Classes/MAS.h +++ b/MASFoundation/Classes/MAS.h @@ -14,6 +14,7 @@ #import "MASClaims.h" #import "MASRequest.h" #import "MASMultiFactorAuthenticator.h" +#import "MASMultiPartFormData.h" /** * The top level MAS object represents the Mobile App Services SDK in it's entirety. It @@ -1059,6 +1060,10 @@ withParameters:(NSDictionary *_Nullable)parameterInfo +# pragma mark - FILE Requests + ++ (void)upload:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull MASMultiPartFormDataBlock)formDatablock progress:( MASFileRequestProgressBlock _Nullable )progressBlock completion:(nullable MASResponseObjectErrorBlock)completion; + ///-------------------------------------- /// @name JWT Signing ///-------------------------------------- diff --git a/MASFoundation/Classes/MAS.m b/MASFoundation/Classes/MAS.m index 3cdaa1a4..caa5ffe7 100644 --- a/MASFoundation/Classes/MAS.m +++ b/MASFoundation/Classes/MAS.m @@ -1128,8 +1128,59 @@ + (void)invoke:(nonnull MASRequest *)request completion:(nullable MASResponseObj } ++ (void)upload:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull MASMultiPartFormDataBlock)formDatablock progress:( MASFileRequestProgressBlock _Nullable )progressBlock completion:(nullable MASResponseObjectErrorBlock)completion +{ + [MAS checkAndValidateRequestScope:request.endPoint headerInfo:request.header isPublic:request.isPublic completion:^(BOOL completed, NSError *error) { + + if(!completed){ + completion(nil,nil,error); + return; + } + + [[MASNetworkingService sharedService] postMultiPartForm:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic constructingBodyBlock:formDatablock progress:progressBlock completion:completion]; + + }]; +} + + # pragma mark - Private ++ (void)checkAndValidateRequestScope:(NSString*)endPoint headerInfo:(NSDictionary *)headerInfo isPublic:(BOOL)isPublic completion:(MASCompletionErrorBlock)completion +{ + // + // Check for endpoint + // + if (!endPoint) + { + if (completion) + { + completion(NO, [NSError errorInvalidEndpoint]); + + return; + } + } + + // + // Check if MAS has been started. + // + if ([MAS MASState] != MASStateDidStart) + { + if (completion) + { + completion(NO, [NSError errorMASIsNotStarted]); + + return; + } + } + + // + // Validate if new scope has been requested in header + // Validation will be ignored if the request is being made as public + // + [MAS validateScopeForRequest:headerInfo isPublic:isPublic completion:completion]; + +} + + (void)httpMethod:(NSString *)httpMethod endPoint:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo diff --git a/MASFoundation/Classes/MASConstants.h b/MASFoundation/Classes/MASConstants.h index 92b994ed..1dcec58f 100644 --- a/MASFoundation/Classes/MASConstants.h +++ b/MASFoundation/Classes/MASConstants.h @@ -13,6 +13,7 @@ @class CLLocation; @class MASAuthCredentials; @class MASUser; +@protocol MASMultiPartFormData; /** @@ -113,6 +114,16 @@ typedef void (^MASResponseObjectErrorBlock)(NSHTTPURLResponse *_Nullable respons */ typedef void (^MASUserResponseErrorBlock)(MASUser *_Nullable user, NSError *_Nullable error); +/** + * Progress block for File requests + */ +typedef void (^MASFileRequestProgressBlock) (NSProgress* _Nullable progress); + + +/** + * Multi Part body data that needs to be supplied + */ +typedef void (^MASMultiPartFormDataBlock)(id _Nonnull formData); /** * The MASAuthCredentialsBlcok to provide auth credentials for device registration and/or user authentication. @@ -240,6 +251,11 @@ typedef NS_ENUM(NSInteger, MASRequestResponseType) */ MASRequestResponseTypeXml, + /** + * Standard Multi-part form data + */ + MASRequestResponseTypeFormData, + /** * The total number of supported types. */ diff --git a/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.h b/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.h index 043e0991..20af507a 100644 --- a/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.h +++ b/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.h @@ -17,6 +17,7 @@ extern NSString * const MASRequestResponseTypeScimJsonValue; extern NSString * const MASRequestResponseTypeTextPlainValue; extern NSString * const MASRequestResponseTypeWwwFormUrlEncodedValue; extern NSString * const MASRequestResponseTypeXmlValue; +extern NSString * const MASRequestResponseTypeFormDataValue; @interface NSMutableURLRequest (MASPrivate) diff --git a/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.m b/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.m index 468212b9..c1f646f1 100644 --- a/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.m +++ b/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.m @@ -69,6 +69,8 @@ - (NSString *)requestResponseTypeAsMimeTypeString:(MASRequestResponseType)type // XML // case MASRequestResponseTypeXml: return MASRequestResponseTypeXmlValue; + + case MASRequestResponseTypeFormData : return MASRequestResponseTypeFormDataValue; // // Default @@ -100,6 +102,8 @@ - (MASRequestResponseType)requestResponseTypeFromMimeTypeString:(NSString *)mime // else if([mimeType isEqualToString:MASRequestResponseTypeXmlValue]) return MASRequestResponseTypeXml; + + else if([mimeType isEqualToString:MASRequestResponseTypeFormDataValue]) return MASRequestResponseTypeFormData; // // Default to text/plain // diff --git a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h index c9da95d5..bc6e40fd 100644 --- a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h +++ b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h @@ -667,5 +667,11 @@ withParameters:(NSDictionary *)parameterInfo isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion; + + +# pragma mark - HTTP File Requests + +- (void)postMultiPartForm:(NSString*)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion; + @end diff --git a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m index e25f0ae5..ab07bcde 100644 --- a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m +++ b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m @@ -29,6 +29,7 @@ #import "MASSecurityPolicy.h" #import "MASNetworkReachability.h" #import "MASMultiFactorHandler+MASPrivate.h" +#import "MASMultiPartRequestSerializer.h" # pragma mark - Configuration Constants @@ -1388,6 +1389,96 @@ - (void)httpPutTo:(NSString *)endPoint } +- (void)postMultiPartForm:(NSString*)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion +{ + // + // endPoint cannot be nil + // + if (!endPoint) + { + // + // Notify + // + if(completion) completion(nil, nil,[NSError errorInvalidEndpoint]); + + return; + } + + [self httpFileUploadRequest:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic constructingBodyBlock:formDataBlock progress:progress completion:completion]; +} + + +- (void)httpFileUploadRequest:(NSString *)endPoint parameters:(NSDictionary *)parameterInfo headers:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion +{ + NSMutableDictionary *mutableHeaderInfo = [headerInfo mutableCopy]; + + MASURLRequest *request = nil; + + // + // if location was successfully retrieved + // + if ([MASLocationService sharedService].lastKnownLocation != nil) + { + mutableHeaderInfo[MASGeoLocationRequestResponseKey] = [[MASLocationService sharedService].lastKnownLocation locationAsGeoCoordinates]; + } + + request = [MASPostFormURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic constructingBodyBlock:formDataBlock]; + + // + // Construct MASSessionDataTaskOperation with request, and completion block to handle any responsive re-authentication or re-registration. + // + if(self.httpRedirectionBlock) + { + [_sessionManager setSessionDidReceiveHTTPRedirectBlock:self.httpRedirectionBlock]; + } + + MASSessionDataTaskOperation *operation = [self.sessionManager fileUploadOperation:request progress:progress completionHandler:[self sessionDataTaskCompletionBlockWithEndPoint:endPoint parameters:parameterInfo headers:headerInfo httpMethod:request.HTTPMethod requestType:requestType responseType:responseType isPublic:isPublic completionBlock:^(NSDictionary * _Nullable responseInfo, NSError * _Nullable error) { + if (completion) + { + completion([responseInfo objectForKey:MASNSHTTPURLResponseObjectKey], [responseInfo objectForKey:MASResponseInfoBodyInfoKey], error); + } + }]]; + + if (![self isMAGEndpoint:endPoint]) + { + // + // if the request is being made to system endpoint, and is not a public request which requires user credentials (tokens) + // then, add dependency on shared validation operation which will validate current session + // sharedOperation will only exist one at any given time as long as sharedOperation is being executed + // + if (!isPublic) + { + // + // add dependency + // + [operation addDependency:self.sharedOperation]; + + // + // to make sure SDK to not enqueue sharedOperation that is already enqueue and being executed + // + if (!self.sharedOperation.isFinished && !self.sharedOperation.isExecuting && ![_sessionManager.internalOperationQueue.operations containsObject:self.sharedOperation]) + { + // + // add sharedOperation into internal operation queue + // + [_sessionManager.internalOperationQueue addOperation:self.sharedOperation]; + } + } + + // + // add current request into normal operation queue + // + [_sessionManager.operationQueue addOperation:operation]; + } + else { + // + // if the request is being made to any one of system endpoints (registration, and/or authentication), then, add the operation into internal operation queue + // + [_sessionManager.internalOperationQueue addOperation:operation]; + } +} + + - (void)httpRequest:(NSString *)httpMethod endPoint:(NSString *)endPoint parameters:(NSDictionary *)parameterInfo headers:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion { // diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m index d3a1cc85..7e1d8537 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m @@ -51,7 +51,8 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo // if (securityConfiguration == nil) { - return NO; + //return NO; + return YES; } NSMutableArray *policies = [NSMutableArray array]; @@ -91,7 +92,18 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo switch (securityConfiguration.pinningMode) { case MASSecuritySSLPinningModeCertificate: { - isPinningVerified = [self validateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]; + BOOL isPublicKeyHashVerified = NO; + + if (securityConfiguration.publicKeyHashes != nil && [securityConfiguration.publicKeyHashes isKindOfClass:[NSArray class]] && [securityConfiguration.publicKeyHashes count] > 0) + { + isPublicKeyHashVerified = [self validatePublicKeyHash:serverTrust configuration:securityConfiguration]; + } + else + { + isPublicKeyHashVerified = YES; + } + + isPinningVerified = ([self validateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]) || isPublicKeyHashVerified; } break; case MASSecuritySSLPinningModeIntermediateCertifcate: @@ -150,7 +162,7 @@ - (BOOL)validateCertPinning:(SecTrustRef)serverTrust configuration:(MASSecurityC } } - return YES; + return NO; } @@ -179,7 +191,7 @@ - (BOOL)validateIntermediateCertPinning:(SecTrustRef)serverTrust configuration:( } - return YES; + return NO; } @@ -273,9 +285,11 @@ - (BOOL)validatePublicKeyHash:(SecTrustRef)serverTrust configuration:(MASSecurit { return NO; } + + return YES; } - return YES; + return NO; } diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.h b/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.h index e5268bdd..37b832fc 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.h +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.h @@ -23,4 +23,6 @@ @property (nonatomic, copy) MASNetworkDataTaskWillCacheResponseBlock willCacheResponseBlock; @property (nonatomic, copy) MASNetworkDataTaskDidReceiveResponseBlock didReceiveResponseBlock; +- (instancetype)initWithSession:(NSURLSession *)session request:(NSURLRequest *)request progress:(MASFileRequestProgressBlock)progress; + @end diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m b/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m index 0329c917..550969bc 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m @@ -21,7 +21,7 @@ @interface MASSessionDataTaskOperation () @property (nonatomic, strong) NSMutableData *responseData; @property (nonatomic, strong) NSError *error; -@property (nonatomic) long long totalBytesExpected; +@property (nonatomic) long long didSendBodyDataBlock; @property (nonatomic) long long bytesReceived; @property (nonatomic, readwrite, getter = isFinished) BOOL finished; @@ -30,6 +30,8 @@ @interface MASSessionDataTaskOperation () @property (nonatomic, readwrite, strong) MASURLRequest *request; @property (nonatomic, readwrite, strong) NSURLSession *session; +@property (nonatomic)MASFileRequestProgressBlock fileProgressblock; + @end @@ -41,6 +43,7 @@ @implementation MASSessionDataTaskOperation - (instancetype)initWithSession:(NSURLSession *)session request:(NSURLRequest *)request { + self = [super initWithSession:session request:request]; if (self) { @@ -51,6 +54,20 @@ - (instancetype)initWithSession:(NSURLSession *)session request:(NSURLRequest *) return self; } +- (instancetype)initWithSession:(NSURLSession *)session request:(NSURLRequest *)request progress:(MASFileRequestProgressBlock)progress +{ + self = [super initWithSession:session request:request]; + if(self) + { + self.request = (MASURLRequest *)request; + [self setResponseType:self.request.responseType]; + self.fileProgressblock = progress; + } + + return self; + +} + # pragma mark - Public - (void)updateSession:(NSURLSession *)session @@ -193,6 +210,7 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler { + NSLog(@"did receive content disposition"); NSURLSessionResponseDisposition disposition = NSURLSessionResponseAllow; if (self.didReceiveResponseBlock) @@ -279,4 +297,17 @@ - (void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session } + +- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend +{ + + NSLog(@"total bytes sent - %lld total bytes expected %lld",totalBytesSent,totalBytesExpectedToSend); + if(self.fileProgressblock){ + //NSProgress* progress = [NSProgress progressWithTotalUnitCount:totalBytesExpectedToSend]; + //[progress set] + self.fileProgressblock(task.progress); + } + + [super URLSession:session task:task didSendBodyData:bytesSent totalBytesSent:totalBytesSent totalBytesExpectedToSend:totalBytesExpectedToSend]; +} @end diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m b/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m index 9b488a77..42839239 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m @@ -54,6 +54,8 @@ - (instancetype)initWithSession:(NSURLSession *)session request:(NSURLRequest *) } + + # pragma mark - Public - (void)updateSession:(NSURLSession *)session @@ -218,6 +220,7 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSend self.didSendBodyDataBlock(session, task, bytesSent, totalBytesSent, totalBytesExpectedToSend); }); } + } @@ -232,4 +235,7 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp } } + +//- (void)URLSe + @end diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.h b/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.h index aee49747..317f6fce 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.h +++ b/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.h @@ -14,6 +14,7 @@ #import "MASSecurityPolicy.h" #import "MASSessionDataTaskOperation.h" #import "MASURLRequest.h" +#import "MASPostFormURLRequest.h" // // NSURLSessionDelegate @@ -81,6 +82,7 @@ typedef void (^MASNetworkSessionDidFinishEventsForBackgroundURLSessionBlock)(NSU - (MASSessionDataTaskOperation *)dataOperationWithRequest:(MASURLRequest *)request completionHandler:(MASSessionDataTaskCompletionBlock)completionHandler; +-(MASSessionDataTaskOperation *)fileUploadOperation:(MASURLRequest *)request progress:(MASFileRequestProgressBlock)progress completionHandler:(MASSessionDataTaskCompletionBlock)completionHandler; ///-------------------------------------- /// @name Public diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.m b/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.m index e96ff1dc..e3181367 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.m @@ -12,6 +12,8 @@ #import "MASSecurityService.h" +#import "MASPostFormURLRequest.h" + @interface MASURLSessionManager () @property (readwrite, nonatomic, strong) NSURLSession *session; @@ -168,6 +170,23 @@ - (MASSessionDataTaskOperation *)dataOperationWithRequest:(MASURLRequest *)reque return dataTask; } +-(MASSessionDataTaskOperation *)fileUploadOperation:(MASURLRequest *)request progress:(MASFileRequestProgressBlock)progress completionHandler:(MASSessionDataTaskCompletionBlock)completionHandler +{ + MASSessionDataTaskOperation *dataTask = [[MASSessionDataTaskOperation alloc] initWithSession:_session request:request progress:progress]; + + [self.operations addObject:dataTask]; + + dataTask.didCompleteWithDataErrorBlock = ^(NSURLSession *session, NSURLSessionTask *task, NSData *data, NSError *error) { + + if (completionHandler) + { + completionHandler(task.response, data, error); + } + }; + + return dataTask; +} + # pragma mark - NSOperationQueue diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h new file mode 100644 index 00000000..0fb6a343 --- /dev/null +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h @@ -0,0 +1,20 @@ +// +// MASPostFormURLRequest.h +// MASFoundation +// +// Created by nimma01 on 12/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import "MASURLRequest.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MASPostFormURLRequest : MASURLRequest + + ++ (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock; + +@end + +NS_ASSUME_NONNULL_END diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m new file mode 100644 index 00000000..da724f1b --- /dev/null +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m @@ -0,0 +1,67 @@ +// +// MASPostFormURLRequest.m +// MASFoundation +// +// Created by nimma01 on 12/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import "MASPostFormURLRequest.h" +#import "MASMultiPartRequestSerializer.h" + + +#define kMASHTTPPostRequestMethod @"POST" + +@implementation MASPostFormURLRequest + + ++ (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock +{ + // + // Adding prefix to the endpoint path + // + if ([MASConfiguration currentConfiguration].gatewayPrefix && ![endPoint hasPrefix:@"http://"] && ![endPoint hasPrefix:@"https://"]) + { + endPoint = [NSString stringWithFormat:@"%@%@",[MASConfiguration currentConfiguration].gatewayPrefix, endPoint]; + } + + // + // Full URL path (no query parameters go here) + // + NSURL *url = [NSURL URLWithString:endPoint relativeToURL:[MASConfiguration currentConfiguration].gatewayUrl]; + + NSAssert(url, @"URL cannot be nil"); + + // + // Create the request + // + MASPostFormURLRequest *request = [MASPostFormURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:240]; + + // + // Method + // + [request setHTTPMethod:kMASHTTPPostRequestMethod]; + + [request setHeaderInfo:headerInfo forRequestType:requestType andResponseType:responseType]; + + // + // capture request + // + request.isPublic = isPublic; + request.requestType = requestType; + request.responseType = responseType; + request.headerInfo = headerInfo; + request.parameterInfo = parameterInfo; + request.endPoint = endPoint; + + __block MASMultiPartRequestSerializer* formData = [[MASMultiPartRequestSerializer alloc] initWithURLRequest:request]; + + if(formDataBlock){ + formDataBlock(formData); + } + + return [formData requestByFinalizingMultipartFormData]; + + +} +@end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m index 06f16d11..c8304053 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m @@ -70,14 +70,15 @@ + (MASPostURLRequest *)requestForEndpoint:(NSString *)endPoint // Body ... format the parameter dictionary to data for the request type if there is anything // to format. It's possible there isn't. // - NSData *data = [self dataForBodyFromParameterInfo:parameterInfo forRequestType:requestType]; + // THIS PART Is not needed. Confirm from testing + /* NSData *data = [self dataForBodyFromParameterInfo:parameterInfo forRequestType:requestType]; if(data) { // // Set the body with the data // [request setHTTPBody:data]; - } + }*/ return request; } diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.m index cb982295..745234da 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.m @@ -15,6 +15,7 @@ NSString * const MASRequestResponseTypeTextPlainValue = @"text/plain"; NSString * const MASRequestResponseTypeWwwFormUrlEncodedValue = @"application/x-www-form-urlencoded"; NSString * const MASRequestResponseTypeXmlValue = @"application/xml"; +NSString * const MASRequestResponseTypeFormDataValue = @"multipart/form-data"; @implementation MASURLRequest diff --git a/MASFoundation/Classes/models/Network/MASFileRequest.h b/MASFoundation/Classes/models/Network/MASFileRequest.h new file mode 100644 index 00000000..629a1e37 --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASFileRequest.h @@ -0,0 +1,19 @@ +// +// MASFileRequest.h +// MASFoundation +// +// Created by nimma01 on 09/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface MASFileRequest : MASRequest + +@property(nonatomic) NSString* boundary; + +@end + +NS_ASSUME_NONNULL_END diff --git a/MASFoundation/Classes/models/Network/MASFileRequest.m b/MASFoundation/Classes/models/Network/MASFileRequest.m new file mode 100644 index 00000000..31a9c7ed --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASFileRequest.m @@ -0,0 +1,13 @@ +// +// MASFileRequest.m +// MASFoundation +// +// Created by nimma01 on 09/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import "MASFileRequest.h" + +@implementation MASFileRequest + +@end diff --git a/MASFoundation/Classes/models/Network/MASFileRequestBuilder.h b/MASFoundation/Classes/models/Network/MASFileRequestBuilder.h new file mode 100644 index 00000000..c4cb3c02 --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASFileRequestBuilder.h @@ -0,0 +1,32 @@ +// +// MASFileRequestBuilder.h +// MASFoundation +// +// Created by nimma01 on 09/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import +#import "MASFileRequest.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MASFileRequestBuilder : MASRequestBuilder + + +@property (nonatomic) NSString* boundary; + +//@property (nonatomic) +/** + Create a MASFileRequest object using the parameters from MASRequestBuider + + @return MASFileRequest object + */ +- (MASFileRequest *_Nullable)build; + + + + +@end + +NS_ASSUME_NONNULL_END diff --git a/MASFoundation/Classes/models/Network/MASFileRequestBuilder.m b/MASFoundation/Classes/models/Network/MASFileRequestBuilder.m new file mode 100644 index 00000000..cc0f2a78 --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASFileRequestBuilder.m @@ -0,0 +1,13 @@ +// +// MASFileRequestBuilder.m +// MASFoundation +// +// Created by nimma01 on 09/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import "MASFileRequestBuilder.h" + +@implementation MASFileRequestBuilder + +@end diff --git a/MASFoundation/Classes/models/Network/MASMultiPartFormData.h b/MASFoundation/Classes/models/Network/MASMultiPartFormData.h new file mode 100644 index 00000000..950f002b --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASMultiPartFormData.h @@ -0,0 +1,63 @@ +// +// MASMultiPartFormData.h +// MASFoundation +// +// Created by nimma01 on 11/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#ifndef MASMultiPartFormData_h +#define MASMultiPartFormData_h + +@protocol MASMultiPartFormData + + +/** + Appends the HTTP header `Content-Disposition: file; filename=#{generated filename}; name=#{name}"` and `Content-Type: #{generated mimeType}`, followed by the encoded file data and the multipart form boundary. + + The filename and MIME type for this data in the form will be automatically generated, using the last path component of the `fileURL` and system associated MIME type for the `fileURL` extension, respectively. + + @param fileURL The URL corresponding to the file whose content will be appended to the form. This parameter must not be `nil`. + @param name The name to be associated with the specified data. This parameter must not be `nil`. + @param error If an error occurs, upon return contains an `NSError` object that describes the problem. + + @return `YES` if the file data was successfully appended, otherwise `NO`. + */ +- (BOOL)appendPartWithFileURL:(NSURL * __nonnull)fileURL name:(NSString * __nonnull)name error:(NSError *_Nullable* _Nullable)error; + + +/** + Appends the HTTP header `Content-Disposition: file; filename=#{filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary. + + @param fileURL The URL corresponding to the file whose content will be appended to the form. This parameter must not be `nil`. + @param name The name to be associated with the specified data. This parameter must not be `nil`. + @param fileName The file name to be used in the `Content-Disposition` header. This parameter must not be `nil`. + @param mimeType The declared MIME type of the file data. This parameter must not be `nil`. + @param error If an error occurs, upon return contains an `NSError` object that describes the problem. + + @return `YES` if the file data was successfully appended otherwise `NO`. + */ +- (BOOL)appendPartWithFileURL:(NSURL * __nonnull)fileURL name:(NSString * __nonnull)name fileName:(NSString * __nonnull)fileName mimeType:(NSString * __nonnull)mimeType error:(NSError *_Nullable* _Nullable)error; + + +/** + Appends the HTTP header `Content-Disposition: file; filename=#{filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary. + + @param data The data to be encoded and appended to the form data. + @param name The name to be associated with the specified data. This parameter must not be `nil`. + @param fileName The filename to be associated with the specified data. This parameter must not be `nil`. + @param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`. + */ +- (void)appendPartWithFileData:(NSData * __nonnull)data name:(NSString * __nonnull)name fileName:(NSString * __nonnull)fileName mimeType:(NSString * __nonnull)mimeType; + +/** + Appends the HTTP headers `Content-Disposition: form-data; name=#{name}"`, followed by the encoded data and the multipart form boundary. + + @param data The data to be encoded and appended to the form data. + @param name The name to be associated with the specified data. This parameter must not be `nil`. + */ + +- (void)appendPartWithFormData:(NSData * __nonnull)data name:(NSString * __nonnull)name; + +@end +#endif /* MASMultiPartFormData_h */ diff --git a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h new file mode 100644 index 00000000..3c68e440 --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h @@ -0,0 +1,23 @@ +// +// MASMultiPartRequestSerializer.h +// MASFoundation +// +// Created by nimma01 on 11/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import +#import "MASMultiPartFormData.h" +#import "MASPostFormURLRequest.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MASMultiPartRequestSerializer : NSObject + +- (id)initWithURLRequest:(MASPostFormURLRequest *)request; + +- (MASPostFormURLRequest *)requestByFinalizingMultipartFormData; + +@end + +NS_ASSUME_NONNULL_END diff --git a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m new file mode 100644 index 00000000..cde4bc0e --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m @@ -0,0 +1,144 @@ +// +// MASMultiPartRequestSerializer.m +// MASFoundation +// +// Created by nimma01 on 11/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import "MASMultiPartRequestSerializer.h" +#import + +@interface MASMultiPartRequestSerializer() +{ + +} + +@property(nonatomic) NSString* boundary; +@property(nonatomic) NSMutableData* body; +@property(nonatomic) MASURLRequest* request; + +@end + +static NSString * MASCreateMultipartFormBoundary() { + return [NSString stringWithFormat:@"Boundary+%08X%08X", arc4random(), arc4random()]; +} + + +static inline NSString * MASMultipartFormEncapsulationBoundary(NSString *boundary) { + return [NSString stringWithFormat:@"%@--%@%@", @"\r\n", boundary, @"\r\n"]; +} + + +static inline NSString * MASMultipartFormFinalBoundary(NSString *boundary) { + return [NSString stringWithFormat:@"%@--%@--%@", @"\r\n", boundary, @"\r\n"]; +} + +static inline NSString * MASContentTypeForPathExtension(NSString *extension) { +#ifdef __UTTYPE__ + NSString *UTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)extension, NULL); + NSString *contentType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)UTI, kUTTagClassMIMEType); + if (!contentType) { + return @"application/octet-stream"; + } else { + return contentType; + } +#else +#pragma unused (extension) + return @"application/octet-stream"; +#endif +} + +@implementation MASMultiPartRequestSerializer + + +- (id)initWithURLRequest:(MASPostFormURLRequest *)request +{ + if(self = [super init]) + { + self.request = request; + self.boundary = MASCreateMultipartFormBoundary(); + self.body = [NSMutableData data]; + [self setInitialHeadersforRequest]; + [self setBodyParameters]; + + } + + return self; +} + +-(void)setInitialHeadersforRequest +{ + NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", self.boundary]; + [self.request addValue:contentType forHTTPHeaderField:@"Content-Type"]; +} + + +-(void)setBodyParameters +{ + [self.request.parameterInfo enumerateKeysAndObjectsUsingBlock:^(NSString *parameterKey, NSString *parameterValue, BOOL *stop) { + [self.body appendData:[[NSString stringWithFormat:@"%@", self.boundary] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", parameterKey] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"%@\r\n", parameterValue] dataUsingEncoding:NSUTF8StringEncoding]]; + }]; +} + + +- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError *__autoreleasing _Nullable *)error +{ + return [self appendPartWithFileURL:fileURL name:name fileName:name mimeType:MASContentTypeForPathExtension([fileURL pathExtension]) error:error]; +} + +- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType error:(NSError *__autoreleasing _Nullable *)error +{ + if(!fileURL || !name) + { + return NO; + } + + [self.body appendData:[[NSString stringWithFormat:@"%@", MASMultipartFormEncapsulationBoundary(self.boundary)] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", name, fileName] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", mimeType] dataUsingEncoding:NSUTF8StringEncoding]]; + NSData* data = [NSData dataWithContentsOfURL:fileURL]; + [self.body appendData:data]; + [self.body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; + + + return YES; +} + + +- (void)appendPartWithFormData:(NSData *)data name:(NSString *)name +{ + [self.body appendData:[[NSString stringWithFormat:@"%@", MASMultipartFormEncapsulationBoundary(self.boundary)] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"", name] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:data]; +} + + +-(void)appendPartWithFileData:(NSData *)data name:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType +{ + [self.body appendData:[[NSString stringWithFormat:@"--%@\r\n", MASMultipartFormEncapsulationBoundary(self.boundary)] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", name, fileName] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", mimeType] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:data]; + [self.body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; +} + + +- (MASURLRequest *)requestByFinalizingMultipartFormData { + if (!self.body) { + return self.request; + } + + [self.body appendData:[[NSString stringWithFormat:@"%@", MASMultipartFormFinalBoundary(self.boundary)] dataUsingEncoding:NSUTF8StringEncoding]]; + + [self.request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", self.boundary] forHTTPHeaderField:@"Content-Type"]; + [self.request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[self.body length]] forHTTPHeaderField:@"Content-Length"]; + // Reset the initial and final boundaries to ensure correct Content-Length + [self.request setHTTPBody:self.body]; + + return self.request; +} + +@end diff --git a/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m b/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m index 4e28e867..1e43938e 100755 --- a/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m +++ b/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m @@ -111,6 +111,7 @@ - (BOOL)validateResponse:(NSHTTPURLResponse *)response NSError *validationError = nil; if (response && [response isKindOfClass:[NSHTTPURLResponse class]]) { + NSLog(@"response mime type is %@",[response MIMEType]); if (self.acceptableContentTypes && ![self.acceptableContentTypes containsObject:[response MIMEType]]) { if ([data length] > 0 && [response URL]) { NSMutableDictionary *mutableUserInfo = [@{ From 2d326b51b7174eff3376314943f0e4115f895b53 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Wed, 7 Aug 2019 14:54:11 +0530 Subject: [PATCH 02/10] fixed a bug in not setting mag identifier --- .../services/network/requests/MASPostFormURLRequest.m | 9 +++++++++ .../services/network/requests/MASPostURLRequest.m | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m index da724f1b..078833c9 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m @@ -64,4 +64,13 @@ + (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameter } + +- (MASURLRequest *)rebuildRequest +{ + [self setHeaderInfo:self.headerInfo forRequestType:self.requestType andResponseType:self.responseType]; + + return self; +} + + @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m index c8304053..daf0f7b8 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m @@ -71,14 +71,14 @@ + (MASPostURLRequest *)requestForEndpoint:(NSString *)endPoint // to format. It's possible there isn't. // // THIS PART Is not needed. Confirm from testing - /* NSData *data = [self dataForBodyFromParameterInfo:parameterInfo forRequestType:requestType]; + NSData *data = [self dataForBodyFromParameterInfo:parameterInfo forRequestType:requestType]; if(data) { // // Set the body with the data // [request setHTTPBody:data]; - }*/ + } return request; } From f97c6061bfe79436f00339ef3427ab2d0889273f Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Mon, 19 Aug 2019 15:29:40 +0530 Subject: [PATCH 03/10] fixed an issue where multi-part body boundary was missing from the headers --- .../network/requests/MASPostFormURLRequest.m | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m index 078833c9..fe2d6a04 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m @@ -73,4 +73,66 @@ - (MASURLRequest *)rebuildRequest } +//overriding the behavior for this class as the super class does not know about boundary string + +- (void)setHeaderInfo:(NSDictionary *)headerInfo forRequestType:(MASRequestResponseType)requestType andResponseType:(MASRequestResponseType)responseType +{ + + //don't set the request type as we don't want to disturb the boundary string + + // + // Accept based on MASRequestResponseType + // + [self setValue:[self requestResponseTypeAsMimeTypeString:responseType] forHTTPHeaderField:MASAcceptRequestResponseKey]; + + NSString *lowerKey; + NSString *value; + for(NSString *key in [headerInfo allKeys]) + { + lowerKey = [key lowercaseString]; + value = [headerInfo objectForKey:key]; + [self setValue:value forHTTPHeaderField:key]; + } +} + +//overriding the behavior for this class as the super class does not know about boundary string +- (NSString *)requestResponseTypeAsMimeTypeString:(MASRequestResponseType)type +{ + // + // Detect type and respond approriately + // + switch(type) + { + // + // JSON + // + case MASRequestResponseTypeJson: return MASRequestResponseTypeJsonValue; + + // + // SCIM variant JSON + // + case MASRequestResponseTypeScimJson: return MASRequestResponseTypeScimJsonValue; + + // + // Form URL Encoded + // + case MASRequestResponseTypeWwwFormUrlEncoded: return MASRequestResponseTypeWwwFormUrlEncodedValue; + + // + // XML + // + case MASRequestResponseTypeXml: return MASRequestResponseTypeXmlValue; + + case MASRequestResponseTypeFormData : return MASRequestResponseTypeFormDataValue; + + // + // Default + // + default: return MASRequestResponseTypeTextPlainValue; + } +} + + + + @end From aef4d9a21c47937c3d74fb7aa0ca125f68897314 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Tue, 20 Aug 2019 15:59:29 +0530 Subject: [PATCH 04/10] removed unnecessary files from the project --- MASFoundation.xcodeproj/project.pbxproj | 16 ---------- .../Classes/models/Network/MASFileRequest.h | 19 ----------- .../Classes/models/Network/MASFileRequest.m | 13 -------- .../models/Network/MASFileRequestBuilder.h | 32 ------------------- .../models/Network/MASFileRequestBuilder.m | 13 -------- 5 files changed, 93 deletions(-) delete mode 100644 MASFoundation/Classes/models/Network/MASFileRequest.h delete mode 100644 MASFoundation/Classes/models/Network/MASFileRequest.m delete mode 100644 MASFoundation/Classes/models/Network/MASFileRequestBuilder.h delete mode 100644 MASFoundation/Classes/models/Network/MASFileRequestBuilder.m diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index eb19eb0d..511a184e 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -185,15 +185,11 @@ C81CC3CD1FC2EA190058718E /* MASBrowserBasedAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */; }; C81CC3D01FC2EFBB0058718E /* UIAlertController+MAS.h in Headers */ = {isa = PBXBuildFile; fileRef = C81CC3CE1FC2EFBB0058718E /* UIAlertController+MAS.h */; }; C81CC3D11FC2EFBB0058718E /* UIAlertController+MAS.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CF1FC2EFBB0058718E /* UIAlertController+MAS.m */; }; - C850970C22D48E7E002182A0 /* MASFileRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = C850970A22D48E7E002182A0 /* MASFileRequest.h */; }; - C850970D22D48E7E002182A0 /* MASFileRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C850970B22D48E7E002182A0 /* MASFileRequest.m */; }; C8C32B0D22D706B900D64DF0 /* MASMultiPartFormData.h in Headers */ = {isa = PBXBuildFile; fileRef = C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */; settings = {ATTRIBUTES = (Public, ); }; }; C8C32B1022D7163100D64DF0 /* MASMultiPartRequestSerializer.h in Headers */ = {isa = PBXBuildFile; fileRef = C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */; }; C8C32B1122D7163100D64DF0 /* MASMultiPartRequestSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */; }; C8C32B1822D88BF100D64DF0 /* MASPostFormURLRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = C8C32B1622D88BF100D64DF0 /* MASPostFormURLRequest.h */; }; C8C32B1922D88BF100D64DF0 /* MASPostFormURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C8C32B1722D88BF100D64DF0 /* MASPostFormURLRequest.m */; }; - C8CEAFD222D48D32000B6C8A /* MASFileRequestBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = C8CEAFD022D48D32000B6C8A /* MASFileRequestBuilder.h */; }; - C8CEAFD322D48D32000B6C8A /* MASFileRequestBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = C8CEAFD122D48D32000B6C8A /* MASFileRequestBuilder.m */; }; CB0B58591E258C2A00BC0163 /* MASAuthorizationResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = CB0B58571E258C2A00BC0163 /* MASAuthorizationResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; CB0B585A1E258C2A00BC0163 /* MASAuthorizationResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = CB0B58581E258C2A00BC0163 /* MASAuthorizationResponse.m */; }; CB1907EF1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = CB1907ED1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h */; }; @@ -569,15 +565,11 @@ C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASBrowserBasedAuthentication.m; sourceTree = ""; }; C81CC3CE1FC2EFBB0058718E /* UIAlertController+MAS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIAlertController+MAS.h"; sourceTree = ""; }; C81CC3CF1FC2EFBB0058718E /* UIAlertController+MAS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIAlertController+MAS.m"; sourceTree = ""; }; - C850970A22D48E7E002182A0 /* MASFileRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASFileRequest.h; sourceTree = ""; }; - C850970B22D48E7E002182A0 /* MASFileRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASFileRequest.m; sourceTree = ""; }; C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASMultiPartFormData.h; sourceTree = ""; }; C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASMultiPartRequestSerializer.h; sourceTree = ""; }; C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASMultiPartRequestSerializer.m; sourceTree = ""; }; C8C32B1622D88BF100D64DF0 /* MASPostFormURLRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASPostFormURLRequest.h; sourceTree = ""; }; C8C32B1722D88BF100D64DF0 /* MASPostFormURLRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASPostFormURLRequest.m; sourceTree = ""; }; - C8CEAFD022D48D32000B6C8A /* MASFileRequestBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASFileRequestBuilder.h; sourceTree = ""; }; - C8CEAFD122D48D32000B6C8A /* MASFileRequestBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASFileRequestBuilder.m; sourceTree = ""; }; CB0B58571E258C2A00BC0163 /* MASAuthorizationResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASAuthorizationResponse.h; sourceTree = ""; }; CB0B58581E258C2A00BC0163 /* MASAuthorizationResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASAuthorizationResponse.m; sourceTree = ""; }; CB1907ED1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MASIKeyChainStore+MASPrivate.h"; sourceTree = ""; }; @@ -1247,10 +1239,6 @@ 699C17901F9585BC008C1B11 /* MASRequest.m */, 699C17921F9585BC008C1B11 /* MASRequestBuilder.h */, 699C17931F9585BD008C1B11 /* MASRequestBuilder.m */, - C8CEAFD022D48D32000B6C8A /* MASFileRequestBuilder.h */, - C8CEAFD122D48D32000B6C8A /* MASFileRequestBuilder.m */, - C850970A22D48E7E002182A0 /* MASFileRequest.h */, - C850970B22D48E7E002182A0 /* MASFileRequest.m */, C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */, C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */, C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */, @@ -1578,7 +1566,6 @@ CBD25B0C1E78C47C00DFB47F /* JWTBase64Coder.h in Headers */, A419B3A11C176259008DC88C /* NSData+MAS.h in Headers */, A488CE751C0B97FD00B8B961 /* MASService.h in Headers */, - C8CEAFD222D48D32000B6C8A /* MASFileRequestBuilder.h in Headers */, CB6491FB1FE9DAF300281288 /* MQTTSSLSecurityPolicy.h in Headers */, CBD25B0B1E78C47C00DFB47F /* JWT.h in Headers */, CBD25B091E78C47C00DFB47F /* JWTCoding.h in Headers */, @@ -1725,7 +1712,6 @@ 10E027A61F72B10100EAB103 /* RNEncryptor.h in Headers */, CB6491E01FE9DAF300281288 /* MQTTCFSocketEncoder.h in Headers */, CBD25AFB1E78C47C00DFB47F /* JWTClaimsSet.h in Headers */, - C850970C22D48E7E002182A0 /* MASFileRequest.h in Headers */, CB6491F11FE9DAF300281288 /* MQTTProperties.h in Headers */, 69B7DF6C1F96756B0056DD3A /* MASRequest+MASPrivate.h in Headers */, A417BA511BF033C300EC9BCB /* CLLocation+MASPrivate.h in Headers */, @@ -1883,7 +1869,6 @@ CB99754F1EDF5837006CEBB1 /* MASAuthCredentialsAuthorizationCode.m in Sources */, A488CE761C0B97FD00B8B961 /* MASService.m in Sources */, A42A86A11BBDA27F00AE98AC /* NSError+MASPrivate.m in Sources */, - C8CEAFD322D48D32000B6C8A /* MASFileRequestBuilder.m in Sources */, A450BC0C1BE1570C0030491F /* NSNotificationCenter+MASPrivate.m in Sources */, A46F49F41C2F5FC500A4C370 /* MASIOrderedDictionary.m in Sources */, CB1907F01C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.m in Sources */, @@ -2025,7 +2010,6 @@ A46F49D61C2F5FC500A4C370 /* MASIURLResponseSerialization.m in Sources */, CB1907F91C17950700A5EF16 /* MASAccessService.m in Sources */, CBD25B0A1E78C47C00DFB47F /* JWTCoding.m in Sources */, - C850970D22D48E7E002182A0 /* MASFileRequest.m in Sources */, CBD25B101E78C47C00DFB47F /* JWTErrorDescription.m in Sources */, CB5E4C6D1C1D2467001B3B8A /* MASDeleteURLRequest.m in Sources */, A46F49CE1C2F5FC500A4C370 /* MASINetworkReachabilityManager.m in Sources */, diff --git a/MASFoundation/Classes/models/Network/MASFileRequest.h b/MASFoundation/Classes/models/Network/MASFileRequest.h deleted file mode 100644 index 629a1e37..00000000 --- a/MASFoundation/Classes/models/Network/MASFileRequest.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// MASFileRequest.h -// MASFoundation -// -// Created by nimma01 on 09/07/19. -// Copyright © 2019 CA Technologies. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface MASFileRequest : MASRequest - -@property(nonatomic) NSString* boundary; - -@end - -NS_ASSUME_NONNULL_END diff --git a/MASFoundation/Classes/models/Network/MASFileRequest.m b/MASFoundation/Classes/models/Network/MASFileRequest.m deleted file mode 100644 index 31a9c7ed..00000000 --- a/MASFoundation/Classes/models/Network/MASFileRequest.m +++ /dev/null @@ -1,13 +0,0 @@ -// -// MASFileRequest.m -// MASFoundation -// -// Created by nimma01 on 09/07/19. -// Copyright © 2019 CA Technologies. All rights reserved. -// - -#import "MASFileRequest.h" - -@implementation MASFileRequest - -@end diff --git a/MASFoundation/Classes/models/Network/MASFileRequestBuilder.h b/MASFoundation/Classes/models/Network/MASFileRequestBuilder.h deleted file mode 100644 index c4cb3c02..00000000 --- a/MASFoundation/Classes/models/Network/MASFileRequestBuilder.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// MASFileRequestBuilder.h -// MASFoundation -// -// Created by nimma01 on 09/07/19. -// Copyright © 2019 CA Technologies. All rights reserved. -// - -#import -#import "MASFileRequest.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface MASFileRequestBuilder : MASRequestBuilder - - -@property (nonatomic) NSString* boundary; - -//@property (nonatomic) -/** - Create a MASFileRequest object using the parameters from MASRequestBuider - - @return MASFileRequest object - */ -- (MASFileRequest *_Nullable)build; - - - - -@end - -NS_ASSUME_NONNULL_END diff --git a/MASFoundation/Classes/models/Network/MASFileRequestBuilder.m b/MASFoundation/Classes/models/Network/MASFileRequestBuilder.m deleted file mode 100644 index cc0f2a78..00000000 --- a/MASFoundation/Classes/models/Network/MASFileRequestBuilder.m +++ /dev/null @@ -1,13 +0,0 @@ -// -// MASFileRequestBuilder.m -// MASFoundation -// -// Created by nimma01 on 09/07/19. -// Copyright © 2019 CA Technologies. All rights reserved. -// - -#import "MASFileRequestBuilder.h" - -@implementation MASFileRequestBuilder - -@end From 4dc7d1479494eb4cbb70478f103b1ec387986c05 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Tue, 20 Aug 2019 16:02:48 +0530 Subject: [PATCH 05/10] rectified unwanted change in security policy --- .../_private_/services/network/internal/MASSecurityPolicy.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m index 2dad57f1..78b0e5ff 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m @@ -51,8 +51,7 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo // if (securityConfiguration == nil) { - //return NO; - return YES; + return NO; } NSMutableArray *policies = [NSMutableArray array]; From a93d3c83121d25b215e1564e6f4a358bbf694de6 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Tue, 20 Aug 2019 16:06:48 +0530 Subject: [PATCH 06/10] removed unnecessary params --- .../services/network/internal/MASSessionDataTaskOperation.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m b/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m index 550969bc..7889c12a 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m @@ -21,7 +21,7 @@ @interface MASSessionDataTaskOperation () @property (nonatomic, strong) NSMutableData *responseData; @property (nonatomic, strong) NSError *error; -@property (nonatomic) long long didSendBodyDataBlock; +@property (nonatomic) long long totalBytesExpected; @property (nonatomic) long long bytesReceived; @property (nonatomic, readwrite, getter = isFinished) BOOL finished; @@ -210,7 +210,6 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler { - NSLog(@"did receive content disposition"); NSURLSessionResponseDisposition disposition = NSURLSessionResponseAllow; if (self.didReceiveResponseBlock) From c597904cef6c07bf48ea3756cfcd55564e6783ce Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Tue, 20 Aug 2019 16:09:24 +0530 Subject: [PATCH 07/10] undid few changes --- .../services/network/internal/MASSessionTaskOperation.m | 2 -- .../_private_/services/network/requests/MASPostURLRequest.m | 1 - .../Vendor/MASINetworking/MASIURLResponseSerialization.m | 1 - 3 files changed, 4 deletions(-) diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m b/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m index 42839239..db685612 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m @@ -236,6 +236,4 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp } -//- (void)URLSe - @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m index daf0f7b8..06f16d11 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m @@ -70,7 +70,6 @@ + (MASPostURLRequest *)requestForEndpoint:(NSString *)endPoint // Body ... format the parameter dictionary to data for the request type if there is anything // to format. It's possible there isn't. // - // THIS PART Is not needed. Confirm from testing NSData *data = [self dataForBodyFromParameterInfo:parameterInfo forRequestType:requestType]; if(data) { diff --git a/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m b/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m index 1e43938e..4e28e867 100755 --- a/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m +++ b/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m @@ -111,7 +111,6 @@ - (BOOL)validateResponse:(NSHTTPURLResponse *)response NSError *validationError = nil; if (response && [response isKindOfClass:[NSHTTPURLResponse class]]) { - NSLog(@"response mime type is %@",[response MIMEType]); if (self.acceptableContentTypes && ![self.acceptableContentTypes containsObject:[response MIMEType]]) { if ([data length] > 0 && [response URL]) { NSMutableDictionary *mutableUserInfo = [@{ From 784c680da0c164534bfd60db96e5a52aa0dc7fa1 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Wed, 21 Aug 2019 16:31:28 +0530 Subject: [PATCH 08/10] throwing an error form the API if the request is not in the proper format for multi-part file upload --- MASFoundation/Classes/MAS.m | 7 +++++++ MASFoundation/Classes/MASError.h | 6 ++++++ .../Classes/_private_/categories/NSError+MASPrivate.h | 9 +++++++++ .../Classes/_private_/categories/NSError+MASPrivate.m | 11 +++++++++++ 4 files changed, 33 insertions(+) diff --git a/MASFoundation/Classes/MAS.m b/MASFoundation/Classes/MAS.m index caa5ffe7..dce1cdee 100644 --- a/MASFoundation/Classes/MAS.m +++ b/MASFoundation/Classes/MAS.m @@ -1130,6 +1130,13 @@ + (void)invoke:(nonnull MASRequest *)request completion:(nullable MASResponseObj + (void)upload:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull MASMultiPartFormDataBlock)formDatablock progress:( MASFileRequestProgressBlock _Nullable )progressBlock completion:(nullable MASResponseObjectErrorBlock)completion { + if(![request.httpMethod isEqualToString:@"POST"] || request.requestType != MASRequestResponseTypeFormData) + { + NSError* error = [NSError errorInvalidRequestForFileUpload]; + completion(nil,nil,error); + return; + } + [MAS checkAndValidateRequestScope:request.endPoint headerInfo:request.header isPublic:request.isPublic completion:^(BOOL completed, NSError *error) { if(!completed){ diff --git a/MASFoundation/Classes/MASError.h b/MASFoundation/Classes/MASError.h index 2b26156d..8a12dbe4 100644 --- a/MASFoundation/Classes/MASError.h +++ b/MASFoundation/Classes/MASError.h @@ -99,6 +99,7 @@ typedef NS_ENUM(NSInteger, MASFoundationErrorCode) MASFoundationErrorCodeResponseSerializationFailedToParseResponse = 100407, MASFoundationErrorCodeNetworkSSLAuthenticationChallengeFailure = 100408, + // // Application // @@ -198,6 +199,11 @@ typedef NS_ENUM(NSInteger, MASFoundationErrorCode) MASFoundationErrorCodeMultiFactorAuthenticationCancelled = 180002, MASFoundationErrorCodeMultiFactorAuthenticationInvalidRequest = 180003, + // + // File Request Errors + // + MASFoundationErrorCodeInvalidRequestForFileUpload = 180100, + MASFoundationErrorCodeCount = -999999 }; diff --git a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.h b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.h index 91029b35..dc59163f 100644 --- a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.h +++ b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.h @@ -647,4 +647,13 @@ */ + (NSError *)errorBrowserBasedAuthenticaionNotEnabled; + +/** + * Create MASFoundationErrorDomainLocal NSError for MASFoundationErrorCodeInvalidRequestForFileUpload. + * + * @return Returns an NSError instance with the domain MASFoundationErrorDomainLocal and + * error MASFoundationErrorCodeInvalidRequestForFileUpload + */ ++ (NSError *)errorInvalidRequestForFileUpload; + @end diff --git a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m index 3219ff6d..f77e5b88 100644 --- a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m +++ b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m @@ -833,6 +833,11 @@ + (NSError *)errorBrowserBasedAuthenticaionNotEnabled return [self errorForFoundationCode:MASFoundationErrorCodeBBANotEnabled errorDomain:MASFoundationErrorDomainLocal]; } ++ (NSError *)errorInvalidRequestForFileUpload +{ + return [self errorForFoundationCode:MASFoundationErrorCodeInvalidRequestForFileUpload errorDomain:MASFoundationErrorDomainLocal]; +} + # pragma mark - Foundation Errors Private @@ -1098,6 +1103,12 @@ + (NSString *)descriptionForFoundationErrorCode:(MASFoundationErrorCode)errorCod case MASFoundationErrorCodeMultiFactorAuthenticationCancelled : return @"Multi factor authentication process has been cancelled."; case MASFoundationErrorCodeMultiFactorAuthenticationInvalidRequest : return @"Invalid request for multi factor authentication."; + // + // File Request Errors + // + + case MASFoundationErrorCodeInvalidRequestForFileUpload : return @"the MASRequest is not valid for multi-part file upload. Please check if the request is of method POST and the request type is MASRequestResponseTypeFormData."; + // // Default // From 1341edda4ba914af9c4af0ad922d8181433cd695 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Mon, 26 Aug 2019 15:51:12 +0530 Subject: [PATCH 09/10] changed license part in headers --- .../network/requests/MASPostFormURLRequest.h | 5 +++- .../models/Network/MASMultiPartFormData.h | 23 +++---------------- .../Network/MASMultiPartRequestSerializer.h | 4 +++- .../Network/MASMultiPartRequestSerializer.m | 4 +++- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h index 0fb6a343..880a8439 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h @@ -2,9 +2,12 @@ // MASPostFormURLRequest.h // MASFoundation // -// Created by nimma01 on 12/07/19. // Copyright © 2019 CA Technologies. All rights reserved. // +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// + #import "MASURLRequest.h" diff --git a/MASFoundation/Classes/models/Network/MASMultiPartFormData.h b/MASFoundation/Classes/models/Network/MASMultiPartFormData.h index 950f002b..ff81528c 100644 --- a/MASFoundation/Classes/models/Network/MASMultiPartFormData.h +++ b/MASFoundation/Classes/models/Network/MASMultiPartFormData.h @@ -2,9 +2,11 @@ // MASMultiPartFormData.h // MASFoundation // -// Created by nimma01 on 11/07/19. // Copyright © 2019 CA Technologies. All rights reserved. // +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// #ifndef MASMultiPartFormData_h #define MASMultiPartFormData_h @@ -40,24 +42,5 @@ - (BOOL)appendPartWithFileURL:(NSURL * __nonnull)fileURL name:(NSString * __nonnull)name fileName:(NSString * __nonnull)fileName mimeType:(NSString * __nonnull)mimeType error:(NSError *_Nullable* _Nullable)error; -/** - Appends the HTTP header `Content-Disposition: file; filename=#{filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary. - - @param data The data to be encoded and appended to the form data. - @param name The name to be associated with the specified data. This parameter must not be `nil`. - @param fileName The filename to be associated with the specified data. This parameter must not be `nil`. - @param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`. - */ -- (void)appendPartWithFileData:(NSData * __nonnull)data name:(NSString * __nonnull)name fileName:(NSString * __nonnull)fileName mimeType:(NSString * __nonnull)mimeType; - -/** - Appends the HTTP headers `Content-Disposition: form-data; name=#{name}"`, followed by the encoded data and the multipart form boundary. - - @param data The data to be encoded and appended to the form data. - @param name The name to be associated with the specified data. This parameter must not be `nil`. - */ - -- (void)appendPartWithFormData:(NSData * __nonnull)data name:(NSString * __nonnull)name; - @end #endif /* MASMultiPartFormData_h */ diff --git a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h index 3c68e440..939b30e5 100644 --- a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h +++ b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h @@ -2,9 +2,11 @@ // MASMultiPartRequestSerializer.h // MASFoundation // -// Created by nimma01 on 11/07/19. // Copyright © 2019 CA Technologies. All rights reserved. // +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// #import #import "MASMultiPartFormData.h" diff --git a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m index cde4bc0e..224a1a72 100644 --- a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m +++ b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m @@ -2,9 +2,11 @@ // MASMultiPartRequestSerializer.m // MASFoundation // -// Created by nimma01 on 11/07/19. // Copyright © 2019 CA Technologies. All rights reserved. // +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// #import "MASMultiPartRequestSerializer.h" #import From 3d62b7e4c36bcc19a6a29c3738a61932b68796aa Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Tue, 27 Aug 2019 11:11:48 +0530 Subject: [PATCH 10/10] changed public API name to postMultiPartForm --- MASFoundation/Classes/MAS.h | 26 +++++++++++++++++++++++++- MASFoundation/Classes/MAS.m | 4 ++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/MASFoundation/Classes/MAS.h b/MASFoundation/Classes/MAS.h index 8719ae97..1c4e6e3c 100644 --- a/MASFoundation/Classes/MAS.h +++ b/MASFoundation/Classes/MAS.h @@ -1062,7 +1062,31 @@ withParameters:(NSDictionary *_Nullable)parameterInfo # pragma mark - FILE Requests -+ (void)upload:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull MASMultiPartFormDataBlock)formDatablock progress:( MASFileRequestProgressBlock _Nullable )progressBlock completion:(nullable MASResponseObjectErrorBlock)completion; +/** + * Post a multi-part form with the parameters defined in the MASRequest object + * + * If endPointPath is full URL format (including port number and http protocol), SDK will validate the server from the client side through SSL pinning (authentication challenge) with + * provided subjectKeyHash (also known as public key hash) in configuration in mag.mobile_sdk.trusted_cert_pinned_public_key_hashes and mag.mobile_sdk.enable_public_key_pinning. + * ALL of servers' public key hashes in certificate chain must be defined in the list. This means when it is configured to use public key hash pinning for SSL pinning, + * subjectKeyHash (public key hash) of the gateway must be also present within the list. The list can contain multiple hash values in array for multiple servers. + * + * When SDK fails to validate SSL with certificate or subjectKeyHash pinning for communication to HTTPs, SDK will cancel the request. + * + * If endPointPath is full URL format, upon successful SSL pinning validation, SDK will also validate the user session against primary gateway regardless the request is being made + * to the primary gateway or not. To ensure bypass the user session validation for public API, use [MAS deleteFrom:withParameters:requestType:responseType:isPublic:completion:] method + * with isPublic being YES. + * + * The API appends the file data and any other parameters to the body and follows the standards defined for Content-Type = multipart/form-data + * + * @param request MASRequest An object containing all parameters to call the endpoint + * When the value is set to true, all automatically injected credentials in SDK will be excluded in the request. + * @param formDataBlock This is a block that gets called while constructing the body of the multi-part form request. Typically files can be added to the body by calling various APIs available in MASMultiPartFormData + * @see MASMultiPartFormData + * @param progressBlock Block which gives back the NSProgress of the task that is going on. Different values can be read from the progress object to present a meaningful progress updates in the UI. Recommend to use progress.fractioncompleted for progress bar updates. + * @param completion An MASResponseObjectErrorBlock (NSHTTPURLResponse *response, id responseObject, NSError *error) that will + * receive the NSHTTPURLResponse object, response object which needs to perform type casting based on the object type, and NSError object when error occurs. + */ ++ (void)postMultiPartForm:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:( MASFileRequestProgressBlock _Nullable )progressBlock completion:(nullable MASResponseObjectErrorBlock)completion; ///-------------------------------------- /// @name JWT Signing diff --git a/MASFoundation/Classes/MAS.m b/MASFoundation/Classes/MAS.m index dce1cdee..90197f61 100644 --- a/MASFoundation/Classes/MAS.m +++ b/MASFoundation/Classes/MAS.m @@ -1128,7 +1128,7 @@ + (void)invoke:(nonnull MASRequest *)request completion:(nullable MASResponseObj } -+ (void)upload:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull MASMultiPartFormDataBlock)formDatablock progress:( MASFileRequestProgressBlock _Nullable )progressBlock completion:(nullable MASResponseObjectErrorBlock)completion ++ (void)postMultiPartForm:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:( MASFileRequestProgressBlock _Nullable )progressBlock completion:(nullable MASResponseObjectErrorBlock)completion { if(![request.httpMethod isEqualToString:@"POST"] || request.requestType != MASRequestResponseTypeFormData) { @@ -1144,7 +1144,7 @@ + (void)upload:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull return; } - [[MASNetworkingService sharedService] postMultiPartForm:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic constructingBodyBlock:formDatablock progress:progressBlock completion:completion]; + [[MASNetworkingService sharedService] postMultiPartForm:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic constructingBodyBlock:formDataBlock progress:progressBlock completion:completion]; }]; }