• This repository has been archived on 18/Jul/2020
  • Stars
    star
    277
  • Rank 148,875 (Top 3 %)
  • Language
    Java
  • License
    MIT License
  • Created about 9 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[DEPRECATED] A wrapper of Lock to use with React Native (iOS & Android)

This library is DEPRECATED

We recommend following our react-native quickstart and using https://github.com/auth0/react-native-auth0.

react-native-lock

NPM version CI Status

Auth0 is an authentication broker that supports social identity providers as well as enterprise identity providers such as Active Directory, LDAP, Google Apps and Salesforce.

react-native-lock is a wrapper around Lock's implementations for iOS and Android ready to use for React Native

Before you start

Starting 8th June 2017 Auth0 restricted some Auth flows for new Auth0 clients (Grant types), even if your account was created before that date, so this library won't work out of the box since it relies on legacy grants. If you were already using this libary before 8th June, you can go to your client's settings and enable the grants you neeed.

  • Legacy: RO (http://auth0.com/oauth/legacy/grant-type/ro): for database connections
  • Legacy: RO jwt bearer (http://auth0.com/oauth/legacy/grant-type/ro/jwt-bearer): for TouchID
  • Legcy: Access Token (http://auth0.com/oauth/legacy/grant-type/access_token): for native social integrations

In our documentation you will find more information about Grant types.

We will continue fixing bugs for react-native-lock for the time being.

Requirements

iOS

Android

  • Minimum SDK 16

Installation

Run npm install --save react-native-lock to add the package to your app's dependencies.

iOS

react-native cli

Run react-native link react-native-lock so your project is linked against your Xcode project & install Lock for iOS using CocoaPods and run react-native run-ios

Manually

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-lock and add A0RNLock.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libA0RNLock.a to your project's Build PhasesLink Binary With Libraries
  4. Click A0RNLock.xcodeproj in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for Header Search Paths and make sure it contains $(SRCROOT)/../react-native/React, $(SRCROOT)/../../React, ${SRCROOT}/../../ios/Pods/Headers/Public and ${SRCROOT}/../../ios/Pods/Headers/Public/Lock - all marked as recursive.
  5. Inside your ios directory add a file named Podfile with the following content
  6. Run pod install --project-directory=ios
  7. Run react-native run-ios

CocoaPods Warning

If you get the following warning.

[!] The `<YourAppName> [Debug]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

[!] The `<YourAppName> [Release]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.release.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

Click <YourAppName>.xcodeproj in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for Other Linker Flags and replace the value -ObjC with the value $(inherited) for your Application's Target.

Compile error react-native >=0.26.0

If you are using a react-native version >=0.26.0, you might encounter the following error while trying to run the project

"std::terminate()", referenced from:
        ___clang_call_terminate in libReact.a(RCTJSCExecutor.o)

React Native introduced some C++ code so we need to tell Xcode to include use those symbols for compile. First click <YourAppName>.xcodeproj in the Project Navigator to show your project's target (at least one for your app). Then for each of the targets do the following:

  • Go the Build Settings tab, and make sure All is toggled on (instead of Basic)
  • Look for Other Linker Flags and add the flag -lc++ for all configurations

If your project was created using react-native init command, you will have two targets (app & tests) so make sure BOTH of them has the correct flags

CocoaPods with uses_framework! flag

This more of a hack than an actual solution. We recommend to avoid including Lock as a dynamic framework unless you have a very good reason to do that.

After setting up react-native-lock either Manually or using react-native cli you need to open your iOS project with Xcode and follow these steps:

  1. Click A0RNLock.xcodeproj in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for Framework Search Paths and make sure it contains $BUILD_DIR/$CONFIGURATION$EFFECTIVE_PLATFORM_NAME/Lock
  2. Change to the A0RNLock.xcodeproj target tab Build Phases, and in the section Link Binary with Libraries click the + and add Lock.framework and make sure it's Status is set to optional
  3. In the project navigator, select your project (should be the top one) and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic') and look for Other Linker Flags and make sure the value -ObjC is listed there

Android

react-native cli

Run react-native link react-native-lock so your project is linked against your Android project

In your file android/app/build.gradle, inside the android section add the following

packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE'
}

Then in your android/app/src/main/AndroidManifest.xml add the following inside <application> tag

<!--Auth0 Lock-->
<activity
  android:name="com.auth0.lock.LockActivity"
  android:theme="@style/Lock.Theme"
  android:screenOrientation="portrait"
  android:launchMode="singleTask">
</activity>
<!--Auth0 Lock End-->
<!--Auth0 Lock Embedded WebView-->
<activity
    android:name="com.auth0.identity.web.WebViewActivity"
    android:theme="@style/Lock.Theme">
</activity>
<!--Auth0 Lock Embedded WebView End-->
<!--Auth0 Lock Passwordless-->
<activity
    android:name="com.auth0.lock.passwordless.LockPasswordlessActivity"
    android:theme="@style/Lock.Theme"
    android:screenOrientation="portrait"
    android:launchMode="singleTask">
</activity>
<activity
    android:name="com.auth0.lock.passwordless.CountryCodeActivity"
    android:theme="@style/Lock.Theme">
</activity>
<!--Auth0 Lock Passwordless End-->

And finally run react-native run-android

Manually

In your file android/settings.gradle add the following

include ':react-native-lock'
project(':react-native-lock').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-lock/android')

In the file android/app/build.gradle add a new dependency

dependencies {
  //Other gradle dependencies...
  compile project(':react-native-lock')
}

And in the same file inside the android section

packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE'
}

This fixes the error `Error: duplicate files during packaging of APK

Then in the file MainApplication.java add the following Java import

import com.auth0.lock.react.LockReactPackage;

In react-native versions older than 0.29 you should add do this in MainActivity.java instead

and add Lock's React Native module

    /**
     * A list of packages used by the app. If the app uses additional views
     * or modules besides the default ones, add more packages here.
     */
    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            //Other RN modules
            new LockReactPackage()
        );
    }

Then in your android/app/src/main/AndroidManifest.xml add the following inside <application> tag

<!--Auth0 Lock-->
<activity
  android:name="com.auth0.lock.LockActivity"
  android:theme="@style/Lock.Theme"
  android:screenOrientation="portrait"
  android:launchMode="singleTask">
</activity>
<!--Auth0 Lock End-->
<!--Auth0 Lock Embedded WebView-->
<activity
    android:name="com.auth0.identity.web.WebViewActivity"
    android:theme="@style/Lock.Theme">
</activity>
<!--Auth0 Lock Embedded WebView End-->
<!--Auth0 Lock Passwordless-->
<activity
    android:name="com.auth0.lock.passwordless.LockPasswordlessActivity"
    android:theme="@style/Lock.Theme"
    android:screenOrientation="portrait"
    android:launchMode="singleTask">
</activity>
<activity
    android:name="com.auth0.lock.passwordless.CountryCodeActivity"
    android:theme="@style/Lock.Theme">
</activity>
<!--Auth0 Lock Passwordless End-->

For more information and configuration options you should see the Lock.Android docs

And finally run react-native run-android

Usage

Let's require react-native-lock module:

var Auth0Lock = require('react-native-lock');

And initialize it with your Auth0 credentials that you can get from our dashboard

var lock = new Auth0Lock({clientId: "YOUR_CLIENT_ID", domain: "YOUR_DOMAIN"});

Email/Password, Enterprise & Social authentication

lock.show({}, (err, profile, token) => {
  console.log('Logged in!');
});

And you'll see our native login screen

Lock.png

Avoid WebView for Social Auth

In order to make Lock use the OS browser to perform Web Auth you will need to pass the attribute useBrowser when you build Lock like

var lock = new Auth0Lock({clientId: "YOUR_CLIENT_ID", domain: "YOUR_DOMAIN", useBrowser: true});

Then you need to configure both your iOS and Android project following the instructions detailed below.

IMPORTANT: This feature only works with iOS 9 or later.

iOS

In the file AppDelegate.m add the following import on the top (next to the other imports of the file)

#import "A0LockReact.h"

and then inside the AppDelegate implementation add the following method

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  return [[A0LockReact sharedInstance] handleURL:url sourceApplication:nil];
}

And finally in the file Info.plist add the following entry

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLName</key>
    <string>auth0</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>{Bundle Identifier}</string>
    </array>
  </dict>
</array>

Where the Bundle identifier can be found in the same file under the key CFBundleIdentifier like

<key>CFBundleIdentifier</key>
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>

Android

In the file AndroidManifest find where the LockActivity is declared and insde the activity tags add the following

<intent-filter>
  <action android:name="android.intent.action.VIEW"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <category android:name="android.intent.category.BROWSABLE"/>
  <data android:scheme="a0{your lowercase auth0 client id}" android:host="{your auth0 domain}"/>
</intent-filter>

And make sure Lock's activity launch mode is singleTask

TouchID (iOS Only)

lock.show({
  connections: ["touchid"]
}, (err, profile, token) => {
  console.log('Logged in!');
});

And you'll see TouchID login screen

Lock.png

Because it uses a Database connection, the user can change it's password and authenticate using email/password whenever needed. For example when you change your device.

SMS Passwordless

lock.show({
  connections: ["sms"]
}, (err, profile, token) => {
  console.log('Logged in!');
});

And you'll see SMS Passwordless login screen

Lock.png

Email Passwordless

lock.show({
  connections: ["email"]
}, (err, profile, token) => {
  console.log('Logged in!');
});

And you'll see Email Passwordless login screen

Lock.png

Upgrading

If you are upgrading your react-native version just run react-native upgrade and overwrite all conflicts (option a or overwrite this and all others).

If you have custom code in any of the conflict files, like AppDelegate.m, it's probably best to backup a copy to apply those changes later.

Then run react-native link react-native-lock and follow the same steps like you did the first time you installed the library.

API

Lock

####.show(options, callback) Show Lock's authentication screen as a modal screen using the connections configured for your applications or the ones specified in the options parameter. This is the list of valid options:

  • closable (boolean): If Lock screen can be dismissed
  • disableSignUp (boolean): default to false, if true will hide the signup button
  • disableResetPassword (boolean): default to false, if true will hide the reset password button
  • connections ([string]): List of enabled connections to use for authentication. Must be enabled in your app's dashboard first.
  • authParams (object): Object with the parameters to be sent to the Authentication API, e.g. scope.

The callback will have the error if anything went wrong or after a successful authentication, it will yield the user's profile info and tokens.

####.authenticationAPI() Returns Auth0 Authentication API client that can be used to refresh user's token, obtain user information or call Auth0 delegation.

For more info check react-native-auth0

####.usersAPI(token) Returns Auth0 Users API client using a valid user's token for Management API. With this client you can update user's metadata or link two user accounts.

For more info check react-native-auth0

Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

What is Auth0?

Auth0 helps you to:

  • Add authentication with multiple authentication sources, either social like Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, among others, or enterprise identity systems like Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider.
  • Add authentication through more traditional username/password databases.
  • Add support for linking different user accounts with the same user.
  • Support for generating signed Json Web Tokens to call your APIs and flow the user identity securely.
  • Analytics of how, when and where users are logging in.
  • Pull data from other sources and add it to the user profile, through JavaScript rules.

Create a free account in Auth0

  1. Go to Auth0 and click Sign Up.
  2. Use Google, GitHub or Microsoft Account to login.

Author

Auth0

License

react-native-lock-ios is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

node-jsonwebtoken

JsonWebToken implementation for node.js http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html
JavaScript
17,054
star
2

java-jwt

Java implementation of JSON Web Token (JWT)
Java
5,403
star
3

express-jwt

connect/express middleware that validates a JsonWebToken (JWT) and set the req.user with the attributes
TypeScript
4,396
star
4

jwt-decode

Decode JWT tokens; useful for browser applications.
JavaScript
2,913
star
5

angular2-jwt

Helper library for handling JWTs in Angular apps
TypeScript
2,606
star
6

nextjs-auth0

Next.js SDK for signing in with Auth0
TypeScript
2,009
star
7

angular-jwt

Library to help you work with JWTs on AngularJS
JavaScript
1,259
star
8

lock

Auth0's signin solution
JavaScript
1,121
star
9

go-jwt-middleware

A Middleware for Go Programming Language to check for JWTs on HTTP requests
Go
978
star
10

auth0.js

Auth0 headless browser sdk
JavaScript
949
star
11

auth0-spa-js

Auth0 authentication for Single Page Applications (SPA) with PKCE
TypeScript
900
star
12

auth0-react

Auth0 SDK for React Single Page Applications (SPA)
TypeScript
864
star
13

node-jwks-rsa

A library to retrieve RSA public keys from a JWKS (JSON Web Key Set) endpoint.
JavaScript
824
star
14

node-jws

JSON Web Signatures
JavaScript
698
star
15

angular-storage

A storage library for AngularJS done right
JavaScript
644
star
16

repo-supervisor

Scan your code for security misconfiguration, search for passwords and secrets. 🔍
JavaScript
634
star
17

node-auth0

Node.js client library for the Auth0 platform.
JavaScript
586
star
18

cosmos

🔭 Auth0 Design System
JavaScript
545
star
19

JWTDecode.swift

A JWT decoder for iOS, macOS, tvOS, and watchOS
Swift
545
star
20

nginx-jwt

Lua script for Nginx that performs reverse proxy auth using JWT's
JavaScript
534
star
21

SimpleKeychain

A simple Keychain wrapper for iOS, macOS, tvOS, and watchOS
Swift
488
star
22

react-native-auth0

React Native toolkit for Auth0 API
TypeScript
477
star
23

express-openid-connect

An Express.js middleware to protect OpenID Connect web applications.
JavaScript
464
star
24

auth0-python

Auth0 SDK for Python
Python
445
star
25

JWTDecode.Android

A library to help you decode JWTs for Android
Java
437
star
26

docs

Auth0 documentation
JavaScript
366
star
27

auth0-PHP

PHP SDK for Auth0 Authentication and Management APIs.
PHP
355
star
28

wt-cli

Webtask CLI - all you need is code
JavaScript
322
star
29

auth0.net

.NET client for the Auth0 Authentication & Management APIs.
C#
296
star
30

passport-auth0

Auth0 authentication strategy for Passport.js
JavaScript
283
star
31

rules

Rules are code snippets written in JavaScript that are executed as part of the authentication pipeline in Auth0
JavaScript
283
star
32

Auth0.swift

Auth0 SDK for Apple platforms
Swift
275
star
33

auth0-java

Java client library for the Auth0 platform
Java
265
star
34

Lock.swift

A Swift & iOS framework to authenticate using Auth0 and with a Native Look & Feel
Swift
251
star
35

auth0-cli

Build, manage and test your Auth0 integrations from the command line
Go
243
star
36

auth0-deploy-cli

The Auth0 Deploy CLI is a tool that helps you manage your Auth0 tenant configuration. It integrates into your development workflows as a standalone CLI or as a node module.
JavaScript
242
star
37

laravel-auth0

Laravel SDK for Auth0 Authentication and Management APIs.
PHP
224
star
38

Auth0.Android

Android toolkit for Auth0 API
Kotlin
213
star
39

jwks-rsa-java

Java
194
star
40

ruby-auth0

Ruby toolkit for Auth0 API
Ruby
189
star
41

cxn

cXn: extensible open-source CDN
Ruby
178
star
42

passport-windowsauth

Windows Authentication strategy for Passport.js
JavaScript
175
star
43

auth0-angular

Auth0 SDK for Angular Single Page Applications
TypeScript
175
star
44

terraform-provider-auth0

The Auth0 Terraform Provider is the official plugin for managing Auth0 tenant configuration through the Terraform tool.
Go
161
star
45

styleguide

🖌 Conjunction of design patterns, components and resources used across our products.
Stylus
160
star
46

jwt-handbook-samples

JWT Handbook code samples
JavaScript
143
star
47

Lock.Android

Android Library to authenticate using Auth0 and with a Native Look & Feel
Java
140
star
48

wordpress

WordPress Plugin for Auth0 Authentication
PHP
133
star
49

node-samlp

SAML Protocol support for node (only IdP for now)
JavaScript
129
star
50

go-auth0

Go SDK for the Auth0 Management API.
Go
122
star
51

passport-linkedin-oauth2

Passport Strategy for LinkedIn OAuth 2.0
JavaScript
115
star
52

omniauth-auth0

OmniAuth strategy to login with Auth0
Ruby
112
star
53

symfony

Symfony SDK for Auth0 Authentication and Management APIs.
PHP
110
star
54

node-odata-parser

OData query string parser for node.js.
JavaScript
106
star
55

node-jwa

JSON Web Algorithms
JavaScript
98
star
56

express-jwt-authz

Validate the JWT scope to authorize access to an endpoint
JavaScript
97
star
57

auth0-vue

Auth0 authentication SDK for Vue.js apps
TypeScript
95
star
58

lock-passwordless

Auth0 Lock Passwordless [DEPRECATED]
JavaScript
93
star
59

auth0-aspnetcore-authentication

SDK for integrating Auth0 in ASPNET Core
C#
93
star
60

node-oauth2-jwt-bearer

Monorepo for libraries that protect Node APIs with OAuth2 Bearer JWTs
TypeScript
88
star
61

open-source-template

A template for open source projects at Auth0
85
star
62

auth0-angular2

84
star
63

auth0-oidc-client-net

OIDC Client for .NET Desktop and Mobile applications
C#
84
star
64

auth0-authorization-extension

Auth0 Extension that adds authorization features to your account
JavaScript
82
star
65

react-browserify-spa-seed

Seed / Boilerplate project to create your own SPA using React, Browserify and ReworkCSS
JavaScript
80
star
66

node-baas

Node.js implementation of Bcrypt as a micro service.
JavaScript
79
star
67

password-sheriff

Password policies made easy.
JavaScript
77
star
68

idtoken-verifier

Lightweight RSA JWT verification
JavaScript
76
star
69

sharelock-android

Sharelock Android app
Java
76
star
70

auth0-spring-security-api

Spring Security integration with Auth0 to secure your API with JWTs
Java
76
star
71

ad-ldap-connector

Auth0 AD and LDAP connector
JavaScript
70
star
72

nodejs-msi

Build an MSI Windows Installer for a node.js application using WIX Toolset.
PowerShell
70
star
73

id-generator

Generates random ids with a prefix (a la Stripe)
JavaScript
66
star
74

node-saml

SAML assertion creation for node
JavaScript
65
star
75

webtask-scripts

JavaScript
61
star
76

TouchIDAuth

A library for passwordless authentication using TouchID & JWT
Objective-C
60
star
77

passport-azure-ad-oauth2

OAuth 2.0 authentication Passport strategies for Windows Azure Active Directory
JavaScript
59
star
78

spa-pkce

JavaScript
58
star
79

discourse-plugin

Discourse plugin to authenticate with auth0.
Ruby
58
star
80

auth0-flutter

Auth0 SDK for Flutter
Dart
58
star
81

auth0-multitenant-spa-api-sample

JQuery SPA + Node.js API with multi-tenant support
JavaScript
58
star
82

sandboxjs

Sandbox node.js code like a boss
JavaScript
58
star
83

multitenant-jwt-auth

This sample shows how to implement an API that authenticates using JWTs. It supports mutiple tenants and JWT blacklisting.
JavaScript
54
star
84

coreos-mongodb

CoreOS MongoDB units
52
star
85

shiny-auth0

Auth0 shiny proxy
JavaScript
51
star
86

auth0-cordova

Auth0 integration for Cordova apps
JavaScript
49
star
87

disyuntor

A circuit-breaker implementation for node.js
TypeScript
48
star
88

sharelock-osx

Swift
47
star
89

passport-wsfed-saml2

passport strategy for both WS-fed and SAML2 protocol
JavaScript
47
star
90

php-jwt-example

Php JWT example.
PHP
46
star
91

auth0-aspnet-owin

Auth0 ASP.NET 4.5 Owin/Katana Authentication Handler
JavaScript
46
star
92

webauthn.me

webauthn.me, learn more about the Web Authentication API or try the debugger.
JavaScript
46
star
93

auth0-dotnet-templates

Auth0 Templates for .NET
C#
44
star
94

auth0-java-mvc-common

Contains common helper classes and api client logic that are used across our Java MVC libraries
Java
43
star
95

auth0-custom-password-reset-hosted-page

An example on how to do a custom reset password hosted page.
HTML
41
star
96

express-oauth2-bearer

Experimental Middleware for express.js to validate access tokens.
JavaScript
40
star
97

magic

Auth0 Cryptography Toolkit
JavaScript
40
star
98

single-page-app-seed

A very opinionated seed for creating Single Page Apps that uses NO framework at all. Just a bunch of component libs
JavaScript
39
star
99

kbd

Styles for <kbd> tags.
HTML
37
star
100

webtask-workshop

36
star