{"id":13658605,"url":"https://github.com/icerockdev/moko-biometry","last_synced_at":"2025-08-11T07:38:15.071Z","repository":{"id":44882690,"uuid":"329245775","full_name":"icerockdev/moko-biometry","owner":"icerockdev","description":"Biometry authentication with Touch ID, Face ID from common code with Kotlin Multiplatform Mobile","archived":false,"fork":false,"pushed_at":"2023-07-31T08:30:42.000Z","size":147,"stargazers_count":42,"open_issues_count":5,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-08-02T05:09:12.739Z","etag":null,"topics":["android","ios","kotlin-multiplatform","kotlin-multiplatform-mobile","kotlin-native","moko"],"latest_commit_sha":null,"homepage":"https://moko.icerock.dev","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/icerockdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-01-13T08:45:58.000Z","updated_at":"2024-05-16T22:34:36.000Z","dependencies_parsed_at":"2024-01-17T03:30:18.269Z","dependency_job_id":null,"html_url":"https://github.com/icerockdev/moko-biometry","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icerockdev%2Fmoko-biometry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icerockdev%2Fmoko-biometry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icerockdev%2Fmoko-biometry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icerockdev%2Fmoko-biometry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icerockdev","download_url":"https://codeload.github.com/icerockdev/moko-biometry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223952547,"owners_count":17230908,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","ios","kotlin-multiplatform","kotlin-multiplatform-mobile","kotlin-native","moko"],"created_at":"2024-08-02T05:01:01.074Z","updated_at":"2025-04-24T11:32:12.022Z","avatar_url":"https://github.com/icerockdev.png","language":"Kotlin","readme":"![moko-biometry](https://user-images.githubusercontent.com/5010169/128705751-e76a78a4-e367-4d4f-a643-b90e250a6f22.png)  \n[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) [![Download](https://img.shields.io/maven-central/v/dev.icerock.moko/biometry) ](https://repo1.maven.org/maven2/dev/icerock/moko/biometry) ![kotlin-version](https://kotlin-version.aws.icerock.dev/kotlin-version?group=dev.icerock.moko\u0026name=biometry)\n\n# Mobile Kotlin biometry\n\nThis is a Kotlin Multiplatform library that provides authentication by FaceId and TouchId(Fingerprint)\n\n## Table of Contents\n\n- [Features](#features)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Samples](#samples)\n- [Set Up Locally](#setup-locally)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Features\n\n- **Biometric user authentication** - allows you to use familiar user authentication methods from business logic\n- **Compose Multiplatform** support (partly, mobile platforms: Android, iOS)\n\n## Requirements\n\n- Gradle version 6.8+\n- Android API 16+\n- iOS version 11.0+\n\n## Installation\n\nroot build.gradle\n\n```groovy\nallprojects {\n    repositories {\n        mavenCentral()\n    }\n}\n```\n\nproject build.gradle\n\n```groovy\ndependencies {\n    commonMainApi(\"dev.icerock.moko:biometry:0.4.0\")\n\n    // Compose Multiplatform\n    commonMainApi(\"dev.icerock.moko:biometry-compose:0.4.0\")\n\n    // Jetpack Compose (only for android, if you don't use multiplatform)\n    implementation(\"dev.icerock.moko:biometry-compose:0.4.0\")\n}\n```\n\n## Usage\n\n**common**\n\nIn `commonMain` we should create `ViewModel` like:\n\n```kotlin\nclass SampleViewModel(\n    val biometryAuthenticator: BiometryAuthenticator\n) : ViewModel() {\n\n    fun tryToAuth() = viewModelScope.launch {\n        try {\n            val isSuccess = biometryAuthenticator.checkBiometryAuthentication(\n                requestTitle = \"Biometry\".desc(),\n                requestReason = \"Just for test\".desc(),\n                failureButtonText = \"Oops\".desc(),\n                allowDeviceCredentials = false // true - if biometric permission is not granted user can authorise by device creds\n            )\n\n            if (isSuccess) {\n                // Do something onSuccess\n            }\n        } catch (throwable: Throwable) {\n            // Do something onFailed\n        }\n    }\n}\n```\n\nAfter create ViewModel, let's integrate on platform.\n\n**Android**\n\n```kotlin\nclass MainActivity : AppCompatActivity() {\n\n    private lateinit var viewModel: SampleViewModel\n\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        setContentView(R.layout.activity_main)\n\n        // Create viewModel from common code.\n        viewModel = getViewModel {\n            SampleViewModel(\n                // Pass platform implementation of the Biometry Authenticator\n                // to a common code\n                biometryAuthenticator = BiometryAuthenticator(\n                    applicationContext = applicationContext\n                )\n            )\n        }\n\n        // Binds the Biometry Authenticator to the view lifecycle\n        viewModel.biometryAuthenticator.bind(\n            lifecycle = this@MainActivity.lifecycle,\n            fragmentManager = supportFragmentManager\n        )\n    }\n}\n```\n\n**Compose:**\n\nIn compose for android, the MainActivity is extended from ComponentActivity, we need to change it to FragmentActivity\n\n```kotlin\nclass MainActivity : FragmentActivity() {\n\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        setContentView(R.layout.activity_main)\n\n        setContent {\n            val biometryFactory: BiometryAuthenticatorFactory = rememberBiometryAuthenticatorFactory()\n\n            // Create viewModel from common code\n            val viewModel = getViewModel {\n                SampleViewModel(\n                    // Pass platform implementation of the Biometry Authenticator\n                    // to a common code\n                    biometryAuthenticator = biometryFactory.createBiometryAuthenticator()\n                )\n            }\n\n            // Binds the Biometry Authenticator to the view lifecycle\n            BindBiometryAuthenticatorEffect(viewModel.biometryAuthenticator)\n\n            // Same screen content here\n        }\n    }\n}\n```\n\n**iOS:**\n\n```swift\nclass SampleViewController: UIViewController {\n    \n    private var viewModel: SampleViewModel!\n        \n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        self.viewModel = SampleViewModel(\n            biometryAuthenticator: BiometryBiometryAuthenticator(),\n        )\n    }\n    \n    @IBAction private func loginAction() {\n        self.viewModel.tryToAuth()\n    }\n}\n```\n\nAdditionally, you need add `NSFaceIDUsageDescription` key in Info.plist of your project:\n\n```swift\n\u003ckey\u003eNSFaceIDUsageDescription\u003c/key\u003e\n\u003cstring\u003e$(PRODUCT_NAME) Authentication with TouchId or FaceID\u003c/string\u003e\n```\n\n**Compose Multiplatform:**\n\n```kotlin\n@Composable\nfun BiometryScreen() {\n    val biometryFactory: BiometryAuthenticatorFactory = rememberBiometryAuthenticatorFactory()\n    \n    BiometryScreen(\n        viewModel = getViewModel(\n            key = \"biometry-screen\",\n            factory = viewModelFactory {\n                BiometryViewModel(\n                    biometryAuthenticator = biometryAuthenticatorFactory.createBiometryAuthenticator()\n                )\n            }\n        )\n    )\n}\n\n@Composable\nprivate fun BiometryScreen(\n    viewModel: BiometryViewModel\n) = NavigationScreen(title = \"moko-biometry\") { paddingValues -\u003e\n    BindBiometryAuthenticatorEffect(viewModel.biometryAuthenticator)\n\n    val text: String by viewModel.result.collectAsState()\n\n    Column(\n        modifier = Modifier.fillMaxSize().padding(paddingValues),\n        horizontalAlignment = Alignment.CenterHorizontally\n    ) {\n        Text(text = text)\n\n        Button(onClick = viewModel::onButtonClick) {\n            Text(text = \"Click on me\")\n        }\n    }\n}\n```\n\n## Samples\n\nPlease see more examples in the [sample directory](sample).\n\n## Set Up Locally\n\n- The [biometry directory](biometry) contains the `biometry` library;\n- The [sample directory](sample) contains sample apps for Android and iOS; plus the mpp-library connected to the apps.\n\n## Contributing\n\nAll development (both new features and bug fixes) is performed in the `develop` branch. This way `master` always\ncontains the sources of the most recently released version. Please send PRs with bug fixes to the `develop` branch.\nDocumentation fixes in the markdown files are an exception to this rule. They are updated directly in `master`.\n\nThe `develop` branch is pushed to `master` on release.\n\nFor more details on contributing please see the [contributing guide](CONTRIBUTING.md).\n\n## License\n\n    Copyright 2021 IceRock MAG Inc.\n    \n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n    \n       http://www.apache.org/licenses/LICENSE-2.0\n    \n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":[],"categories":["Libraries"],"sub_categories":["📱 Device"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficerockdev%2Fmoko-biometry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficerockdev%2Fmoko-biometry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficerockdev%2Fmoko-biometry/lists"}