Hybrid App integration
What is a Hybrid App
A Hybrid App uses both native URL requests and web views to communicate with your server. In the context of HUMAN, it’s crucial to ensure that both native requests and web views are synchronized to provide the expected behavior for end users.
How Do I Know if My App is a Hybrid App
Your app is considered a Hybrid App if it has ALL of the following:
- A web view component (
WKWebView
on iOS orWebView
on Android) that loads your website. - Your website is protected by HUMAN (Bot Defender or Account Defender).
On iOS, if your app uses SFSafariViewController
, please let us know, and we will guide you through a specific integration.
How to Enable Hybrid App Support in My App
Integrate the SDK (Native)
You should integrate the SDK into your native app. You may choose one of the following methods:
Enable Hybrid App Support
When starting the SDK, declare your website’s root domain in the policy. This should be the domain where the SDK will set cookies.
The SDK enables Hybrid App support ONLY for the specified domains. It checks if the website’s domain ends with one of the specified domains. For example, setting example.com
will also support www.example.com
and api.example.com
.
You should pass the WebView
instance to the SDK using the following functions:
- iOS:
HumanSecurity.setupWebView(webView:navigationDelegate:)
- Android:
HumanSecurity.setupWebView(webView:webViewClient:)
Important: Do not set the navigationDelegate
(iOS) or webViewClient
(Android) properties after calling the setupWebView
function.
On iOS, you can enable automatic detection and setup of WKWebView
s by setting HSHybridAppPolicy.automaticSetup
to true
. This eliminates the need to manually call setupWebView
for each instance.
Example Implementation
Android
Kotlin:
Java:
Kotlin (Activity):
Java (Activity):
iOS
Swift:
Objective-C:
Explanation of the Code
- Adding Web Root Domains:
- Specify your website’s root domain (e.g.,
.example.com
) in the policy’swebRootDomains
. This ensures that the SDK only intercepts requests to these domains.
- Specify your website’s root domain (e.g.,
- Starting the SDK:
- Initialize the SDK as early as possible on the main thread to ensure all URL requests include the necessary HTTP headers.
- Setting Up Web Views:
- Android: Use
HumanSecurity.setupWebView(webView:webViewClient:)
to set up theWebView
with the SDK’sWebViewClient
. Do not set theWebViewClient
directly after this. - iOS: Use
HumanSecurity.setupWebView(webView:navigationDelegate:)
to set up theWKWebView
with the SDK’snavigationDelegate
. Do not set thenavigationDelegate
directly after this.
- Android: Use
Notes:
- iOS Automatic Setup: If you enable
HSHybridAppPolicy.automaticSetup
, the SDK will automatically detect and set up allWKWebView
instances without needing to callsetupWebView
for each one. - Multiple AppIDs: If your app communicates with multiple servers having different AppIDs, use the
HumanSecurity.start(appIds:policy:)
function to pass an array of AppIDs and specify the relevant AppID for each API call.
Apple Pay on the Web
If your website uses Apple Pay on the Web, you should disable JavaScript evaluation by the SDK. To protect the security of Apple Pay transactions in WKWebView
, Apple Pay cannot be used alongside script injection APIs (relevant for iOS 13-15). Disable JavaScript evaluation by setting the SDK’s policy accordingly.
Note: If your app targets only iOS 16 or above, you don’t need to disable JavaScript evaluation by the SDK.
Swift:
Objective-C:
External Web Views (Available from v4.0.1)
If your app uses web views that are created outside the native side of the app but are still based on Apple’s WKWebView
or Android’s WebView
(e.g., react-native-webview), you should enable support for them in the SDK’s policy.
Android
Kotlin:
Java:
iOS
Swift:
Objective-C: