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 @@ -564,6 +564,12 @@
10E0279B1F72B10100EAB103 /* RNDecryptor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNDecryptor.m; sourceTree = "<group>"; };
10E0279C1F72B10100EAB103 /* RNEncryptor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNEncryptor.h; sourceTree = "<group>"; };
10E0279D1F72B10100EAB103 /* RNEncryptor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNEncryptor.m; sourceTree = "<group>"; };
699C17901F9585BC008C1B11 /* MASRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASRequest.m; sourceTree = "<group>"; };
699C17911F9585BC008C1B11 /* MASRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASRequest.h; sourceTree = "<group>"; };
699C17921F9585BC008C1B11 /* MASRequestBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASRequestBuilder.h; sourceTree = "<group>"; };
699C17931F9585BD008C1B11 /* MASRequestBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASRequestBuilder.m; sourceTree = "<group>"; };
699C17951F958660008C1B11 /* MASRequest+MASPrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MASRequest+MASPrivate.h"; sourceTree = "<group>"; };
699C17961F958660008C1B11 /* MASRequest+MASPrivate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "MASRequest+MASPrivate.m"; sourceTree = "<group>"; };
A4150E691BF1643900037E27 /* MASIJSONResponseSerializer+MASPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MASIJSONResponseSerializer+MASPrivate.h"; sourceTree = "<group>"; };
A4150E6A1BF1643900037E27 /* MASIJSONResponseSerializer+MASPrivate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MASIJSONResponseSerializer+MASPrivate.m"; sourceTree = "<group>"; };
A4150E6B1BF1643900037E27 /* NSMutableURLRequest+MASPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableURLRequest+MASPrivate.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1044,6 +1050,15 @@
path = libmosquitto123;
sourceTree = "<group>";
};
699C17941F958660008C1B11 /* Network */ = {
isa = PBXGroup;
children = (
699C17951F958660008C1B11 /* MASRequest+MASPrivate.h */,
699C17961F958660008C1B11 /* MASRequest+MASPrivate.m */,
);
path = Network;
sourceTree = "<group>";
};
A4150EBD1BF16D9A00037E27 /* network */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1407,6 +1422,7 @@
isa = PBXGroup;
children = (
CB99752B1EDCA749006CEBB1 /* AuthCredentials */,
699C17941F958660008C1B11 /* Network */,
CB1907F11C1794FC00A5EF16 /* MASAccess.h */,
CB1907F21C1794FC00A5EF16 /* MASAccess.m */,
A4831AE81BD1A87C007B4AE6 /* MASApplication+MASPrivate.h */,
Expand Down Expand Up @@ -1456,6 +1472,10 @@
CB23578A1F0EE35A00D4C420 /* Network */ = {
isa = PBXGroup;
children = (
699C17911F9585BC008C1B11 /* MASRequest.h */,
699C17901F9585BC008C1B11 /* MASRequest.m */,
699C17921F9585BC008C1B11 /* MASRequestBuilder.h */,
699C17931F9585BD008C1B11 /* MASRequestBuilder.m */,
);
path = Network;
sourceTree = "<group>";
Expand Down
24 changes: 23 additions & 1 deletion MASFoundation/Classes/MAS.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#import "MASConstants.h"
#import "MASClaims.h"

#import "MASRequest.h"

/**
* The top level MAS object represents the Mobile App Services SDK in it's entirety. It
Expand Down Expand Up @@ -949,6 +949,28 @@ withParameters:(NSDictionary *_Nullable)parameterInfo
completion:(MASResponseInfoErrorBlock _Nullable)completion;


/**
* Invoke the endpoint 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.
*
* @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 completion An MASResponseInfoErrorBlock (NSDictionary *responseInfo, NSError *error) that will
* receive the JSON response object or an NSError object if there is a failure.
*/
+ (void)invoke:(nonnull MASRequest *)request completion:(nullable MASResponseInfoErrorBlock)completion;


///--------------------------------------
/// @name JWT Signing
///--------------------------------------
Expand Down
27 changes: 27 additions & 0 deletions MASFoundation/Classes/MAS.m
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,33 @@ + (void)putTo:(nonnull NSString *)endPoint
}


+ (void)invoke:(nonnull MASRequest *)request completion:(nullable MASResponseInfoErrorBlock)completion
{
//
// Process the request
//
if ([request.httpMethod isEqualToString:@"DELETE"])
{
[self deleteFrom:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic completion:completion];
}
else if ([request.httpMethod isEqualToString:@"GET"])
{
[self getFrom:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic completion:completion];
}
else if ([request.httpMethod isEqualToString:@"PATCH"])
{
[self patchTo:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic completion:completion];
}
else if ([request.httpMethod isEqualToString:@"POST"])
{
[self postTo:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic completion:completion];
}
else if ([request.httpMethod isEqualToString:@"PUT"])
{
[self putTo:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic completion:completion];
}
}

# pragma mark - Private


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// MASRequest+MASPrivate.h
// MASFoundation
//
// Copyright (c) 2017 CA. All rights reserved.
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
//

#import <MASFoundation/MASFoundation.h>

@interface MASRequest (MASPrivate)

/**
Private initializer for MASRequest.

@param url NSURL of the target domain
@return MASRequest object
*/
- (instancetype)initWithBuilder:(MASRequestBuilder *)builder;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// MASRequest+MASPrivate.m
// MASFoundation
//
// Copyright (c) 2017 CA. All rights reserved.
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
//

#import "MASRequest+MASPrivate.h"


@interface MASRequest ()

@property (nonatomic, readwrite) NSString *endPoint;
@property (nonatomic, readwrite) NSString *httpMethod;
@property (nonatomic, readwrite) NSData *privateKey;
@property (nonatomic, readwrite) NSDictionary *header;
@property (nonatomic, readwrite) NSDictionary *body;
@property (nonatomic, readwrite) NSDictionary *query;
@property (assign, readwrite) BOOL isPublic;
@property (assign, readwrite) BOOL sign;
@property (assign, readwrite) MASRequestResponseType requestType;
@property (assign, readwrite) MASRequestResponseType responseType;

@end

@implementation MASRequest (MASPrivate)

# pragma mark - Lifecycle

- (instancetype)initWithBuilder:(MASRequestBuilder *)builder
{
self = [super init];
if(self)
{
//
// copy parameters from builder
//
self.endPoint = builder.endPoint;
self.isPublic = builder.isPublic;
self.sign = builder.sign;
self.requestType = builder.requestType;
self.responseType = builder.responseType;
self.httpMethod = builder.httpMethod;
self.privateKey = builder.privateKey;
self.header = builder.header;
self.body = builder.body;
self.query = builder.query;


//
// check if query parameters are provided
//
if(self.query)
{
//
// add query parameters into URL
//
NSURL *url = [NSURL URLWithString:self.endPoint];

NSMutableArray<NSURLQueryItem *> *queryItems = [NSMutableArray array];
for (NSString *key in self.query) {
NSURLQueryItem *queryItem = [NSURLQueryItem queryItemWithName:key value:self.query[key]];
[queryItems addObject:queryItem];
}

NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
components.queryItems = [queryItems copy];

self.endPoint = [components.URL absoluteString];
}

}

return self;
}


@end
150 changes: 150 additions & 0 deletions MASFoundation/Classes/models/Network/MASRequest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
//
// MASRequest.h
// MASFoundation
//
// Copyright (c) 2017 CA. All rights reserved.
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
//

#import "MASRequestBuilder.h"

/**
MASRequest class is an object created by MASRequestBuilder. It contains all necessary information to invoke an API.
The class cannot be constructed or changed directly, only through MASRequestBuilder.
*/
@interface MASRequest : MASObject


///--------------------------------------
/// @name Properties
///--------------------------------------

# pragma mark - Properties

/**
NSString value of the HTTP Method (GET, POST, PUT, DELETE).
*/
@property (nonatomic, strong, readonly) NSString * _Nonnull httpMethod;


/**
BOOL value that determines whether or not to include credentials of primary gateway in the request.
*/
@property (assign, readonly) BOOL isPublic;


/**
BOOL value that determines whether or not digitally sign the request parameters with JWT signature.
*/
@property (assign, readonly) BOOL sign;


/**
NSString value of the specific end point path fragment to append to the base Gateway URL. endPoint value can also be defined as full URL format; in this case,
SDK must be configured to add add the external host as a trusted source using MASSecurityConfiguration object.
*/
@property (nonatomic, strong, nullable, readonly) NSString *endPoint;


/**
NSData value of private key.
*/
@property (nonatomic, strong, nullable, readonly) NSData *privateKey;


/**
NSDictionary of type/value parameters to put into the header of a request.
*/
@property (nonatomic, strong, nullable, readonly) NSDictionary *header;


/**
NSDictionary of type/value parameters to put into the body of a request.
*/
@property (nonatomic, strong, nullable, readonly) NSDictionary *body;


/**
NSDictionary of type/value parameters to put into the URL of a request.
*/
@property (nonatomic, strong, nullable, readonly) NSDictionary *query;


/**
MASRequestResponseType value that specifies what type formatting is required for request body.
*/
@property (assign, readonly) MASRequestResponseType requestType;


/**
MASRequestResponseType value that specifies what type formatting is required for response body.
*/
@property (assign, readonly) MASRequestResponseType responseType;


# pragma mark - Public


/**
Initialize MASRequest using MASRequestBuilder block and defining the request method as a HTTP DELETE call. This type of HTTP Method type
places its parameters within the NSURL itself as an HTTP query extension.

@discussion default values for designated initializer are: isPublic: NO, sign: NO, requestType:MASRequestResponseTypeJson, responseType:MASRequestResponseTypeJson.
@param block MASRequestBuilder block containing all paramters to build the request.
@return MASRequestBuilder object
*/
+ (instancetype _Nullable)deleteFrom:(void (^_Nonnull)(MASRequestBuilder* _Nonnull builder))block;



/**
Initialize MASRequest using MASRequestBuilder block and defining the request method as a HTTP GET call. This type of HTTP Method type
places its parameters within the NSURL itself as an HTTP query extension.

@discussion default values for designated initializer are: isPublic: NO, sign: NO, requestType:MASRequestResponseTypeJson, responseType:MASRequestResponseTypeJson.
@param block MASRequestBuilder block containing all paramters to build the request.
@return MASRequestBuilder object
*/
+ (instancetype _Nullable)getFrom:(void (^_Nonnull)(MASRequestBuilder* _Nonnull builder))block;



/**
Initialize MASRequest using MASRequestBuilder block and defining the request method as a HTTP PATCH call. This type of HTTP Method type
places its parameters within the HTTP body in www-form-url-encoded format.

@discussion default values for designated initializer are: isPublic: NO, sign: NO, requestType:MASRequestResponseTypeJson, responseType:MASRequestResponseTypeJson.
@param block MASRequestBuilder block containing all paramters to build the request.
@return MASRequestBuilder object
*/
+ (instancetype _Nullable)patchTo:(void (^_Nonnull)(MASRequestBuilder* _Nonnull builder))block;



/**
Initialize MASRequest using MASRequestBuilder block and defining the request method as a HTTP POST call. This type of HTTP Method type
places its parameters within the HTTP body in www-form-url-encoded format.

@discussion default values for designated initializer are: isPublic: NO, sign: NO, requestType:MASRequestResponseTypeJson, responseType:MASRequestResponseTypeJson.
@param block MASRequestBuilder block containing all paramters to build the request.
@return MASRequestBuilder object
*/
+ (instancetype _Nullable)postTo:(void (^_Nonnull)(MASRequestBuilder* _Nonnull builder))block;



/**
Initialize MASRequest using MASRequestBuilder block and defining the request method as a HTTP PUT call. This type of HTTP Method type
places its parameters within the HTTP body in www-form-url-encoded format.

@discussion default values for designated initializer are: isPublic: NO, sign: NO, requestType:MASRequestResponseTypeJson, responseType:MASRequestResponseTypeJson.
@param block MASRequestBuilder block containing all paramters to build the request.
@return MASRequestBuilder object
*/
+ (instancetype _Nullable)putTo:(void (^_Nonnull)(MASRequestBuilder* _Nonnull builder))block;



@end
Loading