Switch to dark theme

Switch to light theme

Background #

Cipher EIAM SDK helps to provide authentication functionality to your customers in a simple and convenient way. The SDK exposes various functions that eases your life that you can quickly use for your authentication uses cases for your application.

Preconditions #

Before you begin, take care of the following prerequisites before you begin with SDK setup:

  1. Get access to Apollo App Center
  2. Download the SSO SDK/Cipher_SSO.json from the Apollo App Center for your tenant, domain and sandbox

For downloading the SDK from Apollow App Center please follow this doc

Step 1 - Setting up your environment #

  • Install or update Android Studio to its latest version
  • Make sure your projects meet the following requirements:
    • Target API level 28 or later
    • Min API level 19
  • Set up a physical device (preferred as you won’t be able to use device binding otherwise) or use an emulator to run your app. Emulators must use an emulator image with Google Play.
  • Have jitpack and google maven repos added to your project gradle.
  • You have the employeename and password handy for accessing the SDK artifacts from our maven repo.
  • You have the cipher_sso.json config file from the Apollo App Center.
  • You use Java 8 or above

Step 2 - Get Access to the Cipher EIAM SDK #

We host all our SDKs on a remotely accessible Maven Repositry. Gradle understands the semantics of a maven repository and can download the SDK artifacts ( aar files) from a remotely hosted maven repository.

Add the following lines to your project level build.gradle

allprojects { \
    repositories { \
        .... \
        maven { \
            credentials  { \
                employeename = "<usename>" \
                password = "<password>" \
            } \
            url 'https://apollo-sdk.zetaapps.in/repository/maven-releases/' \
            authentication { \
                basic(BasicAuthentication) \
            } \
        } \
        ....         \
    } \
}

Step 3 - Adding the Cipher EIAM SDK #

  1. To your module (app-level) Gradle file (usually app/build.gradle), add the dependency for the cipher SDK
dependencies {
    ............
    implementation 'in.zeta.apollo:ciphersecurity:<latest-version>'
    .............
}
  1. Add kotlin jVM target to your if you are using Kotlin as your programming language
android {
  ........
  kotlin_options = {
         jvmTarget = "1.8"
      	}
  .......
}
  1. (Optional) Custom packaging options if you face issues with packaging:
android {
..........
  packagingOptions {
     exclude 'META-INF/library_release.kotlin_module'
     exclude 'META-INF/DEPENDENCIES'
  }
.......
}

Step 4 - Adding permissions #

Add the following permissions in your app’s AndroidManifest.xml.

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

Step 5 - Adding the config json file #

Add the cipher_sso.json file received from Apollo App Center to the app/src/main/assets folder. A sample file looks like this

{

"oauthTenantId": XXXX,
 "zone": "U",                     // environment (prepro/staging/prod)
 "enableDeviceBinding": true,
 "authDataInSecuredStore": true //flag to stare private key from SSO & auth-token & refreshToken in secured (encrypted) store

}

Zone :- The environment on which you will be testing (such as staging/prod)

EnableDeviceBinding :- This flag will enable you to mandate device binding

AuthDataInSecureStore :- This flag signifies that the sensitive data such as authToken, refreshToken and the privateKey will be stored in a secure store.

If turned off the data will be stored in normal shared-preference of the application.

Step 6 - Instantiating Cipher EIAM SDK #

Once you complete the Setup for sdk, you are now ready to create an instance of CipherSecurityService. Add the following code to your app’s Application class (Create one if you haven’t yet). Inside your Application class, add the following code.

private static CipherSecurityService cipherSecurityService; private static void setupCipherSecurity(Application application) {

cipherSecurityService = new CipherSecurityBuilder(application) .setGoogleApiKey(application.getString(R.string.safety_net_api_key)) .build();

cipherSecurityService.setSSOStateListener(new CipherSecurityService.CipherSSOStateListener() { @Override

public void onSSOResult(boolean ssoSuccess) {

if(ssoSuccess) {

/**Your SSO is successful here, you may fetch auth token now**/

fetchAuthToken()

}

}

});

}

Why fetch Auth Token ?

Once your employee has done SSO, then you need auth-Token which you can use to authenticate other sdks.

private void fetchAuthToken() {

cipherSecurityService.addAuthenticationListener(new OAuthAuthenticationListener() {

@SuppressLint("CheckResult")

@Override

public void authenticationDone() {

cipherSecurityService.removeAuthenticationListener(this);

cipherSecurityService.getAuthToken(applicationContext).subscribe(token -> { /** your auth token fetched here **/

},error -> {

/** error fetching auth token **/

});

}

}, applicationContext); }