Xamarin SDK
  • 26 Nov 2023
  • Dark
    Light

Xamarin SDK

  • Dark
    Light

Article Summary

Supported Versions

The following SDKs are supported:

  • iOS version 9 and higher
  • Android SDK version 21 (5.0 Lollipop) and higher

Introduction

The Xamarin SDK works by constantly profiling and evaluating device behavior to ensure that the connections to your mobile APIs and services are genuine.

This process is complex and detailed yet only requires initializing a client to manage a set of secure HTTP headers which are added to all HTTP and HTTPS requests made by the mobile application to the origin server.

Prerequisites

The following are required to install the Xamarin SDK:

  • Administrative access to the HUMAN Portal to retrieve the application ID.
  • An active Enforcer.

Integration

Download the NuGet Package

Download and install the latest stable PXSdk NuGet package from the NuGet Gallery. You can do this as you would any other NuGet package.

Initialize the SDK

Include the PXSdk namespace in your source file.

using PXSdk;

Retrieve the appropriate IPXClient by calling PXClientFactory.GetPXClient() and call the Start function. You must pass in the App ID.

IPXClient pxClient = PXClientFactory.GetPXClient();
pxClient.Start(PERIMETERX_APP_ID);

Add all the IPXClient.HttpHeaders to your HTTP request before sending it.

foreach (KeyValuePair<string, string> pair in pxClient.HttpHeaders)
{
    webRequest.Headers.Add(pair.Key, pair.Value);
}
Note
It is not recommended for the application to make network calls going through the Enforcer without headers.

If you receive a 403: Unauthorized response, pass in the body of the response (as a string) to the HandleResponse function. The return value is a boolean indicating if the 403 response was due to internal errors.

if (httpResponse.StatusCode == 403)
{
    bool isPXEnforcement = pxClient.HandleResponse(responseBody.ToString());
    if (!isPXEnforcement) {
        // handle 403 responses not resulting from PX enforcement
    }
}

PXSdk OnCaptchaComplete Event

To trigger certain events when the Captcha has been solved or closed, add a new CaptchaCompleteHandler function to the OnCaptchaComplete event. You can choose what you would like these functions to do based on the resulting PXCaptchaResult and PXCaptchaCancelReason, which are passed as arguments to the function.

pxClient.OnCaptchaComplete += new IPXClient.CaptchaCompleteHandler((result, reason) =>
  {
      // ...
  });

Was this article helpful?