npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-auth0-guardian

v1.0.4

Published

React native bridge for Auth0 Guardian

Downloads

75

Readme

React Native Auth0 Guardian (iOS & Android)

npm version contributions welcome

Installation

NPM

npm install --save react-native-auth0-guardian

Yarn

yarn add react-native-auth0-guardian

Linking the library

React Native 0.60+: CLI autolink feature links the module while building the app. No any extra steps needed.

React Native <= 0.59: You need to link manually
$ react-native link react-native-auth0-guardian

Use CocoaPods to add the native RNAuth0Guardian to your project:
$ npx pod-install

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-auth0-guardian and add RNAuth0Guardian.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNAuth0Guardian.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.reactlibrary.RNAuth0GuardianPackage; to the imports at the top of the file
  • Add new RNAuth0GuardianPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-auth0-guardian'
    project(':react-native-auth0-guardian').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-auth0-guardian/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      implementation project(':react-native-auth0-guardian')

Usage

Initialization

import Auth0Guardian from 'react-native-auth0-guardian';

// Before using `Auth0Guardian`, you should call `initialize` method 
// with `auth0Domain` as a parameter. Calling this in the root file is recommended Ex: root index.js or App.js

const auth0Domain = "yourtenant.guardian.auth0.com" // replace it with your own

Auth0Guardian.initialize(auth0Domain)
	.then(result => console.log('Auth0 Guardian initialized 😎'))
	.catch(err => console.log(err))

Enrolling the device

An enrollment is a link between the second factor and an Auth0 account. When an account is enrolled you'll need it to provide the second factor required to verify the identity.

For an enrollment you need the following things, besides your Guardian Domain:

enrollmentUri - this is the url parsed from qr code. You can use react-native-qrcode-scanner library to scan the qrcode and parse it.

deviceToken - unique device token (aka FCM token for android, APNS token for iOS). You can get it using react-native push notification libraries

try {
	const isEnrolled = await Auth0Guardian.enroll(enrollmentUri, deviceToken);
	console.log({ isEnrolled })
} catch (err)  {
	console.log(err)
}

Get TOTP code for current enrollment. (Returns only if the device is enrolled successfully)

You can also get TOTP code and show it inside your application if this use case is required. User will have 2 options: notification based authentication or totp based authentication (like Google Authenticator)

try {
	const totpCode = await Auth0Guardian.getTOTP();
	console.log({ totpCode })
} catch (err) {
	console.log(err)
}

Allow a login request.

Once you have the enrollment in place, you will receive a push notification every time the user has to validate his identity with MFA.

notificationData - body of notification received through push notification libraries (firebase, push-notification-ios or etc.)

try {
	const isAllowed = await Auth0Guardian.allow(notificationData);
	console.log({ isAllowed })
} catch (err) {
	console.log(err)
}

Reject a login request.

To deny an authentication request use the method below.

notificationData - body of notification received through push notification libraries (firebase, push-notification-ios or etc.)

try {
	const isRejected = await Auth0Guardian.reject(notificationData);
	console.log({ isRejected })
} catch (err) {
	console.log(err)
}

Removing device enrollment

If you want to delete an enrollment -for example if you want to disable MFA

try {
	const isUnenrolled = await Auth0Guardian.unenroll();
	console.log({ isUnenrolled })
} catch (err) {
	console.log(err)
}

Native libraries used:

Auth0 Guardian Java
Auth0 Guardian Swift