Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions MASFoundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +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 */; };
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 */; };
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 */; };
Expand Down Expand Up @@ -560,6 +565,11 @@
C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASBrowserBasedAuthentication.m; sourceTree = "<group>"; };
C81CC3CE1FC2EFBB0058718E /* UIAlertController+MAS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIAlertController+MAS.h"; sourceTree = "<group>"; };
C81CC3CF1FC2EFBB0058718E /* UIAlertController+MAS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIAlertController+MAS.m"; sourceTree = "<group>"; };
C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASMultiPartFormData.h; sourceTree = "<group>"; };
C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASMultiPartRequestSerializer.h; sourceTree = "<group>"; };
C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASMultiPartRequestSerializer.m; sourceTree = "<group>"; };
C8C32B1622D88BF100D64DF0 /* MASPostFormURLRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASPostFormURLRequest.h; sourceTree = "<group>"; };
C8C32B1722D88BF100D64DF0 /* MASPostFormURLRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASPostFormURLRequest.m; sourceTree = "<group>"; };
CB0B58571E258C2A00BC0163 /* MASAuthorizationResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASAuthorizationResponse.h; sourceTree = "<group>"; };
CB0B58581E258C2A00BC0163 /* MASAuthorizationResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASAuthorizationResponse.m; sourceTree = "<group>"; };
CB1907ED1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MASIKeyChainStore+MASPrivate.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -897,6 +907,8 @@
CB5E4C671C1D21FB001B3B8A /* MASPostURLRequest.m */,
CB5E4C6E1C1D250D001B3B8A /* MASPutURLRequest.h */,
CB5E4C6F1C1D250D001B3B8A /* MASPutURLRequest.m */,
C8C32B1622D88BF100D64DF0 /* MASPostFormURLRequest.h */,
C8C32B1722D88BF100D64DF0 /* MASPostFormURLRequest.m */,
);
path = requests;
sourceTree = "<group>";
Expand Down Expand Up @@ -1227,6 +1239,9 @@
699C17901F9585BC008C1B11 /* MASRequest.m */,
699C17921F9585BC008C1B11 /* MASRequestBuilder.h */,
699C17931F9585BD008C1B11 /* MASRequestBuilder.m */,
C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */,
C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */,
C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */,
);
path = Network;
sourceTree = "<group>";
Expand Down Expand Up @@ -1530,6 +1545,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 */,
Expand Down Expand Up @@ -1624,6 +1640,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 */,
Expand Down Expand Up @@ -1675,6 +1692,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 */,
Expand Down Expand Up @@ -1905,6 +1923,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 */,
Expand Down Expand Up @@ -1949,6 +1968,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 */,
Expand Down
29 changes: 29 additions & 0 deletions MASFoundation/Classes/MAS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1059,6 +1060,34 @@ withParameters:(NSDictionary *_Nullable)parameterInfo



# pragma mark - FILE Requests

/**
* 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
///--------------------------------------
Expand Down
58 changes: 58 additions & 0 deletions MASFoundation/Classes/MAS.m
Original file line number Diff line number Diff line change
Expand Up @@ -1128,8 +1128,66 @@ + (void)invoke:(nonnull MASRequest *)request completion:(nullable MASResponseObj
}


+ (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)
{
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){
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
Expand Down
16 changes: 16 additions & 0 deletions MASFoundation/Classes/MASConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@class CLLocation;
@class MASAuthCredentials;
@class MASUser;
@protocol MASMultiPartFormData;


/**
Expand Down Expand Up @@ -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 <MASMultiPartFormData> _Nonnull formData);

/**
* The MASAuthCredentialsBlcok to provide auth credentials for device registration and/or user authentication.
Expand Down Expand Up @@ -240,6 +251,11 @@ typedef NS_ENUM(NSInteger, MASRequestResponseType)
*/
MASRequestResponseTypeXml,

/**
* Standard Multi-part form data
*/
MASRequestResponseTypeFormData,

/**
* The total number of supported types.
*/
Expand Down
6 changes: 6 additions & 0 deletions MASFoundation/Classes/MASError.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ typedef NS_ENUM(NSInteger, MASFoundationErrorCode)
MASFoundationErrorCodeResponseSerializationFailedToParseResponse = 100407,
MASFoundationErrorCodeNetworkSSLAuthenticationChallengeFailure = 100408,


//
// Application
//
Expand Down Expand Up @@ -198,6 +199,11 @@ typedef NS_ENUM(NSInteger, MASFoundationErrorCode)
MASFoundationErrorCodeMultiFactorAuthenticationCancelled = 180002,
MASFoundationErrorCodeMultiFactorAuthenticationInvalidRequest = 180003,

//
// File Request Errors
//
MASFoundationErrorCodeInvalidRequestForFileUpload = 180100,

MASFoundationErrorCodeCount = -999999
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ - (NSString *)requestResponseTypeAsMimeTypeString:(MASRequestResponseType)type
// XML
//
case MASRequestResponseTypeXml: return MASRequestResponseTypeXmlValue;

case MASRequestResponseTypeFormData : return MASRequestResponseTypeFormDataValue;

//
// Default
Expand Down Expand Up @@ -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
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Loading