The SecucardConnect class

Introduction

When you are using our SDKs, the communication details with our servers are abstracted away for you. You don't need to send data to our servers, poll for replies and parse to and from JSON formatted data. All SDK functionality is available through the SecucardConnect class. This class contains a static Create method, which you can invoke to obtain a SecucardConnect object. You use this object throughout the lifetime of your application.

There are two things you need to provide before being able to create this object. These are:

  • Client credentials for authentication
  • A cache object for data storage

Credentials

The use of credentials and different authentication methods has been explained before, in authentication and authorization. The credentials are to be provided in an object implementing the Client Authorization interface as described in your SDK-specific documentation. Basically, this object provides the SDK with client credentials and authorization tokens. That interface is defined as follows: Class Diagram IClientAuth

A sample implementation of such class is:

private class ClientAuthDetails : AbstractClientAuthDetails, IClientAuthDetails
{
    public OAuthCredentials GetCredentials()
    {
        return new DeviceCredentials("Client!234", "myPassw0rd", "/vendor/test/serial/1234");
    }

    public ClientCredentials GetClientCredentials()
    {
        return (ClientCredentials) GetCredentials();
    }
}

Cache storage

The cache object for storage of data is used to store refresh tokens and other data necessary for the SDK to function properly. Depending on your scenario, you may opt to cache data in memory, on a filesystem, in a distributed key/value store or any other possibility we cannot foresee. Although you are free to choose the best strategy for your scenario, we provide you with a simple implementation of in-memory cache storage. All cache storage objects need to implement the Datastorage interface, which is defined as follows:

Class Diagram IDatastorage

To use the sample in-memory cache storage, simply instantiate it:

var cache = new MemoryDataStorage()

SecucardConnect object

Now that you have the credentials and cache storage ready, you can Create the SecucardConnect object. The following code snippet shows an example of how to create this object:

private static void Main(string[] args)
{
    var properties = Properties.Load("SecucardConnect.config");
    clientConfiguration = new ClientConfiguration(properties)
    {
        ClientAuthDetails = new ClientAuthDetails(),
        DataStorage = new MemoryDataStorage()
    };

    var Client = SecucardConnect.Create(clientConfiguration);
}

Connection After Creating your SecucardConnect object using the credentials and cache storage provided by you, you can initiate a connection by invoking the object's Open method. This initiates authentication and stores the refresh token in the cache storage object you provided. The class instance automatically deals with authorization and session management for you. Opening a connection is as easy as:

Client.Open();

The code snippets from this moment on assume that there is a SecucardConnect object named Client, which has been Open()ed, as shown above.

Services

The SecucardConnect object provides access to all services. As you can see in the following diagram, one such service is the Smart service.

Class Diagram SecucardConnect


Now you know how to connect to our servers and have access to our services, we will describe each of these services in the Smart object.