Initializing the SDK
Initialization
The main functionality to the Android SDK is available from a single facade, the OneginiClient
. The OneginiClient
is a singleton which has to be set up once with a OneginiClientBuilder
and fetched via OneginiClient.getInstance()
afterwards.
If you used the SDK Configurator in order to generate a config model, you can simply use OneginiClientBuilder#build()
method to initialize the SDK. In such case the SDK will use reflection and the Context.getPackageName()
method to search for the generated class <your.application.package>.OneginiConfigModel
, that implements the OneginiClientConfigModel
interface. If proper class can't be found, the SDK will throw a OneginiConfigNotFoundException
exception.
If you created your own implementation of the OneginiClientConfigModel
, you can provide it explicitly via OneginiClientBuilder#setConfigModel()
method.
Either way the OnginiClientConfigModel
values will be validated during OneginiClientBuilder#build()
method call to make sure all the values are set, in case of any issues IllegalArgumentException
will be thrown and its message will tell you what's wrong.
The OneginiClientBuilder
constructor has three mandatory parameters, these are applicationContext
, OneginiCreatePinRequestHandler
and OneginiPinAuthenticationRequestHandler
. Read more about PIN authentication on Authenticate user with PIN page.
Code example OneginiClient initialization
SDK Start
When users starts the application first call that you should perform on the SDK is OneginiClient#start
method. The method is responsible for
asynchronous initialization of the SDK. During this process the SDK can return errors, for example if the device is using deprecated android version or when the
app version is outdated. Because of that the method expects a OneginiInitializationHandler
in order to return initialization results.
Please note that no other SDK methods should be called before the start()
method completes. Doing so has the potential to create race conditions that may lead
to issues such as user or device deregistration.
When the SDK is successfully initialized the onSuccess
method will be called. The Set
that is passed in the method contains profiles that were detected on
the device but removed on the Token Server side. In such case the SDK removes outdated profiles from and indicates which profiles were removed, so you can
perform additional actions if needed (for example remove additional data from your app's memory).
If something wrong happens during initialization, the SDK will call onError
method with OneginiInitializationError
object containing error details. In some
cases you might want to ignore some errors. For example some apps could ignore OneginiInitializationError.NETWORK_CONNECTIVITY_PROBLEM
error type and allow
user to perform some operations offline. On the other hand errors like OneginiInitializationError.OUTDATED_APP
should be handled as soon as possible, because
the SDK will return the same error in other calls (like authenticateUser
) as long as they are not resolved. In case
OneginiInitializationError.DEVICE_DEREGISTERED
occur, you should clear local storage from device and all user's related data.
Code example OneginiClient start