- 09 Mar 2023
-
Print
-
DarkLight
Manual integration
- Updated on 09 Mar 2023
-
Print
-
DarkLight
v3.0
Understanding the flow
SDK's headers must be included in your URL requests. To your delight, the SDK automatically intercepts URL requests from your app which sent with OkHttp client. By doing so, the SDK takes care of adding those headers to your URL requests and handling blocks response from your server, which means you don't have to do anything else.
However, you may choose to take care of them manually.
Adding SDK's HTTP headers to your URL requests
- Disable requests interception by setting the
PXPolicy/urlRequestInterceptionType
toPXPolicyUrlRequestInterceptionType/none
.policy.urlRequestInterceptionType = PXPolicyUrlRequestInterceptionType.NONE
policy.setUrlRequestInterceptionType(PXPolicyUrlRequestInterceptionType.NONE);
- Before sending your URL request, take HTTP headers from the SDK and add them to your request.
val headers = PerimeterX.headersForURLRequest(null) // add those headers to your URL request
HashMap<String, String> headers = PerimeterX.INSTANCE.headersForURLRequest(null); // add those headers to your URL request
headersForURLRequest
function!PerimeterX/headersForURLRequest(forAppId:)
function. Those headers contain a token with expiration date. The SDK manages this token to be up-to-date.perimeterxHeadersWereUpdated
delegate functionPerimeterXDelegate/perimeterxHeadersWereUpdated(headers:forAppId:)
function to cache those HTTP headers. However, you must ensure that you update your cache every time this function is called.Handle block responses from your server
After receiving an error in the server's response, pass the information to SDK with the PerimeterX/handleResponse(response:data:forAppId:callback:)
function.
val isHandledBySDK = PerimeterX.handleResponse(responseString, null) { result ->
println("challenge result = $result")
}
boolean isHandledByPX = PerimeterX.INSTANCE.handleResponse(responseString, null, result -> {
Log.i("tag", "challenge result = " + result);
return null;
);
if (isHandledByPX) {
Log.i("tag", "block response was handled by PX");
}
If the response cannot be handled by the SDK, this function will return false
. This function returns true
when the response was handled by the SDK. That means that a challenge will be presented to the user. After the user solved/cancelled the challenge, the handler code will be called with the proper result. You may use this handler to retry your request.