HTTP Request Customization

Change Face SDK's outgoing http requests right before they are sent

HTTP Headers

Because the Face SDK has an underlying online web service it is a common scenario that you would be required to modify some properties of the HTTP request ongoing from your app.

Here is how you can add new HTTP Header Fields:

iOS

For the iOS platform, you will be required to conform to URLRequestInterceptingDelegate which provides you with a callback that receives URLRequest right before they are fired. In this example, we will utilize AppDelegate to intercept our requests.

Swift
Objective-C
Swift
#import FaceSDK
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FaceSDK.service.requestInterceptingDelegate = self
return true
}
}
extension AppDelegate: URLRequestInterceptingDelegate {
func interceptorPrepare(_ request: URLRequest) -> URLRequest? {
var request = request
request.addValue("Authorization", forHTTPHeaderField: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmYWNlLXNkayI6IkhhdmUgYSBncmVhdCBkYXkhIn0.IPoW0D0LnMv_pL4U22MuIhDNGIdK34TaHhqhKBAaBEs")
return request
}
}
Objective-C
#import "AppDelegate.h"
#import <FaceSDK/FaceSDK.h>
@interface AppDelegate () <RFSURLRequestInterceptingDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
RFSFaceSDK.service.requestInterceptingDelegate = self;
return YES;
}
- (NSURLRequest * _Nullable)interceptorPrepareRequest:(NSURLRequest * _Nonnull)request {
NSMutableURLRequest *interceptedRequest = [request mutableCopy];
[interceptedRequest addValue:@"Authorization" forHTTPHeaderField:@"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmYWNlLXNkayI6IkhhdmUgYSBncmVhdCBkYXkhIn0.IPoW0D0LnMv_pL4U22MuIhDNGIdK34TaHhqhKBAaBEs"];
return interceptedRequest;
}
@end

Android

For the Android platform, you can specify custom Header Fields in the configuration object created right before starting the UI module.

Kotlin
Java
Kotlin
val configuration = LivenessConfiguration.Builder()
.setHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmYWNlLXNkayI6IkhhdmUgYSBncmVhdCBkYXkhIn0.IPoW0D0LnMv_pL4U22MuIhDNGIdK34TaHhqhKBAaBEs")
.build()
Face.Instance().startLiveness(this@MainActivity, configuration) { livenessResponse: LivenessResponse? -> }
Java
LivenessConfiguration configuration = new LivenessConfiguration.Builder()
.setHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmYWNlLXNkayI6IkhhdmUgYSBncmVhdCBkYXkhIn0.IPoW0D0LnMv_pL4U22MuIhDNGIdK34TaHhqhKBAaBEs")
.build();
Face.Instance().startLiveness(MainActivity.this, configuration, livenessResponse -> {});