MYDIGIPASS.COM Mobile App Authentication SDK for Android
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
MYDIGIPASS_SDK
gradle/wrapper
.gitignore
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

MYDIGIPASS Mobile App Authentication SDK for Android

About the SDK

The SDK connects your mobile application with the MYDIGIPASS Authenticator allowing you to reuse your server integration of the Secure Connect API in your mobile app.

Installation

  1. Download the latest version of our SDK in the release section
  2. Move the binary file into your app's libs folder; The file extension is .aar.
  3. Add the compile(name: 'mydigipass-sdk-file-name-in-the-libs-folder', ext: 'aar') dependency to the app's build.gradle file
  4. Rebuild your application

Getting started

Client ID, bundle identifier and redirect URI for your mobile app

To configure the MDPMobile instance you need to use a MYDIGIPASS client ID and register your bundle identifier and a redirect URI specific to your mobile app:

  1. Create an application at https://developer.mydigipass.com/ to get a client ID
  2. Register the bundle identifier of your mobile app and the redirect URI by editing the OAuth URIs of your application

Example:

  • bundle identifier: com.yourcompany.com.your-app
  • redirect URI: your-app://mydigipass-login

Configuring the mobile app redirect URI

Once you have done the above, it's time to configure your Android project by registering your mobile redirect URI so that we can redirect the user back to your mobile app on successful login.

In the example below we register MyActivity in the AndroidManifest.xml file of your app to open when a person gets redirected to your-app://mydigipass-login:

  <activity android:name="MyActivity">
    <intent-filter>
      <action android:name="android.intent.action.VIEW"/>

      <category android:name="android.intent.category.DEFAULT"/>
      <category android:name="android.intent.category.BROWSABLE"/>

      <data
          android:host="mydigipass-login"
          android:scheme="your-app"
          />
    </intent-filter>
  </activity>

Note:

If you know nothing about Intents and Intent Filters we suggest you to read the documentation at https://developer.android.com/guide/components/intents-filters.html.

More information about how the example above works can be found at https://developer.android.com/training/app-indexing/deep-linking.html.

Initialization of the SDK

Initialize the SDK in the onCreate callback method of your Activity:

public class MyActivity extends Activity {

  private MDPMobile mydigipass;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initialize the MYDIGIPASS SDK.
    mydigipass = new MDPMobile(this);
  }
}

Using your Client ID and mobile app redirect URI with the SDK

Configure your mobile redirect URI and client ID in the onCreate callback method of your Activity:

public class MyActivity extends Activity {

    private MDPMobile mydigipass;

    protected void onCreate(Bundle savedInstanceState) {
        // Other code

        // Configure your MYDIGIPASS client ID.
        mydigipass.setClientId("your-mdp-client-id");

        // Configure your MYDIGIPASS redirect URI.
        mydigipass.setRedirectUri("your-app://mydigipass-login");
    }
}

Handling incoming data (intent)

Allow your app to deal with incoming data from the MYDIGIPASS website and the MYDIGIPASS app:

public class MyActivity extends Activity {

    private MDPMobile mydigipass;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // Other code

        // Handles an incoming intent triggered by the MYDIGIPASS website.
        mydigipass.webFlow();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // Handles an incoming intent triggered by the MYDIGIPASS app.
        mydigipass.handleResult(requestCode, resultCode, data);
    }
}

Performing an authentication request

To perform an authentication request you need to call the authenticate method on the MDPMobile instance.

This method accepts three parameters:

  1. state, mandatory, may not be null
  2. scope, optional, may be null
  3. passthroughParams, optional, may be null

A brief description about these parameters, more information can be found at https://developer.mydigipass.com/:

  • State: To track state, e.g. to remember that a user pressed the Secure Login Button on your application’s user profile page and to prevent CSRF attacks.
  • Scope: The scope of the user data you want to retrieve (e.g. email).
  • Passthrough parameters: Any other parameters you want use to pass information and/or state to your server's redirect endpoint.

Example:

public class MyActivity extends Activity implements OnMDPAuthenticationListener {

    private MDPMobile mydigipass;

    // Other code

    public void myButtonClick(View view) {
        Map<String, String> passthroughParameters = new HashMap<>();
        passthroughParameters.put("redirect_to", "dashboard");
        passthroughParameters.put("new_user", "yes");

        mydigipass.authenticate("xyzabc1234567", "email phone", passthroughParameters);
    }
}

Notes:

Callbacks

When an authentication has been performed by the SDK it will trigger a callback.

Set the MYDIGIPASS authentication listener to enable authentication callbacks:

public class MyActivity extends Activity implements OnMDPAuthenticationListener {

    private MDPMobile mydigipass;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // Other code

        // Sets the MYDIGIPASS authentication listener to enable authentication callbacks
        mydigipass.setMDPAuthenticationListener(this);
    }

    // Other code
}

Use the OnMDPAuthenticationListener listener in your Activity and implement the onMDPAuthenticationSuccess and onMDPAuthenticationFail methods to execute code on authentication success or failure:

public class MyActivity extends Activity implements OnMDPAuthenticationListener {

    // Other code

    @Override
    public void onMDPAuthenticationSuccess(MDPResponse response) {
        String authorizationCode = response.getAuthorizationCode();
        String state = response.getState();
    }

    @Override
    public void onMDPAuthenticationFail(MDPResponse response) {
        if (response != null) {
            Error error = response.getError();
        }
    }
}

Note: More information about the MDPResponse object can be found in the attached javadoc.

Building from scratch

To build the project from scratch you need to check out this project and run the gradle command assembleRelease. You can also open it in Android studio and use the gradle menu to build. This will generate an .aar file under MYDIGIPASS_SDK/build/outputs.