Directory Client

Device Management

The Directory Client will interact with Directories for managing Directory Services and Directory Users’ Devices as well as managing the Service Sessions for its Directory Users. The Directory Client can be obtained from the appropriate factories.

Get Linked Devices

The Get Linked Devices method generates a list containing each Device linked to a Directory User. The method takes a Directory User ID as the single argument. The example below provides a loop in order to print all linked devices and their current attributes.

var identifier = "my-permanent-unique-user-identifier";
var devices = directoryClient.GetLinkedDevices(identifier);
for (var device in devices)
{
    Console.WriteLine("  " + device.Id + ":");
    Console.WriteLine("    Name:    " + device.Name);
    Console.WriteLine("    Type:    " + device.Type);
    Console.WriteLine("    Status:  " + device.Status);
    Console.WriteLine("    Created: " + device.Created);
    Console.WriteLine("    Updated: " + device.Updated);
}
String identifier = "my-permanent-unique-user-identifier";
List<Device> devices = directoryClient.getLinkedDevices(identifier);
for (Device device : devices) {
    System.out.println("  " + device.getId() + ":");
    System.out.println("    Name:    " + device.getName());
    System.out.println("    Type:    " + device.getType());
    System.out.println("    Status:  " + device.getStatus());
    System.out.println("    Created: " + device.getCreated());
    System.out.println("    Updated: " + device.getUpdated());
}
identifier = "my-permanent-unique-user-identifier"
devices = directory_client.get_linked_devices(identifier)
for device in devices:
    print("  " + device.id + ":");
    print("    Name:    " + device.name)
    print("    Type:    " + device.type)
    print("    Status:  " + device.status)

Session Management

Get Service Sessions for a User

The Get All Service Sessions method retrieves the Service Sessions for a Directory User. The method takes a Directory User ID as the single argument.

var identifier = "my-permanent-unique-user-identifier"
var sessions = directoryClient.GetAllServiceSessions(identifier)
for (var session in sessions)
{
    Console.WriteLine("  " + session.ServiceId + ":")
    Console.WriteLine("    Name:     " + session.ServiceName)
    Console.WriteLine("    Icon:     " + session.ServiceIcon)
    Console.WriteLine("    Auth Req: " + session.AuthRequest)
    Console.WriteLine("    Created:  " + session.Created)
}
String identifier = "my-permanent-unique-user-identifier";
List<Session> sessions = directoryClient.getAllServiceSessions(identifier);

for (Session session : sessions) {
    System.out.println("  " + session.getServiceId() + ":");
    System.out.println("    Name:     " + session.getServiceName());
    System.out.println("    Icon:     " + session.getServiceIcon());
    System.out.println("    Auth Req: " + session.getAuthRequest());
    System.out.println("    Created:  " + session.getCreated());
}
identifier = "my-permanent-unique-user-identifier"
var sessions = directory_client.get_all_service_sessions(identifier)
for session in sessions:
    print("  " + session.service_id + ":")
    print("    Name:     " + session.service_name)
    print("    Icon:     " + session.service_icon)
    print("    Auth Req: " + session.auth_request)
    print("    Created:  " + session.created)

Ending All Service Sessions for a User

The End All Service Sessions method ends all Service Sessions for a Directory User. The method takes a Directory User ID as the single argument.

Note

To end an individual session, use the Service Client.

var identifier = "my-permanent-unique-user-identifier";
directoryClient.EndAllServiceSessions(identifier);
String identifier = "my-permanent-unique-user-identifier";
directoryClient.endAllServiceSessions(identifier);
identifier = "my-permanent-unique-user-identifier"
directory_client.end_all_service_sessions(identifier)

Service Management

Creating a Service

The Create Service method creates a Service Profile. The method takes five arguments: 1) the Service name, 2) a description, 3) an icon image URL, 4) a webhook callback URL, and 5) the active flag for the Service. The method returns a UUID as the Service ID for all further interactions regarding the Service created.

Example:

var serviceId = client.CreateService(
    "My Unique Service Name",
    "My Service Description",
    URI.create("https://my.com/icon.png"),
    URI.create("https://my.com/launchkey-callback"),
    true
);
UUID serviceId = client.createService(
    "My Unique Service Name",
    "My Service Description",
    URI.create("https://my.com/icon.png"),
    URI.create("https://my.com/launchkey-callback"),
    true
);
service_id = client.create_service(
    "My Unique Service Name",
    description="My Service Description",
    icon="https://my.com/icon.png",
    callback_url="https://my.com/launchkey-callback",
    active=True
)

Get a Service

The Get Service method retrieves a single Service Profile. The method takes the Service ID as the single argument.

Example:

var service = client.GetService(serviceId);
Console.WriteLine("  " + service.Id + ":");
Console.WriteLine("    Name:    " + service.Name);
Console.WriteLine("    Desc:    " + service.Description);
Console.WriteLine("    Icon:    " + service.Icon);
Console.WriteLine("    Created: " + service.CallbackURL);
Console.WriteLine("    Active:  " + service.Active);
Service service = client.getService(serviceId);
System.out.println("  " + service.getId() + ":");
System.out.println("    Name:    " + service.getName());
System.out.println("    Desc:    " + service.getDescription());
System.out.println("    Icon:    " + service.getIcon());
System.out.println("    Created: " + service.getCallbackURL());
System.out.println("    Active:  " + service.isActive());
service = client.get_service(service_id)
print("  " + service.id + ":")
print("    Name:    " + service.name)
print("    Desc:    " + service.description)
print("    Icon:    " + service.icon)
print("    Created: " + service.callback_url)
print("    Active:  " + service.active)

Get All Services

The Get All Services method retrieves a list of all Service Profile items. The method does not takes any arguments.

Example:

var services = client.GetAllServices();
for (var service in services)
{
    Console.WriteLine("  " + service.Id + ":");
    Console.WriteLine("    Name:    " + service.Name);
    Console.WriteLine("    Desc:    " + service.Description);
    Console.WriteLine("    Icon:    " + service.Icon);
    Console.WriteLine("    Created: " + service.CallbackURL);
    Console.WriteLine("    Active:  " + service.Active);
}
List<Service> services = client.getAllServices();
for (Service service : services) {
    System.out.println("  " + service.getId() + ":");
    System.out.println("    Name:    " + service.getName());
    System.out.println("    Desc:    " + service.getDescription());
    System.out.println("    Icon:    " + service.getIcon());
    System.out.println("    Created: " + service.getCallbackURL());
    System.out.println("    Active:  " + service.isActive());
}
services = client.get_all_services()
for service in services:
    print("  " + service.id + ":")
    print("    Name:    " + service.name)
    print("    Desc:    " + service.description)
    print("    Icon:    " + service.icon)
    print("    Created: " + service.callback_url)
    print("    Active:  " + service.active)

Get a List of Services

The Get Services method retrieves a list of specific Service Profile items. The method takes a list of Service IDs the single argument. The example below provides a loop in order to print all items and their current attributes.

Example:

var services = client.GetServices(serviceIds);
for (var service in services)
{
    Console.WriteLine("  " + service.Id + ":");
    Console.WriteLine("    Name:    " + service.Name);
    Console.WriteLine("    Desc:    " + service.Description);
    Console.WriteLine("    Icon:    " + service.Icon);
    Console.WriteLine("    Created: " + service.CallbackURL);
    Console.WriteLine("    Active:  " + service.Active);
}
List<Service> services = client.getServices(serviceIds);
for (Service service : services) {
    System.out.println("  " + service.getId() + ":");
    System.out.println("    Name:    " + service.getName());
    System.out.println("    Desc:    " + service.getDescription());
    System.out.println("    Icon:    " + service.getIcon());
    System.out.println("    Created: " + service.getCallbackURL());
    System.out.println("    Active:  " + service.isActive());
}
services = client.get_services(service_ids)
for service in services:
    print("  " + service.id + ":")
    print("    Name:    " + service.name)
    print("    Desc:    " + service.description)
    print("    Icon:    " + service.icon)
    print("    Created: " + service.callback_url)
    print("    Active:  " + service.active)

Updating a Service

The Update Service Method updates a Service Profile item. The method takes five arguments: 1) the Service ID, 2) the Service name, 3) a description of the Service, 4) an icon image URL, 5) a webhook callback URL, and 6) the active flag for the Service. It does not return a value.

Example:

client.UpdateService(
    serviceId,
    "My Unique Service Name",
    "My Service Description",
    URI.create("https://my.com/icon.png"),
    URI.create("https://my.com/launchkey-callback"),
    true
);
client.updateService(
    serviceId,
    "My Unique Service Name",
    "My Service Description",
    URI.create("https://my.com/icon.png"),
    URI.create("https://my.com/launchkey-callback"),
    true
);
client.update_service(
    service_id,
    name="My Unique Service Name",
    description="My Service Description",
    icon="https://my.com/icon.png",
    callback_url="https://my.com/launchkey-callback",
    active=True
)

Removing a Service

A Service cannot be removed via the LaunchKey API. However, the Service can be set to inactive via the LaunchKey API. The only way to remove a Service is via the Admin Center.

Public Key Management

Add a Public Key

The Add Public Key Method adds a Public Key to a Service Profile. The method takes four arguments: 1) the Service ID, 2) the Public Key, 3) the active flag for the Service, and 4) the date in which the public key will expire. It returns a Key ID tied to all further interactions regarding the Public Key created.

Note

Supplying a null value for the expiration date will prevent the Public Key from expiring.

Example:

var keyId = client.AddServicePublicKey(serviceId, publicKey, false, null);
String keyId = client.addServicePublicKey(serviceId, publicKey, false, null);
key_id = client.add_service_public_key(service_id, public_key, None, False)

Update a Public Key

The Update Service Public Key method updates a Public Key for a Service Profile. The method takes four arguments: 1) the Service ID, 2) the Key ID, 3) the active flag for the Service, and 4) the date in which the public key will expire. It does not return a value.

Example:

client.UpdateServicePublicKey(serviceId, keyId, false, null);
client.updateServicePublicKey(serviceId, keyId, false, null);
client.update_service_public_key(service_id, key_id, expires=None, active=False)

Remove a Public Key

The Remove Service Public Key method removes a Public Key from a Service Profile. The method takes two arguments: 1) the Service ID and 2) the Key ID. It does not return a value.

Note

Every entity must have at least one Public Key. As such, you cannot remove the last Public Key for an entity. However, you can deactivate any Public Key by setting the active flag to false.

Example:

client.RemoveServicePublicKey(serviceId, keyId);
client.removeServicePublicKey(serviceId, KeyId);
client.remove_service_public_key(service_id, key_id)

Policy Management

Creating a Policy Object

A Policy can be based on a number of authorization factors or by requiring individual types of authorization factors. Examples of various scenarios follow.

Fences

Fences allow for creating location-based limits that the device will evaluate to determine its compliance to a given policy. All policies (other than a Conditional GeoFence Policy) will fail if the device responding to an authorization request is not within one of the policy’s fences. Fences can be either GeoCircleFence, which creates a fence of a particular radius around a point described via latitude and longitude, or a TerritoryFence, which is described via a country, optional administrative area, and optional postal code. The country value must be an ISO 3166-1 Alpha-2 code. The administrative area value must be an ISO 3166-2 code. The postal code must be a recognized postal code. In the U.S.A., it must be the five (5) digit code rather than the nine (9) digit “Zip+4”.

Example:

Policy policy = new MethodAmountPolicy(fences=new List<Fence> {
    new GeoCircleFence("Portland", 1000.0, 45.522187, -122.676291),
    new TerritoryFence("US", "US-NV", "89169", "Las Vegas")
});
Policy policy = new MethodAmountPolicy(false, false, new ArrayList<Policy>() {{
        add(new GeoCircleFence("Portland", 1000.0, 45.522187, -122.676291);
        add(new TerritoryFence("US", "US-NV", "89169", "Las Vegas");
}}, 0);
from launchkey.entities.service.policy import FactorsPolicy, GeoCircleFence, TerritoryFence

policy = MethodAmountPolicy(fences=[
        GeoCircleFence(45.522187, -122.676291, 1000.0, "Portland"),
        TerritoryFence("US", "US-NV", "89169", "Las Vegas")
]);
Device Integrity

Device integrity can prevent devices whose integrity has been compromised from responding to an authorization request. Devices can be identified as rooted/jailbroken or am emulator/simulator. Each policy type allows for the attribute deny rooted jailbroken. All policies (except legacy policies) allow for the attribute deny emulator simulator.

Example:

var policy = new MethodAmountPolicy(denyRootedJailbroken: true, denyEmulatorSimulator: true);
boolean denyRootedJailbroken = false;
boolean denyEmulatorSimulator = false;

MethodAmountPolicy policy = new MethodAmountPolicy(denyRootedJailbroken, denyEmulatorSimulator, null, 0);
from launchkey.entities.service.policy import MethodAmountPolicy

policy = MethodAmountPolicy(deny_rooted_jailbroken=True, deny_emulator_simulator=True)
Legacy Policy Objects

Warning

Legacy Policy Objects are required for LaunchKey Mobile Authenticator SDK versions prior to 4.9.0. The ability to send Legacy Policy objects will be removed at a future date. The LegacyPolicy class will be removed from the Service SDKs prior to the support being removed entirely.

Example:

    new GeoCircleFence("Portland", 1000.0, 45.522187, -122.676291)
}
var policy = new LegacyPolicy(amount=2, inherenceRequired=false, knowledgeRequired=false,
        possessionRequired=false, denyRootedJailbroken=true, fences=fences);
    fences.add(new GeoCircleFence("Portland", 1000.0, 45.522187, -122.676291));
}}
boolean denyRootedJailbroken = false;
boolean knowledgeRequired = true;
boolean inherenceRequired = true;
boolean possessionRequired = false;
MethodAmountPolicy policy = new LegacyPolicy(2, inherenceRequired, knowledgeRequired,
        possessionRequired=false, denyRootedJailbroken=true, fences=fences, null);
fences = [
    GeoCircleFence("Portland", 1000.0, 45.522187, -122.676291)
]
var policy = new LegacyPolicy(amount=2, inherence_required=false, knowledge_required=false,
        possession_required=false, deny_rooted_jailbroken=true, fences=fences);
Method Amount Policies

Method amount policies allow you to require a number of authentication methods in your policy:

var policy = new MethodAmountPolicy(2);
MethodAmountPolicy policy = new MethodAmountPolicy(2);
from launchkey.entities.service.policy import MethodAmountPolicy

policy = MethodAmountPolicy(2)
Factors Policies

Factors policies allow you to require specific authentication factors:

var policy = new FactorsPolicy(
        knowledgeRequired: true,
        inherenceRequired: true,
        possessionRequired: false);
boolean denyRootedJailbroken = false;
boolean denyEmulatorSimulator = false;
boolean knowledgeRequired = true;
boolean inherenceRequired = true;
boolean possessionRequired = false;
FactorsPolicy Policy = new FactorsPolicy(
        denyRootedJailbroken,
        denyEmulatorSimulator,
        knowledgeRequired,
        inherenceRequired,
        possessionRequired);
from launchkey.entities.service.policy import FactorsPolicy

policy = FactorsPolicy(knowledge_required=True, inherence_required=True, possession_required=False);
Conditional Geo-Fence Policies

Conditional policies allow you to require a secondary policy based on the responding Device being inside one or outside all of the provided Fences. The secondary policies must be either a MethodAmountPolicy or a FactorsPolicy. The secondary policies cannot have deny emulator simulator or deny rooted jailbroken set to true.

var policy = new ConditionalGeoFencePolicy(
        denyRootedJailbroken: true,
        denyEmulatorSimulator: true,
        fences=new List<Fence> {
            new GeoCircleFence("Portland", 1000.0, 45.522187, -122.676291),
            new TerritoryFence("US", "US-NV", "89169", "Las Vegas")
        },
        inside=new FactorsPolicy(
                knowledgeRequired: true,
                inherenceRequired: true,
                possessionRequired: false),
        outside=new MethodAmountPolicy(2)
);
boolean knowledgeRequired = true;
boolean inherenceRequired = true;
boolean possessionRequired = false;
Policy policy = new ConditionalGeoFencePolicy(true, true,
        new ArrayList<Policy>() {{
                add(new GeoCircleFence("Portland", 1000.0, 45.522187, -122.676291);
                add(new TerritoryFence("US", "US-NV", "89169", "Las Vegas");
        }},
        new FactorsPolicy(
                knowledgeRequired,
                inherenceRequired,
                possessionRequired)
        ),
        new MethodAmountPolicy(2)
);
from launchkey.entities.service.policy import FactorsPolicy, GeoCircleFence, TerritoryFence

policy = ConditionalGeoFencePolicy(
        deny_rooted_jailbroken=True, deny_emulator_simulator=True,
        fences=[
            GeoCircleFence(45.522187, -122.676291, 1000.0, "Portland"),
            TerritoryFence("US", "US-NV", "89169", "Las Vegas")],
        inside=FactorsPolicy(knowledge_required=True, inherence_required=True, possession_required=False),
        outside=MethodAmountPolicy(2))

Set the Policy

The Set Service Policy method sets the Policy for a Service. The method takes two arguments: 1) the Service ID and 2) the Policy. It does not return a value.

Example:

client.SetAdvancedServicePolicy(serviceId, policy);
client.setAdvancedServicePolicy(serviceId, policy);
client.set_advanced_service_policy(service_id, policy)

Get a Policy

The Get Advanced Service Policy method retrieves the Policy for a Service. The method takes the Service ID as the single argument. It returns the Policy or null (if no Policy exists).

Example:

var policy = client.GetAdvancedServicePolicy(serviceId);
Fence[] fences = null
bool? preventJailBrokenRooted = null;
bool? preventSimulatorEmulator = null;

if policy instanceof LegacyPolicy:
    LegacyPolicy legacyPolicy = (LegacyPolicy) policy;
    Console.WriteLine("Required Factors:     " + legacyPolicy.RequiredFactors);
    Console.WriteLine("Inherence Required:   " + legacyPolicy.RequireInherenceFactor);
    Console.WriteLine("Knowledge Required:   " + legacyPolicy.RequireKnowledgeFactor);
    Console.WriteLine("Possession Required:  " + legacyPolicy.RequirePossessionFactor);
    Console.WriteLine("Jailbreak Protection: " + legacyPolicy.JailbreakDetection);
    Console.WriteLine("Time Fences:");
    for (var timeFence in legacyPolicy.TimeFences)
    {
        Console.WriteLine("  " + timeFence.Name + ":");
        Console.WriteLine("    Days:  " + timeFence.Days);
        Console.WriteLine("    Start: " + timeFence.StartHour + ":" + timeFence.StartMinute);
        Console.WriteLine("    End:   " + timeFence.EndHour + ":" + timeFence.EndMinute);
        Console.WriteLine("    TZ:    " + timeFence.TimeZone);
    }
    fences = legacyPolicy.fences;
elif policy instanceof MethodAmountPolicy:
    MethodAmountPolicy methodAmountPolicy = (MethodAmountPolicy) policy;
    Console.WriteLine("Required Factors:     " + methodAmountPolicy.RequiredFactors);
    fences = methodAmountPolicy.Fences;
    preventJailBrokenRooted = methodAmountPolicy.PreventJailBrokenRooted;
    preventSimulatorEmulator = methodAmountPolicy.PreventSimulatorEmulator;
elif policy instanceof FactorTypesPolicy:
    FactorTypesPolicy factorTypesPolicy = (FactorTypesPolicy) policy;
    Console.WriteLine("Inherence Required:   " + factorTypesPolicy.RequireInherenceFactor);
    Console.WriteLine("Knowledge Required:   " + factorTypesPolicy.RequireKnowledgeFactor);
    Console.WriteLine("Possession Required:  " + factorTypesPolicy.RequirePossessionFactor);
    fences = methodAmountPolicy.Fences
    preventJailBrokenRooted = methodAmountPolicy.PreventJailBrokenRooted;
    preventSimulatorEmulator = methodAmountPolicy.PreventSimulatorEmulator;
elif policy instanceof ConditionalGeoFencePolicy:
    ConditionalGeoFencePolicy conditionalGeoFencePolicy = (ConditionalGeoFencePolicy) policy;
    Console.WriteLine("Inside Policy:     " + typeof(conditionalGeoFencePolicy.Inside));
    Console.WriteLine("Outside Policy:    " + typeof(conditionalGeoFencePolicy.Outside));
    fences = conditionalGeoFencePolicy.Fences
    preventJailBrokenRooted = conditionalGeoFencePolicy.PreventJailBrokenRooted;
    preventSimulatorEmulator = conditionalGeoFencePolicy.PreventSimulatorEmulator;

if preventJailBrokenRooted != null:
    Console.WriteLine("Prevent Jail Broken/Rooted: " + preventJailBrokenRooted);
if preventSimulatorEmulator != null:
    Console.WriteLine("Prevent Simulator/Emulator: " + preventSimulatorEmulator);

Console.WriteLine("Fences:");
for (var fence in fences) {
    if fence instanceof CircleGeoFence:
        Console.WriteLine("  " + fence.Name + ":");
        Console.WriteLine("    Latitude:    " + fence.Latitude);
        Console.WriteLine("    Longitude:   " + fence.Longitude);
        Console.WriteLine("    Radius:      " + fence.Radius);
    else:
        Console.WriteLine("  " + fence.Name + ":");
        Console.WriteLine("    Country:     " + fence.Country);
        Console.WriteLine("    Admin Area:  " + fence.AdministrativeArea);
        Console.WriteLine("    Postal Code: " + fence.PostalCode);
}
 Policy policy = client.getAdvancedServicePolicy(serviceId);
 List<Fence> fences = null
 Boolean preventJailBrokenRooted = null;
 Boolean preventSimulatorEmulator = null;

 if (policy instanceof LegacyPolicy) {
     LegacyPolicy legacyPolicy = (LegacyPolicy) policy;
     System.out.println("Required Factors:     " + legacyPolicy.getRequiredFactors());
     System.out.println("Inherence Required:   " + legacyPolicy.isInherenceFactorRequired());
     System.out.println("Knowledge Required:   " + legacyPolicy.isKnowledgeFactorRequired());
     System.out.println("Possession Required:  " + legacyPolicy.isPossessionFactorRequired());
     System.out.println("Jailbreak Protection: " + legacyPolicy.isJailBreakProtectionEnabled());
     fences = legacyPolicy.getFences();
     System.out.println("Time Fences:");
     for (Policy.TimeFence timeFence : legacyPolicy.getTimeFences()) {
         System.out.println("  " + timeFence.getName() + ":");
         System.out.println("    Days:  " + timeFence.getDays());
         System.out.println("    Start: " + timeFence.getStartHour() + ":" + timeFence.getStartMinute());
         System.out.println("    End:   " + timeFence.getEndHour() + ":" + timeFence.getEndMinute());
         System.out.println("    TZ:    " + timeFence.getTimeZone());
     }
} else if (policy instanceof MethodAmountPolicy) {
     MethodAmountPolicy methodAmountPolicy = (MethodAmountPolicy) policy;
     System.out.println("Required Factors:     " + methodAmountPolicy.getRequiredFactors());
     fences = methodAmountPolicy.getFences();
     preventJailBrokenRooted = methodAmountPolicy.isPreventJailBrokenRooted();
     preventSimulatorEmulator = methodAmountPolicy.isPreventSimulatorEmulator();
 } else if (policy instanceof FactorTypesPolicy) {
     FactorTypesPolicy factorTypesPolicy = (FactorTypesPolicy) policy;
     System.out.println("Inherence Required:   " + factorTypesPolicy.isInherenceFactorRequired());
     System.out.println("Knowledge Required:   " + factorTypesPolicy.isKnowledgeFactorRequired());
     System.out.println("Possession Required:  " + factorTypesPolicy.isPossessionFactorRequired());
     fences = factorTypesPolicy.getFences();
     preventJailBrokenRooted = factorTypesPolicy.isPreventJailBrokenRooted();
     preventSimulatorEmulator = factorTypesPolicy.isPreventSimulatorEmulator();
 } else if (policy instanceof ConditionalGeoFencePolicy) {
     ConditionalGeoFencePolicy conditionalGeoFencePolicy = (ConditionalGeoFencePolicy) policy;
     System.out.println("Inside Policy:   " + conditionalGeoFencePolicy.getInside().getClass().getShortName());
     System.out.println("Outside Policy:   " + conditionalGeoFencePolicy.getInside().getClass().getShortName());
     fences = conditionalGeoFencePolicy.getFences();
     preventJailBrokenRooted = conditionalGeoFencePolicy.isPreventJailBrokenRooted();
     preventSimulatorEmulator = conditionalGeoFencePolicy.isPreventSimulatorEmulator();

 if preventJailBrokenRooted != null:
     System.out.println("Prevent Jail Broken/Rooted: " + preventJailBrokenRooted);
 if preventSimulatorEmulator != null:
     System.out.println("Prevent Simulator/Emulator: " + preventSimulatorEmulator);

 Console.WriteLine("Fences:");
 for (var fence in fences) {
     if fence instanceof CircleGeoFence:
         System.out.println("  " + fence.getName() + ":");
         System.out.println("    Latitude:    " + fence.getLatitude());
         System.out.println("    Longitude:   " + fence.getLongitude());
         System.out.println("    Radius:      " + fence.getRadius());
     else:
         System.out.println("  " + fence.getName() + ":");
         System.out.println("    Country:     " + fence.getCountry());
         System.out.println("    Admin Area:  " + fence.getAdministrativeArea());
         System.out.println("    Postal Code: " + fence.getPostalCode());
 }
policy = client.get_advanced_service_policy(service_id)
if hasattr(policy, "minimum_amount"):
    print("Required Factors:     " + policy.minimum_amount)
if hasattr(policy, "require_inherence"):
    print("Inherence Required:   " + policy.require_inherence
    print("Knowledge Required:   " + policy.require_knowledge
    print("Possession Required:  " + policy.require_possession
if hasattr(policy, "inside"):
    print("Inside Policy:   " + policy.inside
    print("Outside Policy:   " + policy.outside

if hasattr(policy, "jailbreak_protection"):
    print("Prevent Rooted/Jailbroken: " + policy.jailbreak_protection)
if hasattr(policy, "prevent_simulator_emulator"):
    print("Prevent Simulator/Emulator: " + policy.prevent_simulator_emulator)


print("Geofence Locations:")
for fence in policy.fences:
    print("  " + fence.name + ":")
    if hasattr(fence, "latitude"):
        print("    Latitude:    " + fence.latitude)
        print("    Longitude:   " + fence.longitude)
        print("    Radius:      " + fence.radius)
    elif hasattr(fence, "latitude"):
        print("  " + fence.name + ":");
        print("    Country:     " + fence.country);
        print("    Admin Area:  " + fence.administrative_area);
        print("    Postal Code: " + fence.postal_code);

if hasattr(policy, "time_fences"):
    print("Time Fences:")
    for time_fence in policy.time_fences:
        print("  " + time_fence.name + ":")
        print("    Days:  " + time_fence.days)
        print("    Start: " + time_fence.start_time)
        print("    End:   " + time_fence.end_time)
        print("    TZ:    " + time_fence.timezone)

Remove the Policy

The Remove Advanced Service Policy method removes the Policy for a Service. The method takes the Service ID as the single argument. It does not return a value.

Example:

client.RemoveServicePolicy(serviceId);
client.removeServicePolicy(serviceId);
client.remove_service_policy(service_id)

Process Webhooks

Webhooks allow a service to reduce its load by not performing polling against an external API. An endpoint must be created to receive the webhook HTTP request and update the Directory configuration accordingly. Here is a link to the setup instructions: Webhooks.

Webhooks are HTTP POST requests utilizing a JSON Web Token (JWT) for authorization and validation and a JSON Web Encrypted payload. To process a webhook, the implementation must collect the request headers as a map or dictionary (with the key being a string and the value being a list of strings) and pass it with the request body as a string to the Handle Webhook method.

var context = listener.GetContext();
using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8))
{
    var body = reader.ReadToEnd();
    var headers = new Dictionary<string, List<string>>();
    foreach (var headerName in context.Request.Headers.AllKeys)
    {
        headers.Add(headerName, new List<string>());
        foreach (var headerValue in context.Request.Headers.GetValues(headerName))
        {
            headers[headerName].Add(headerValue);
        }
    }
    Var webhookPackage = directoryClient.HandleWebhook(
            headers, body, context.Request.HttpMethod, context.Request.Url.AbsolutePath);
    if (webhookPackage is DirectoryUserDeviceLinkCompletionWebhookPackage)
    {
        // Handle Device link completion webhook
    }
}
// Spring Web Example
@RequestMapping(value = "/webhook/directory", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void webhook (WebRequest request, @RequestBody String body) throws BaseException {
    Map<String, List<String>> headers = new HashMap<>();
    Iterator<String> headerNames = request.getHeaderNames();
    while (headerNames.hasNext()) {
        String headerName = headerNames.next();
        headers.put(headerName, Arrays.asList(request.getHeaderValues(headerName)));
    }
    WebhookPackage webhookPackage = directoryClient.handleWebhook(headers, body, "POST", "/webhook");
    if (webhookPackage instanceof DirectoryUserDeviceLinkCompletionWebhookPackage) {
        // Handle Device link completion webhook
    }
}
# Flask example
from flask import Flask, request
from launchkey.entities.directory import DeviceLinkCompletionResponse

app = Flask(__name__)

# Path defined in your Directory Webhook URL value
@app.route('/webhook/directory', methods = ['POST'])
def launchkey_directory_webhook():
    package = directory_client.handle_webhook(request.data, request.headers, request.method, request.path)
    if isinstance(package, DeviceLinkCompletionResponse):
        device_id = package.device_id
        device_public_key = package.device_public_key
        device_public_key_id = package.device_public_key_id
        # Notify app / frontend that the user has finished linking

User Contributed

LaunchKey links to user contributed code as a resource to its community. LaunchKey does not in any way guarantee or warrant the quality and security of these code bases. User contributed code is supported by the creators. If you do find a link from the site to user contributed code that is malicious or inappropriate in any way, please report that link to LaunchKey immediately and we will investigate the claim. Submit any issue to LaunchKey support at https://launchkey.com./support. ×