Overview

OwnID Elite offers fully guided, secure, and streamlined webview screens for authentication. They can be easily customized with your brand’s look and feel.

Prerequisites

Create OwnID Instance

Update your Application class to use the create an OwnID Instance:

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        // Create instance of OwnId
        OwnId.createInstanceFromFile(
            context = applicationContext,
            configurationAssetFileName = "ownIdSdkConfig.json",
            productName = "<yourAppName>/<yourAppVersion>" // will be used in the user agent string
        )
    }
}

Implementation

Elite provides pre-built webview authentication screens that can be easily customized. Implementation involves creating providers and setting up event handlers.

Providers Setup

Providers allow you to define how users are authenticated, how sessions are maintained and how accounts are managed within the application. All providers use suspend functions.

Create the following providers:

  • Session Provider: Manages user session creation.
  • Account Provider: Handles account creation. If you want to handle account creation on your own, skip this provider. You will use the onAccountNotFound event handler explained later in this guide.
  • Authentication Provider: Manages various authentication mechanisms, including Password-based authentication provider.

Here’s an example of providers setup:

OwnId.providers {
    session { // Session Provider
        create { loginId: String, session: String, authToken: String, authMethod: AuthMethod? ->
            // Create a user session using the provided data.
            // Return an AuthResult indicating success or failure.
        }
    }

    account { // Account Provider (skip if using your own registration UI)
        register { loginId: String, profile: String, ownIdData: String?, authToken: String? ->
            // Register a new account with the given loginId and profile data. 
            // Set ownIdData to the user profile if available.
            // Return an AuthResult indicating the outcome of the registration.
        }
    }

    auth {
        password { // Password-based Authentication Provider
            authenticate { loginId: String, password: String ->
                // Authenticate the user with the provided loginId and password. 
                // Return an AuthResult to indicate success or failure. 
            }
        }
    }
}

Check an example of OwnId.providers implementation here

Start Authentication

To start the authentication flow, call the start() function. You can define event handlers for specific actions and responses within the authentication flow. They allow to customize behavior when specific events occur. All event handlers are optional.

OwnId.start {
    events {
        onNativeAction { name, params ->
            // Called when a native action is requested by other event handlers, such as `onAccountNotFound`.
            // Auth screen is currently closed or will be closed in a moment.
            // Run native actions such as user registration.
        }
        onAccountNotFound { loginId, ownIdData, authToken ->
            // Called when the specified account details do not match any existing accounts.
            // Call your own registration logic or UI. 
            // Return PageAction.Close to close the OwnID auth screen and continue.
            PageAction.Close
        }
        onFinish { loginId, authMethod, authToken ->
            // Called when the authentication flow successfully completes.
            // Auth screen is currently closed or will be closed in a moment.
            // Define post-authentication actions here, such as session management or navigation.
        }
        onError { cause ->
            // Called when an error occurs during the authentication flow.
            // Auth screen is currently closed or will be closed in a moment.
            // Handle errors gracefully, such as logging or showing a message to the user.
        }
        onClose {
            // Called when the authentication flow is closed, either by the user or automatically.
            // Auth screen is currently closed or will be closed in a moment.
            // Define any cleanup or UI updates needed.
        }
    }
}

Check an example of OwnId.start implementation here

Was this page helpful?