Skip to main content

Android

Initial Setup

The LoginID Android SDK enables you to add FIDO-certified authentication in your native Android application without having to redirect the user to any pages outside your application.

For more robust functionality, it is likely that you will need to also leverage a Server SDK. The Server SDK makes requests to LoginID's API easier by leveraging your API Credential. Check out the LoginID Server SDK for a simplified integration.

note

The LoginID Android Mobile SDK requires Android 7+ (API 24+) for compatibility.

Create Application on the Dashboard

An application must be created on the LoginID Dashboard in order to correctly configure the Android SDK.

Once logged into the dashboard, navigate to the Applications tab in the sidebar, select “Add Application,” then select Mobile.

In the resulting form, you must create a name for your application. We generate a Client ID and Base URL for your application, which you will use to configure the SDK.

After entering your application name, you will be prompted to create an API credential. If you have a client-side only application, please skip this step. Otherwise, create an API credential in order to make protected API calls.

note

An API service token must be included on all requests once an API credential is assigned to an application.

Add SDK to Existing Application

Import the LoginID package in your Android studio by including our repository and specifying the latest package name and version to be downloaded.

Secondly, add the LoginID maven repository and credentials to your Android main project build.gradle. This will let you add the configuration to the code.

allprojects {
repositories{
google()
jcenter()
// ADD maven repository to download LoginSDK
maven {
url "https://sdk.dev.loginid.io/repository/maven-releases/"
}
}
}

Lastly, add the following packages to your Android app module build.gradle dependencies

implementation 'login.api.native:android-sdk:0.92.35'

Create an SDK Instance

LoginApi.client().configure(Context context, String clientId, String baseURL)

note

This API must be called before any other APIs. You should call this API within your custom Application's onCreate() method. You can find more information on the process of creating a custom application on Understanding the Android Application Class.

class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
// clientId example 032690b3-9bc4-4602-87c1-60c1fae782f2
val clientId = "<your client id>"
// baseURL example https://060ce487-b934-43d0-a925-b66e80c7532.native-api.auth.company.id
val baseURL = "<your base url>"
LoginApi.client().configure(this,clientId,baseURL)

// any other configurations
...
...
}
}

API Reference

registerWithFido2

Sign up a user for FIDO authentication.

public void registerWithFido2(@NonNull final Activity activity, @NonNull final String username, @Nullable final RegistrationOptions option, @NonNull final RegisterCallback callback)

Where:

RegistrationOptions {
    authorization_token?: string;
}
ParameterTypeRequiredDetails
activityActivitytrueUsing Android biometric api requires the use of FragmentActivity instead of Activity class. This can be done by making sure your calling activity extends the common activity api such as androidx.appcompat.app.AppCompatActivity or androidx.app.fragment.FragmentActivity
usernamestringtrueUsername of the customer to be registered.
optionsRegistrationOptionsoptionalAPI Service token (JWT) signed by your Private Key, as per the API Credential added to the integration. \nRegistrationOptions.buildAuth(token)
callbackRegisterCallbacktrueCallback function to handle returning results (RegisterResponse)

registerWithPassword

Creates a user account with a password (not recommended). If leveraging this method, users should be migrating to use a FIDO authenticator, then have their password revoked.

public void registerWithPassword(@NonNull final String username, @NonNull final String password, @NonNull final String confirmPassword, @Nullable final RegistrationOptions options, @NonNull final RegisterCallback callback)

ParameterTypeRequiredDetails
usernamestringtrueUsername of the customer to be registered.
passwordstringtruePassword of the customer to be registered.
passwordConfirmationstringtrueIt is best practice to have the customer enter their password twice before creating their profile to prevent typos. If desired, you could only require the end user to enter their password once and pass that password in both fields.
optionsRegistrationOptionsoptionalAPI Service token (JWT) signed by your Private Key, as per the API Credential added to the integration. \nRegistrationOptions.buildAuth(token)
callbackRegisterCallbacktrueCallback function to handle returning results (RegisterResponse)

authenticateWithFido2

Authenticate a previously registered user through FIDO2.

public void authenticateWithFido2(@NonNull final Activity activity, @NonNull final String username, @Nullable final AuthenticationOptions options, @NonNull final AuthenticateCallback callback)

ParameterTypeRequiredDetails
activityActivitytrueUsing Android biometric api requires the use of FragmentActivity instead of Activity class. This can be done by making sure your calling activity extends the common activity api such as androidx.appcompat.app.AppCompatActivity or androidx.app.fragment.FragmentActivity
usernamestringtrueUsername of the customer to be registered.
optionsAuthenticationOptionsoptionalAPI Service token (JWT) signed by your Private Key, as per the API Credential added to the integration. \nAuthenticationOptions.buildAuth(token)
callbackAuthenticateCallbacktrueCallback function to handle returning results (AuthenticateResponse)

authenticateWithPassword

Authenticate a previously registered user using username and password.

public void authenticateWithPassword(@NonNull final String username, @NonNull final String password, @Nullable final AuthenticationOptions options, @NonNull final AuthenticateCallback callback)

ParameterTypeRequiredDetails
usernamestringtrueUsername of the customer to be authenticated.
passwordstringtruePassword of the customer to be authenticated.
optionsAuthenticationOptionsoptionalAPI Service token (JWT) signed by your Private Key, as per the API Credential added to the integration. \nAuthenticationOptions.buildAuth(token)
callbackAuthenticateCallbacktrueCallback function to handle returning results (AuthenticateResponse)

confirmTransaction

Confirm the transaction of a text-based payload using registered Fido2 account.

public void transactionConfirmation(@NonNull final Activity activity, @NonNull final String username, @NonNull final TransactionPayload payload, @Nullable final TransactionOptions options, @NonNull final TransactionConfirmationCallback callback)

ParameterTypeRequiredDetails
activityActivitytrueUsing Android biometric api requires the use of FragmentActivity instead of Activity class. This can be done by making sure your calling activity extends the common activity api such as androidx.appcompat.app.AppCompatActivity or androidx.app.fragment.FragmentActivity
usernamestringtrueUsername of the customer to be authenticated.
payloadTransactionPayloadtrueRequire a client side generated nonce value and a text message to display back to user for confirmation\ne.g. TransactionPayload.buildText("<nonce value here>", message);
optionsAuthenticationOptionsoptionalAPI Service token (JWT) signed by your Private Key, as per the API Credential added to the integration. \nTransactionOptions.buildAuth(token)
callbackTransactionConfirmationCallbacktrueCallback function to handle returning results (TransactionConfirmationResponse)

addFido2Credential

Adds a FIDO2 credential type to the account. Can be used to recover an account or add another device to the same username.

public void addFido2Credential(@NonNull final Activity activity, @NonNull final String username, @NonNull final String code, @Nullable final AddCredentialOptions options, @NonNull AddCredentialCallback callback)

ParameterTypeRequiredDetails
activityActivitytrueUsing Android biometric api requires the use of FragmentActivity instead of Activity class. This can be done by making sure your calling activity extends the common activity api such as androidx.appcompat.app.AppCompatActivity or androidx.app.fragment.FragmentActivity
usernamestringtrueUsername of the customer adding a FIDO2 credential.
codestringtrueThe short OTP code required to initiate adding the FIDO2 credential.
optionsAddCredentialOptionsoptionalAPI Service token (JWT) signed by your Private Key, as per the API Credential added to the integration. \nAddCredentialOptions.buildAuth(token)
callbackAddCredentialCallbacktrueCallback function to handle returning results (AddCredentialCallback)

isLoggedIn

Check if a given user is currently logged in.

logout

Deprecated Methods

The Android SDK previously had the following methods:

  • .register()
  • .login()

The methods have been deprecated, as the type of authenticator is now specified in the register and authenticate methods.