visionOS Integration (Window)
visionOS Integration (Window)
visionOS Integration (Window)
In this article we will learn how integrate the SDK to your visionOS app.
The window option will display the HUMAN challenge in a separate window,
the code integration will be added once, and cover all requests sent from anywhere in the app, background or foreground.
The challenge window does not block the window the user was interacting with, and can be moved to the side by the user,
however once blocked the calls will not go through until the challenge is resolved.
We will cover the following topics:
Note that in order to use challenge in a window you have to enable multiple windows in your app’s Info.plist.
Some features, including the Doctor App, Automatic Interceptor and Hybrid App support, are not available in the SDK for visionOS yet. We will add those features soon.
App’s init function on visionOS.Here is an example of how it should be:
Don’t forget to change the <APP_ID> to your own AppID.
Let’s talk about what we have in the code here:
HSPolicy instance. This object is used to configure the SDK’s behavior.start function of the SDK. We provide the following parameters:
Note: If your app communicates with several servers that have different AppID, you can call the HumanSecurity/start(appIds:policy:) function which allow you to pass an array of AppIDs. You should specify the relevant AppID for each API call in the SDK.
onChange on scenePhase environment variable to check when a window is closed, in that case we will check if challenge window is the only other window and is shown and will close it, if you have a different place in the app where you clean up - you can move the code of closing the window in case it is open there.Here is an example of how it should be:
Let’s talk about what we have in the code here:
View (App):
@Environment(.openWindow) and @Environment(.dismissWindow) properties and call them based on the HSChallengeViewModel/showChallenge observable in the SDK.App’s body.@Environment(.scenePhase) and make sure to close the challenge in case it is the last open window in the app.Model / HTTP client:
Handle it as a failure.
Your app should handle the blocked request as a failure. However, you should consider that your app’s UI is still shown while the challenge is presented to the user. If the request was triggered by a user’s action, you should make it clear that the user may try again the same action.
Use the handler callback to write analytics, logs, etc.
You may use the handler callback to retry the original request When appropriate. You should consider the following:
The HUMAN’s Enforcer, when it decides to block a request, returns a JSON string in the response’s body. The HTTP status code is 403. Here is an example of the response:
The JSON contains metadata for the SDK.
Your app should pass the whole JSON to the SDK via the HSBotDefender/handleBlockResponse function. Otherwise, the SDK won’t present a challenge to the user.
You can set custom parameters in order to configure HUMAN’s backend with additional parameters.
Those parameters can be set with a dictionary (iOS) or a hash map (Android), with the key “custom_param[x]” where [x] is a number between 1-10.
You should call the HSBotDefender/setCustomParameters(parameters:forAppId:) only after the HumanSecurity/start(appId:policy:) function was already called.
Here is an example of how it should be:
In order to enable Account Defender, you should set the UserID of your current logged-in user in the SDK.
Here is an example of how it should be:
In order to allow Account Defender to protect the user’s account, your app has to provide the SDK with outgoing URL requests.
Let’s talk about what we have in the code here:
HSAccountDefender/registerOutgoingUrlRequest(url:forAppId:) function before we send the URL request.You can set additional data in order to configure HUMAN’s backend with additional parameters.
Those parameters can be set with a dictionary.
You should call the HSAccountDefender/setAdditionalData(parameters:forAppId:) only after the HumanSecurity/start(appId:policy:) function was already called.