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
8 changes: 8 additions & 0 deletions MASFoundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@
A4F671331BAFC345000E2223 /* NSString+MASPrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = A4F671311BAFC345000E2223 /* NSString+MASPrivate.m */; };
A858C6651D0978A6001FB9AD /* MASOTPService.h in Headers */ = {isa = PBXBuildFile; fileRef = A858C6631D0978A6001FB9AD /* MASOTPService.h */; };
A858C6661D0978A6001FB9AD /* MASOTPService.m in Sources */ = {isa = PBXBuildFile; fileRef = A858C6641D0978A6001FB9AD /* MASOTPService.m */; };
A888437E2327858D0005F502 /* MASNetworkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = A888437C2327858C0005F502 /* MASNetworkConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; };
A888437F2327858D0005F502 /* MASNetworkConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = A888437D2327858C0005F502 /* MASNetworkConfiguration.m */; };
A898EF632182D30A00CF291B /* MASJWTService.m in Sources */ = {isa = PBXBuildFile; fileRef = A898EF612182D30900CF291B /* MASJWTService.m */; };
A898EF642182D30A00CF291B /* MASJWTService.h in Headers */ = {isa = PBXBuildFile; fileRef = A898EF622182D30900CF291B /* MASJWTService.h */; };
A898EF672182D35700CF291B /* MASJWKSet.h in Headers */ = {isa = PBXBuildFile; fileRef = A898EF652182D35700CF291B /* MASJWKSet.h */; };
Expand Down Expand Up @@ -555,6 +557,8 @@
A4F671311BAFC345000E2223 /* NSString+MASPrivate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MASPrivate.m"; sourceTree = "<group>"; };
A858C6631D0978A6001FB9AD /* MASOTPService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASOTPService.h; sourceTree = "<group>"; };
A858C6641D0978A6001FB9AD /* MASOTPService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASOTPService.m; sourceTree = "<group>"; };
A888437C2327858C0005F502 /* MASNetworkConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASNetworkConfiguration.h; sourceTree = "<group>"; };
A888437D2327858C0005F502 /* MASNetworkConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASNetworkConfiguration.m; sourceTree = "<group>"; };
A898EF612182D30900CF291B /* MASJWTService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASJWTService.m; sourceTree = "<group>"; };
A898EF622182D30900CF291B /* MASJWTService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASJWTService.h; sourceTree = "<group>"; };
A898EF652182D35700CF291B /* MASJWKSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASJWKSet.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1242,6 +1246,8 @@
C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */,
C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */,
C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */,
A888437C2327858C0005F502 /* MASNetworkConfiguration.h */,
A888437D2327858C0005F502 /* MASNetworkConfiguration.m */,
);
path = Network;
sourceTree = "<group>";
Expand Down Expand Up @@ -1681,6 +1687,7 @@
A4831AEC1BD1A87C007B4AE6 /* MASApplication+MASPrivate.h in Headers */,
CB5E4C741C1D26BA001B3B8A /* MASPatchURLRequest.h in Headers */,
A42157261BF864590034BDC9 /* MASConfigurationService.h in Headers */,
A888437E2327858D0005F502 /* MASNetworkConfiguration.h in Headers */,
CB5E4C701C1D250D001B3B8A /* MASPutURLRequest.h in Headers */,
CB6491DE1FE9DAF300281288 /* MQTTCFSocketDecoder.h in Headers */,
CB9975461EDF5799006CEBB1 /* MASAuthCredentials+MASPrivate.h in Headers */,
Expand Down Expand Up @@ -2011,6 +2018,7 @@
CB1907F91C17950700A5EF16 /* MASAccessService.m in Sources */,
CBD25B0A1E78C47C00DFB47F /* JWTCoding.m in Sources */,
CBD25B101E78C47C00DFB47F /* JWTErrorDescription.m in Sources */,
A888437F2327858D0005F502 /* MASNetworkConfiguration.m in Sources */,
CB5E4C6D1C1D2467001B3B8A /* MASDeleteURLRequest.m in Sources */,
A46F49CE1C2F5FC500A4C370 /* MASINetworkReachabilityManager.m in Sources */,
A4831AEF1BD1A87C007B4AE6 /* MASAuthenticationProvider+MASPrivate.m in Sources */,
Expand Down
58 changes: 51 additions & 7 deletions MASFoundation/Classes/MAS.m
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ + (void)startWithURL:(NSURL *)url completion:(MASCompletionErrorBlock)completion
withParameters:urlParameters
andHeaders:nil
requestType:MASRequestResponseTypeJson
responseType:MASRequestResponseTypeJson isPublic:YES];
responseType:MASRequestResponseTypeJson isPublic:YES timeoutInterval:MASDefaultNetworkTimeoutConfiguration];
MASSessionDataTaskOperation *dataTaskOperation = [urlSessionManager dataOperationWithRequest:request
completionHandler:^(NSURLResponse * _Nonnull response, id _Nonnull responseObject, NSError * _Nonnull error) {
if (error)
Expand Down Expand Up @@ -926,7 +926,8 @@ + (void)deleteFrom:(NSString *)endPoint
isPublic:(BOOL)isPublic
completion:(MASResponseInfoErrorBlock)completion
{
[MAS httpMethod:@"DELETE" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]];
[MAS httpMethod:@"DELETE" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint]
completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]];
}


Expand Down Expand Up @@ -971,7 +972,8 @@ + (void)getFrom:(NSString *)endPoint
isPublic:(BOOL)isPublic
completion:(MASResponseInfoErrorBlock)completion
{
[MAS httpMethod:@"GET" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]];
[MAS httpMethod:@"GET" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint]
completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]];
}


Expand Down Expand Up @@ -1015,7 +1017,8 @@ + (void)patchTo:(NSString *)endPoint
isPublic:(BOOL)isPublic
completion:(MASResponseInfoErrorBlock)completion
{
[MAS httpMethod:@"PATCH" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]];
[MAS httpMethod:@"PATCH" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint]
completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]];
}


Expand Down Expand Up @@ -1059,7 +1062,8 @@ + (void)postTo:(NSString *)endPoint
isPublic:(BOOL)isPublic
completion:(MASResponseInfoErrorBlock)completion
{
[MAS httpMethod:@"POST" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]];
[MAS httpMethod:@"POST" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint]
completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]];
}


Expand Down Expand Up @@ -1103,21 +1107,28 @@ + (void)putTo:(nonnull NSString *)endPoint
isPublic:(BOOL)isPublic
completion:(nullable MASResponseInfoErrorBlock)completion
{
[MAS httpMethod:@"PUT" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]];
[MAS httpMethod:@"PUT" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint]
completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]];
}


+ (void)invoke:(nonnull MASRequest *)request completion:(nullable MASResponseObjectErrorBlock)completion
{
__block MASResponseObjectErrorBlock blockCompletion = completion;

// If default timeoutInterval override to NetworkConfiguration timeoutInterval.
NSTimeInterval timeoutInterval =
(request.timeoutInterval == MASDefaultNetworkTimeoutConfiguration) ?
[self timeoutIntervalForEndpoint:request.endPoint] : request.timeoutInterval;

[MAS httpMethod:request.httpMethod
endPoint:request.endPoint
withParameters:request.body
andHeaders:request.header
requestType:request.requestType
responseType:request.responseType
isPublic:request.isPublic
timeoutInterval:request.timeoutInterval
completion:^(NSDictionary<NSString *,id> * _Nullable responseInfo, NSError * _Nullable error) {

if (blockCompletion)
Expand All @@ -1144,7 +1155,12 @@ + (void)postMultiPartForm:(nonnull MASRequest *)request constructingBodyWithBloc
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];
// If default timeoutInterval override to NetworkConfiguration timeoutInterval.
NSTimeInterval timeoutInterval =
(request.timeoutInterval == MASDefaultNetworkTimeoutConfiguration) ?
[self timeoutIntervalForEndpoint:request.endPoint] : request.timeoutInterval;

[[MASNetworkingService sharedService] postMultiPartForm:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic timeoutInterval:timeoutInterval constructingBodyBlock:formDataBlock progress:progressBlock completion:completion];

}];
}
Expand Down Expand Up @@ -1195,6 +1211,7 @@ + (void)httpMethod:(NSString *)httpMethod
requestType:(MASRequestResponseType)requestType
responseType:(MASRequestResponseType)responseType
isPublic:(BOOL)isPublic
timeoutInterval:(NSTimeInterval)timeoutInterval
completion:(MASResponseInfoErrorBlock)completion
{
//
Expand Down Expand Up @@ -1231,6 +1248,7 @@ + (void)httpMethod:(NSString *)httpMethod
__block MASRequestResponseType blockRequestType = requestType;
__block MASRequestResponseType blockResponseType = responseType;
__block BOOL blockIsPublic = isPublic;
__block NSTimeInterval blockTimeoutInterval = timeoutInterval;

//
// Validate if new scope has been requested in header
Expand All @@ -1249,6 +1267,7 @@ + (void)httpMethod:(NSString *)httpMethod
requestType:blockRequestType
responseType:blockResponseType
isPublic:blockIsPublic
timeoutInterval:blockTimeoutInterval
completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]];
}
else if ([blockHttpMethod isEqualToString:@"GET"])
Expand All @@ -1259,6 +1278,7 @@ + (void)httpMethod:(NSString *)httpMethod
requestType:blockRequestType
responseType:blockResponseType
isPublic:blockIsPublic
timeoutInterval:blockTimeoutInterval
completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]];
}
else if ([blockHttpMethod isEqualToString:@"PATCH"])
Expand All @@ -1269,6 +1289,7 @@ + (void)httpMethod:(NSString *)httpMethod
requestType:blockRequestType
responseType:blockResponseType
isPublic:blockIsPublic
timeoutInterval:blockTimeoutInterval
completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]];
}
else if ([blockHttpMethod isEqualToString:@"POST"])
Expand All @@ -1279,6 +1300,7 @@ + (void)httpMethod:(NSString *)httpMethod
requestType:blockRequestType
responseType:blockResponseType
isPublic:blockIsPublic
timeoutInterval:blockTimeoutInterval
completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]];
}
else if ([blockHttpMethod isEqualToString:@"PUT"])
Expand All @@ -1289,6 +1311,7 @@ + (void)httpMethod:(NSString *)httpMethod
requestType:blockRequestType
responseType:blockResponseType
isPublic:blockIsPublic
timeoutInterval:blockTimeoutInterval
completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]];
}
}];
Expand Down Expand Up @@ -1461,6 +1484,27 @@ + (BOOL)isPublicForEndpoint:(NSString *)endPoint
}


+ (NSTimeInterval)timeoutIntervalForEndpoint:(NSString *)endPoint
{
NSTimeInterval timeoutInterval = MASDefaultNetworkTimeoutConfiguration;

NSURL *endpointURL = [NSURL URLWithString:endPoint];
if (endpointURL.scheme && endpointURL.host)
{
MASNetworkConfiguration *networkConfiguration = [MASConfiguration networkConfigurationForDomain:[NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", endpointURL.scheme, endpointURL.host, endpointURL.port]]];
timeoutInterval = networkConfiguration.timeoutInterval;
}
else if ([MASConfiguration currentConfiguration])
{
NSURL *gatewayURL = [MASConfiguration currentConfiguration].gatewayUrl;
MASNetworkConfiguration *networkConfiguration = [MASConfiguration networkConfigurationForDomain:[NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", gatewayURL.scheme, gatewayURL.host, gatewayURL.port]]];
timeoutInterval = networkConfiguration.timeoutInterval;
}

return timeoutInterval;
}


# pragma mark - JWT Signing

+ (NSString * _Nullable)signWithClaims:(MASClaims *_Nonnull)claims error:(NSError *__nullable __autoreleasing *__nullable)error
Expand Down
4 changes: 4 additions & 0 deletions MASFoundation/Classes/MASError.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ typedef NS_ENUM(NSInteger, MASFoundationErrorCode)
MASFoundationErrorCodeResponseSerializationFailedToParseResponse = 100407,
MASFoundationErrorCodeNetworkSSLAuthenticationChallengeFailure = 100408,

//
// Network Configuration
//
MASFoundationErrorCodeConfigurationInvalidHostForNetworkConfiguration = 100501,

//
// Application
Expand Down
3 changes: 3 additions & 0 deletions MASFoundation/Classes/_private_/MASConstantsPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ static NSString *_Nonnull const MASUserPhoneRequestResponseKey = @"phone_number"
static NSString *_Nonnull const MASUserPictureRequestResponseKey = @"picture"; // string
static NSString *_Nonnull const MASUserRefreshTokenRequestResponseKey = @"refresh_token"; // string

// Default network timeout configuration.
static int const MASDefaultNetworkTimeoutConfiguration = 60;


# pragma mark - GrantType Constants

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,11 @@ + (NSString *)descriptionForFoundationErrorCode:(MASFoundationErrorCode)errorCod
case MASFoundationErrorCodeConfigurationInvalidHostForSecurityConfiguration: return @"Invalid host information for security configuration. NSURL host or port cannot be nil.";
case MASFoundationErrorCodeConfigurationInvalidPinningInfoForSecurityConfiguration: return @"Invalid pinning information for security configuration. At least one pinning information should be provided or public PKI should be trusted.";

//
// Network Configuration
//
case MASFoundationErrorCodeConfigurationInvalidHostForNetworkConfiguration: return @"Invalid host information for network configuration. NSURL host or port cannot be nil.";

//
// Device
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ @interface MASRequest ()
@property (assign, readwrite) BOOL sign;
@property (assign, readwrite) MASRequestResponseType requestType;
@property (assign, readwrite) MASRequestResponseType responseType;
@property (assign, readwrite) NSTimeInterval timeoutInterval;

@end

Expand All @@ -48,6 +49,7 @@ - (instancetype)initWithBuilder:(MASRequestBuilder *)builder
self.header = builder.header;
self.body = builder.body;
self.query = builder.query;
self.timeoutInterval = builder.timeoutInterval;


//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,51 @@
@interface MASConfigurationService : MASService



///--------------------------------------
/// @name Network Configuration
///--------------------------------------

# pragma mark - Network Configuration

/**
Sets network timeout for specified host in MASNetworkConfiguration object

@warning Upon SDK initialization, [MASConfiguration currentConfiguration].gatewayUrl's MASNetworkConfiguration object will be overwritten. If primary gateway's network configuration has to be modified, ensure to set network configuration after SDK initialization.
@param networkConfiguration MASNetworkConfiguration object with host, and network configuration values.
*/
+ (void)setNetworkConfiguration:(MASNetworkConfiguration *)networkConfiguration;



/**
Removes network configuration object based on the domain.

@param domain NSURL of the domain to delete network configuration.
*/
+ (void)removeNetworkConfigurationForDomain:(NSURL *)domain;



/**
Returns an array of MASNetworkConfiguration objects for each host.

@return Returns an array of currently active MASNetworkConfigurations.
*/
+ (NSArray *)networkConfigurations;



/**
Returns MASNetworkConfiguration object for a specific domain.

@param domain NSURL of the domain for the MASNetworkConfiguration object.
@return Returns a MASNetworkConfiguration object for the domain.
*/
+ (MASNetworkConfiguration *)networkConfigurationForDomain:(NSURL *)domain;



///--------------------------------------
/// @name Security Configuration
///--------------------------------------
Expand Down
Loading