onfido-android-sdk icon indicating copy to clipboard operation
onfido-android-sdk copied to clipboard

Provide better API for TokenExpirationHandler

Open WildOrangutan opened this issue 2 years ago • 3 comments

Issue

Since TokenExpirationHandler needs to be Serializable, it limits what kind of dependencies you can have. Dependency injection is not possible because of it, which makes it hard to avoid non-testable code or code duplication.

Suggestion

Please provide better API, so we can do dependency injection.

Maybe you could at least provide us with context reference, so we can obtain specific object instance by using entry points? For example:

class OnfidoExpirationHandler() : TokenExpirationHandler {
    override fun refreshToken(injectNewToken: (Context, String?) -> Unit) {
        injectNewToken( context, _ ->
            val api = EntryPoints.get(context, ApiEntryPoint.class).getApi()
            api.getOnfidoSdkToken()
        }
    }
}

Version

onfido-capture-sdk version: 11.3.0

WildOrangutan avatar Mar 03 '22 16:03 WildOrangutan