Magic Link Registration for Web Accounts

HYPR SDK for Android

📘

This document assumes that your application has been configured using Web Authentication Setup.

HYPR SDK for Android allows for registration using deep links and Magic Links.

Setup

Follow the Firebase documentation for setting up Dynamic Links for your Android App.

To support Firebase Dynamic Links for registration, add the following Firebase dependencies in app/webaccountunlock/app/build.gradle:

dependencies {
    // Out of Band Authentication
    implementation platform('com.google.firebase:firebase-bom:29.0.3')
    implementation 'com.google.firebase:firebase-messaging:20.2.1'
}

Within AndroidManifest.xml and the activity that handles the Magic Link, specify the Uniform Resource Identifiers (URIs) to which it will respond:

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <!-- Accepts URIs that begin with "hypr://register” -->
        <data
            android:host="register"
            android:scheme="hypr" />
        <!-- Accepts URIs that begin with "http://hypr.com/mobileregister” -->
        <data
            android:host="hypr.com"
            android:pathPrefix="/mobileregister"
            android:scheme="http" />
        <!-- Accepts URIs that begin with "https://hypr.com/dynamiclink” -->
        <data
            android:host="hypr.com"
            android:pathPrefix="/dynamiclink"
            android:scheme="https" />
        <!-- note that the leading "/" is required for pathPrefix-->
    </intent-filter>
</activity>

Place the following code within the activity that processes the Dynamic Link:

@Override
protected void onResume() {
    super.onResume();
    onResumeStart();
}
    
public boolean doesIntentContainDynamicLink() {
    boolean doesIntentContainDynamicLink = getIntent() != null
            && getIntent().getData() != null
            && getIntent().getData().toString().contains("https://hyprapp.page.link");
    return doesIntentContainDynamicLink;
}

public void startDynamicLinkIntent() {
    if (getIntent() != null) {
        FirebaseDynamicLinks.getInstance()
                .getDynamicLink(getIntent())
                .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
                    @Override
                    public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
                        setIntent(null);
                        if (pendingDynamicLinkData != null) {
                            Uri uri = pendingDynamicLinkData.getLink();

                            Intent magicLinkIntent = new Intent();
                            magicLinkIntent.setData(uri);
                            onNewIntent(magicLinkIntent);
                            onResumeStart();
                        }
                    }
                });
    }
}

private void onResumeStart(){
    if (isMagicLinkUriAvailable()) {
        HyprActions.getInstance().addMachineWithMagicLink(this, new HyprActionCallbacks.HyprActionCallback() {
            @Override
            public void onSuccess(@NonNull HyprStatusResult hyprStatusResult) {
                toast("sucess");
            }

            @Override
            public void onFailure(@NonNull HyprStatusResult hyprStatusResult) {
                toast("fail");
            }
        });
    }
    else if(doesIntentContainDynamicLink()) {
        startDynamicLinkIntent();
    }
}


private boolean isMagicLinkUriAvailable() {
    boolean isMagicLinkUriAvailable = HyprApp.getDbAdapter().isMagicLinkUriAvailable(this);
    return isMagicLinkUriAvailable;
}