All Projects → akvelon → react-native-sms-user-consent

akvelon / react-native-sms-user-consent

Licence: MIT License
React Native wrapper for Android's SMS User Consent API, ready to use in React Native apps with minimum effort.

Programming Languages

java
68154 projects - #9 most used programming language
javascript
184084 projects - #8 most used programming language
objective c
16641 projects - #2 most used programming language
Starlark
911 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to react-native-sms-user-consent

2factor auth
2-Faktor-Authentifizierung mittels one-time-password (OTP)
Stars: ✭ 20 (-55.56%)
Mutual labels:  otp, auth, 2fa
laravel-otp-login
Adds a customizable, translatable, configurable OTP verification step to Laravel Auth. You can add your own SMS provider too.
Stars: ✭ 16 (-64.44%)
Mutual labels:  otp, verification, auth
Otpauth
One Time Password (HOTP/TOTP) library for Node.js, Deno and browsers.
Stars: ✭ 135 (+200%)
Mutual labels:  otp, two-factor, auth
2FAuth
A Web app to manage your Two-Factor Authentication (2FA) accounts and generate their security codes
Stars: ✭ 664 (+1375.56%)
Mutual labels:  otp, two-factor, 2fa
Otplib
🔑 One Time Password (OTP) / 2FA for Node.js and Browser - Supports HOTP, TOTP and Google Authenticator
Stars: ✭ 916 (+1935.56%)
Mutual labels:  otp, two-factor, 2fa
Privacyidea
🔐 multi factor authentication system (2FA, MFA, OTP Server)
Stars: ✭ 1,027 (+2182.22%)
Mutual labels:  otp, two-factor, 2fa
Twofactor totp
🔑 Second factor TOTP (RFC 6238) provider for Nextcloud
Stars: ✭ 203 (+351.11%)
Mutual labels:  otp, two-factor, 2fa
otp-java
A small and easy-to-use one-time password generator library for Java according to RFC 4226 (HOTP) and RFC 6238 (TOTP).
Stars: ✭ 107 (+137.78%)
Mutual labels:  otp, 2fa
ootp
OOTP (Open One-time Password) is a supports multiple programming languages. The generated one-time passwords are fully compliant with HOTP (HMAC-based One-time Password) and TOTP (Time-based One-time Password). 🚀It's easy to use!
Stars: ✭ 17 (-62.22%)
Mutual labels:  otp, one-time
totp
Time-Based One-Time Password Code Generator
Stars: ✭ 76 (+68.89%)
Mutual labels:  two-factor, 2fa
DPOTPView
Customisable OTP view and Passcode view
Stars: ✭ 52 (+15.56%)
Mutual labels:  otp, verification
privacyidea-ldap-proxy
🌲 LDAP Proxy to intercept LDAP binds and authenticate against privacyIDEA
Stars: ✭ 17 (-62.22%)
Mutual labels:  two-factor, 2fa
cerebro-pass
Cerebro plugin for pass.
Stars: ✭ 15 (-66.67%)
Mutual labels:  otp, 2fa
auth
🔑 Laravel Authentication package with built-in two-factor (Authy) and social authentication (Socialite).
Stars: ✭ 39 (-13.33%)
Mutual labels:  auth, 2fa
authorizer
Your data, your control. Fully open source, authentication and authorization. No lock-ins. Deployment in Railway in 120 seconds || Spin a docker image as a micro-service in your infra. Built in login page and Admin panel out of the box.
Stars: ✭ 770 (+1611.11%)
Mutual labels:  auth, 2fa
apache 2fa
Apache two-factor (2FA) authentication with Google Authenticator based on Time-based One-Time Password (TOTP) or HMAC-based one-time password (HOTP) Algorithms.
Stars: ✭ 63 (+40%)
Mutual labels:  two-factor, 2fa
KWVerificationCodeView
A customisable verification code view to capture OTPs
Stars: ✭ 83 (+84.44%)
Mutual labels:  otp, verification
2fa-notifier
2FA Notifier is a web extension that notifies users whether or not the sites they visit support two factor authentication (2FA).
Stars: ✭ 39 (-13.33%)
Mutual labels:  auth, 2fa
node-identif
🔑 Helper class to verify one's identity via personal channels(SMS, Phone, E-Mail and more!)
Stars: ✭ 27 (-40%)
Mutual labels:  verification, 2fa
yoti-php-sdk
The PHP SDK for interacting with the Yoti Platform
Stars: ✭ 22 (-51.11%)
Mutual labels:  verification, 2fa

React Native SMS User Consent

React Native wrapper for Android's SMS User Consent API, ready to use in React Native apps with minimum effort. The purpose of SMS User Consent API is to provide one-tap auto-filling of SMS verification codes.

iOS

SMS User Consent API exists only on Android, so this package is Android-only. Calling this package's APIs on iOS is no-op.

If you want auto-filling on iOS, textContentType="oneTimeCode" for TextInput is the way to go. Basically, this is the only way for iOS.

Getting started

Install the package:

yarn add @eabdullazyanov/react-native-sms-user-consent

or

npm install @eabdullazyanov/react-native-sms-user-consent

Basic usage

import React, { useEffect, useState } from 'react';
import { TextInput } from 'react-native';

import { useSmsUserConsent } from '@eabdullazyanov/react-native-sms-user-consent';

const Example = () => {
  const [code, setCode] = useState();

  const retrievedCode = useSmsUserConsent();

  useEffect(() => {
    if (retrievedCode) setCode(retrievedCode);
  }, [retrievedCode]);

  return <TextInput value={code} onChangeText={setCode} />;
};

In the example we use a controlled TextInput for the code entry. retrievedCode equals to the empty string initially, and whenever an SMS is handled retrievedCode receives the code from it. We use the useEffect to update the input value when an SMS is handled.

API

useSmsUserConsent()

useSmsUserConsent(codeLength = 6): string

React hook that starts SMS handling and provides the received code as its return value, which is the empty string initially. Stops handling SMS messages on unmount. Uses startSmsHandling and retrieveVerificationCode internally.

This hook is the way to go in most cases. Alternatively, you can use startSmsHandling and retrieveVerificationCode directly if dealing with something that is not a functional component or you need some more flexibility.

On iOS it just returns the empty string, so no additional code to handle iOS is needed.

startSmsHandling()

startSmsHandling(onSmsReceived: (event: {sms?: string}) => void): (
  stopSmsHandling(): void
)

Starts the native SMS listener that will show the SMS User Consent system prompt. If the user allowed reading the SMS, then the onSmsReceived callback is called. onSmsReceived receives the event object containing the SMS.

Returns stopSmsHandling function that stops showing the system prompt and stops SMS handling.

retrieveVerificationCode()

retrieveVerificationCode(sms: string, codeLength: number = 6): string | null

Retrieves the verification code from an SMS if there is any.


You can import the whole API as one object if you prefer

import SmsUserConsent from 'react-native-sms-user-consent';

// ...
SmsUserConsent.useSmsUserConsent();
// ...

Help

If you have any ideas about the project or found a bug or have a question, feel free to create an issue with all the relevant information. We are engaged to response ASAP. The following info will make it faster to resolve issues:

  1. Device or emulator model
  2. Android version
  3. Your environment info - output of the npx react-native info command

Contribution

PRs are always welcome. If you're feeling like contributing to the project, please do. It would be great to have all the relevant information with the PR.

To make changes, you'll need to follow these steps:

  1. clone the repo
  2. go to /example folder
  3. run yarn and npx react-native run-android to build and view the example project
  4. make changes
  5. repeat steps 3 and 4 until the desired result is achieved
  6. create a PR
  7. 🥳
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].