All Projects → afollestad → Assure

afollestad / Assure

Licence: apache-2.0
A Kotlin library that makes biometric authentication quick and easy.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Assure

Inline Activity Result
Receive Activity results inline, without any boilerplate. Optional coroutines and RxJava support.
Stars: ✭ 298 (+441.82%)
Mutual labels:  rxjava, coroutines
Awesome Android Kotlin Apps
👓 A curated list of awesome android kotlin apps by open-source contributors.
Stars: ✭ 1,058 (+1823.64%)
Mutual labels:  rxjava, coroutines
Mvvm Kotlin Android Architecture
MVVM + Kotlin + Retrofit2 + Hilt + Coroutines + Kotlin Flow + mockK + Espresso + Junit5
Stars: ✭ 1,014 (+1743.64%)
Mutual labels:  rxjava, coroutines
Kpermissions
A Kotlin library which helps to request runtime permissions in Android.
Stars: ✭ 253 (+360%)
Mutual labels:  rxjava, coroutines
RxCoroutineSchedulers
Kotlin Coroutines as RxJava Schedulers 😈
Stars: ✭ 31 (-43.64%)
Mutual labels:  rxjava, coroutines
NewsReader
Android News Reader app. Kotlin Coroutines, Retrofit and Realm
Stars: ✭ 21 (-61.82%)
Mutual labels:  rxjava, coroutines
Fountain
Android Kotlin paged endpoints made easy
Stars: ✭ 175 (+218.18%)
Mutual labels:  rxjava, coroutines
modern-android
Modern Android Project Skeleton
Stars: ✭ 17 (-69.09%)
Mutual labels:  rxjava, coroutines
Runtimepermission
Simpliest way to ask runtime permissions on Android, no need to extend class or override permissionResult method, choose your way : Kotlin / Coroutines / RxJava / Java7 / Java8
Stars: ✭ 860 (+1463.64%)
Mutual labels:  rxjava, coroutines
Mvi Cleanarch
simple code for MVI architecture
Stars: ✭ 45 (-18.18%)
Mutual labels:  coroutines
Rxjavaapp
学习RxJava操作符的APP,新增RxJava2.x介绍
Stars: ✭ 1,049 (+1807.27%)
Mutual labels:  rxjava
Wanandroid
Jetpack MVVM For Wanandroid 最佳实践 !
Stars: ✭ 1,004 (+1725.45%)
Mutual labels:  coroutines
Thirtyinch
a MVP library for Android favoring a stateful Presenter
Stars: ✭ 1,052 (+1812.73%)
Mutual labels:  rxjava
Weaponapp
一个尽量做到极致的集大成App,努力做到最好(开发阶段)——MVVM+Retrofit+RxJava+Small 插件化+单元测试+MD
Stars: ✭ 1,011 (+1738.18%)
Mutual labels:  rxjava
Rxnearby
Nearby handling APIs for Android Apps using RxJava
Stars: ✭ 52 (-5.45%)
Mutual labels:  rxjava
Billing Android
RxJava wrapper for Android Play Billing Library
Stars: ✭ 40 (-27.27%)
Mutual labels:  rxjava
Meteorite
一个基于Android MVP的简单明了的指引性通用架构,目的是帮助更多的开发者去全面了解实践开发相关的各种技术,快速搭建属于自已的APP。这个项目涉及到如下技术的实际应用:1、MVP 2、网络请求(Novate基于rxjava,okhttp,retrofit封装架构)3、DbFlow(可保存文件入SD卡) 4、6.0权限申请 5、XRecyclerView 6、万能Adapter7、异常处理 8、日志打印 9、屏幕适配 10、代码混淆 11、多渠道打包 12、内存泄露检测 13、热修复 14、升级更新 15、极光推送 工程更新完善中……欢迎关注 @特别感谢ZJ.Y的Logo支持。
Stars: ✭ 49 (-10.91%)
Mutual labels:  rxjava
Eyepetizer
🔥基于 Kotlin 语言仿写「开眼 Eyepetizer」的一个短视频 Android 客户端项目,采用 Jetpack + 协程实现的 MVVM 架构。
Stars: ✭ 988 (+1696.36%)
Mutual labels:  coroutines
Sesame
Android architecture components made right
Stars: ✭ 48 (-12.73%)
Mutual labels:  coroutines
Circulerautoscrollingrecyclerview
Sample code of infinite rotation using RecyclerView. Built with Kotlin
Stars: ✭ 48 (-12.73%)
Mutual labels:  rxjava

Assure

Assure is a Kotlin library that makes biometric authentication quick and easy.

Android CI License

Table of Contents

  1. Core
    1. Gradle Dependency
    2. Prompt
    3. Authentication
    4. More on Credentials
    5. More on Encryptor and Decryptor
  2. Coroutines
    1. Gradle Dependency
    2. Usage
  3. RxJava
    1. Gradle Dependency
    2. Usage

Core

Core

Gradle Dependency

dependencies {

  implementation 'com.afollestad.assure:core:0.2.0'
}

Prompt

Before you can begin authentication, you need to know about the Prompt class. Here is the definition:

data class Prompt(
  @StringRes val title: Int,
  @StringRes val subtitle: Int? = null,
  @StringRes val description: Int? = null,
  @StringRes val negativeButtonText: Int? = null,
  val confirmRequired: Boolean = false,
  val deviceCredentialsAllowed: Boolean = false,
  val validityDurationSeconds: Int? = null
)
  • title: Set the title to display.
  • subtitle: Set the subtitle to display.
  • description: Set the description to display.
  • negativeButtonText: Set the text for the negative button. This would typically be used as a "Cancel" button, but may be also used to show an alternative method for authentication, such as screen that asks for a backup password.
  • confirmRequired: Only applies to Q and above. A hint to the system to require user confirmation after a biometric has been authenticated. For example, implicit modalities like Face and Iris authentication are passive, meaning they don't require an explicit user action to complete. When set to 'false', the user action (e.g. pressing a button) will not be required. BiometricPrompt will require confirmation by default.
  • deviceCredentialsAllowed: The user will first be prompted to authenticate with biometrics, but also given the option to authenticate with their device PIN, pattern, or password. Developers should first check [android.app.KeyguardManager.isDeviceSecure()] before enabling.
  • validityDurationSeconds: Sets the duration of time (seconds) for which this key is authorized to be used after the user is successfully authenticated. This has effect if the key requires user authentication for its use. By default, if user authentication is required, it must take place for every use of the key.

Authentication

This library exposes extension methods on FragmentActivity (which any AppCompatActivity is), and Fragment (from AndroidX). Examples are below.

Plain authentication:

val prompt: Prompt = // ...

authenticate(prompt) { error ->
  // If `error` IS null, auth was successful.
}

Authentication to encrypt data: After successful authentication, the Credentials given will now have a populated IV field.

val credentials = Credentials("default")
val prompt: Prompt = // ...
val plainTextData: ByteArray = // ...

authenticateForEncrypt(
    credentials = credentials,
    prompt = prompt
) { error ->
  // If `error` is NOT null, there was an error.Handle with `e.error` and `e.errorMessage`. Else...
  val encryptedData: ByteArray = encrypt(plainTextData)
  ...
}

Authentication to decrypt data: A populated IV is needed in the credentials.

val credentials: Credentials = // ...
val prompt: Prompt = // ...
val encryptedData: ByteArray = // ...

authenticateForDecrypt(
    credentials = credentials,
    prompt = prompt
) { error ->
  // If `error` is NOT null, there was an error.Handle with `error.error` and `error.errorMessage`. Else...
  val decryptedData: ByteArray = decrypt(encryptedData)
  ...
}

More on Credentials

Credentials is a Parcelable, so it can be parcelized. There are also two extension functions on it that can be used to convert Credentials to and from ByteArrays.

val credentials: Credentials = // ...

val serialized: ByteArray = credentials.serialize()
val deserialized: Credentials = Credentials.deserialize(serialized)

This could be used to securely write Credentials to a file where it cannot be found by someone with malicious intent (shared preferences are not recommended for that).


More on Encryptor and Decryptor

Encryptor and Decryptor have a few additional useful methods. These are the classes that are this in the callbacks of authenticateForEncrypt(...) { } and authenticateForDecrypt(...) { }.

interface Encryptor {

  /** Encrypts a [ByteArray] and returns the result. */
  fun encrypt(data: ByteArray): ByteArray

  /** Encrypts a [String] with a given [charset] and returns the result. */
  fun encrypt(
    data: String,
    charset: Charset = Charset.defaultCharset()
  ): ByteArray

  /** Encrypts a [String] and returns a Base64 representation of the result. */
  fun encryptToString(
    data: String,
    charset: Charset = Charset.defaultCharset()
  ): String
}
interface Decryptor {

  /** Encrypts a [ByteArray] and returns the result. */
  fun decrypt(data: ByteArray): ByteArray

  /** Decrypts an encrypted [ByteArray] and returns the result. */
  fun decryptToString(
    data: ByteArray,
    charset: Charset = Charset.defaultCharset()
  ): String

  /** Decrypts a Base64 [String] to an original [String]. */
  fun decryptToString(
    data: String,
    charset: Charset = Charset.defaultCharset()
  ): String
}

Coroutines

Coroutines

Gradle Dependency

dependencies {

  implementation 'com.afollestad.assure:coroutines:0.2.0'
}

Usage

Coroutines allow you to perform biometric authentication without the callback. These extension functions must happen within a suspend function or CoroutineScope.

Plain authentication:

import com.afollestad.assure.coroutines.authenticate

try {
  authenticate(prompt)
  ...
} catch(e: BiometricErrorException) {
  // Handle error with `e.error` and `e.errorMessage`
}

Authentication to encrypt data: After successful authentication, the Credentials given will now have a populated IV field.

import com.afollestad.assure.coroutines.authenticateForEncrypt

val credentials = Credentials("default")
val prompt: Prompt = // ...
val plainTextData: ByteArray = // ...

try {
  val encryptor: Encryptor = authenticateForEncrypt(credentials, prompt)
  val encryptedData: ByteArray = encryptor.encrypt(plainTextData)
  ...
} catch(e: BiometricErrorException) {
  // Handle error with `e.error` and `e.errorMessage`
}

Authentication to decrypt data: A populated IV is needed in the credentials.

import com.afollestad.assure.coroutines.authenticateForDecrypt

val credentials: Credentials = // ...
val prompt: Prompt = // ...
val encryptedData: ByteArray = // ...

try {
  val decryptor: Decryptor = authenticateForDecrypt(credentials, prompt)
  val decryptedData: ByteArray = decryptor.decrypt(encryptedData)
  ...
} catch(e: BiometricErrorException) {
  // Handle error with `e.error` and `e.errorMessage`
}

RxJava

RxJava

Gradle Dependency

dependencies {

  implementation 'com.afollestad.assure:rxjava:0.2.0'
}

Usage

Coroutines allow you to perform biometric authentication without the callback. These extension functions \must happen within a suspend function or CoroutineScope.

Plain authentication:

import com.afollestad.assure.rxjava.authenticate

val disposable = authenticate(prompt)
    .doOnBiometricError { error ->
      // Handle error with `error.error` and `error.errorMessage`
    }
    .subscribe {
      // Auth was successful, do something
    }

// make sure you manage the subscription
disposable.dispose()

Authentication to encrypt data: After successful authentication, the Credentials given will now have a populated IV field.

import com.afollestad.assure.rxjava.authenticateForEncrypt

val credentials = Credentials("default")
val prompt: Prompt = // ...
val plainTextData: ByteArray = // ...

val disposable = authenticateForEncrypt(credentials, prompt)
    .doOnBiometricError { error ->
      // Handle error with `error.error` and `error.errorMessage`
    }
    .map { encryptor ->
      encryptor.encrypt(plainTextData)
    }
    .subscribe { encryptedData ->
      // Use encryptedData
    }

// make sure you manage the subscription
disposable.dispose()

Authentication to decrypt data: A populated IV is needed in the credentials.

import com.afollestad.assure.rxjava.authenticateForDecrypt

val credentials: Credentials = // ...
val prompt: Prompt = // ...
val encryptedData: ByteArray = // ...

val disposable = authenticateForDecrypt(credentials, prompt)
    .doOnBiometricError { error ->
      // Handle error with `error.error` and `error.errorMessage`
    }
    .map { decryptor ->
      decryptor.decrypt(encryptedData)
    }
    .subscribe { decryptedData ->
      // Use decryptedData
    }

// make sure you manage the subscription
disposable.dispose()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].