react-native-u2f
This module is a simple wrapper to Android's U2fApiClient https://developers.google.com/android/reference/com/google/android/gms/fido/u2f/U2fApiClient
There is no implementation for iOS. Feel free to contribute with an iOS native module.
Getting started
React Native 0.60 or later
Simply install with:
$ yarn add react-native-u2f
or
$ npm install react-native-u2f
React Native before 0.60
$ npm install react-native-u2f --save
Mostly automatic installation
$ react-native link react-native-u2f
Manual installation
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.ReactNativeU2f.U2fPackage;
to the imports at the top of the file - Add
new U2fPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-u2f' project(':react-native-u2f').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-u2f/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-u2f')
Usage
Error codes
//Some error occurred on the Java codeconst errorNames = "0": "NATIVE_ERROR"; //Those are from FIDO specs and will come from the security keyconst errorNames = "1": "OTHER_ERROR" "2": "BAD_REQUEST" "3": "CONFIGURATION_UNSUPPORTED" "4": "DEVICE_INELIGIBLE" "5": "TIMEOUT";
Sign
;; { React;}
Register
;; { React;}
Credits
Credits for inspiration/parts of the code in this package:
u2f-api https://github.com/grantila/u2f-api
Android security-samples https://github.com/android/security-samples/tree/master/Fido
React Native - Native Modules Guide https://facebook.github.io/react-native/docs/native-modules-android