4.1.0 • Published 2 years ago

nativescript-auth0 v4.1.0

Weekly downloads
25
License
MIT
Repository
-
Last release
2 years ago

NativeScript Auth0

Auth0 is a social login provider for NativeScript allowing you to choose between 50 different providers. Use the Auth0 portal to select and configure the providers you would like to make available in your NativeScript application. The Auth0 NativeScript plugin will dynamically load your chosen providers into your application.

The dynamically loading feature reduces the amount of dependencies you’ll have in your application. You also don’t have to worry about loading and managing Cocoapods or Android Jars specific to each implementation.

Auth0 is a freemium service. The free tier supports up to 7,000 active users. Auth0 paid service levels are very reasonable.

In addition to managing many login providers, Auth0 also has solutions for application analytics, logging, web tasks and more. Take a look at all of the Auth0 features and services.

Requires NativeScript version >=6.0.0.

Installation

tns plugin add nativescript-auth0

Go to your Auth0.com backend and configure your CallbackUrls, DO NOT USE THE KEYS IN THE DEMO Configure Callback URLs

Syntax should be:

<!-- iOS -->
{YOUR_BUNDLE_IDENTIFIER}://${YOUR_AUTH0_DOMAIN}/ios/{YOUR_BUNDLE_IDENTIFIER}/callback

<!-- Android -->
https://{YOUR_AUTH0_DOMAIN}/android/{YOUR_APP_PACKAGE_NAME}/callback

iOS

Add this to your Info.plist

Info.plist

<!-- Info.plist -->

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>None</string>
        <key>CFBundleURLName</key>
        <string>auth0</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>YOUR_APP_BUNDLE_IDENTIFIER</string>
        </array>
    </dict>
</array>

Implement Delegate

Sample Delegate

How to initalize it in app.ts

Android

Add this to your AndroidManifest.xml

        <activity
            android:name="org.nativescript.auth0.RedirectActivity"
            tools:node="replace">
            <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:host="YOUR_AUTH0_DOMAIN"
                    android:pathPrefix="/android/${applicationId}/callback"
                    android:scheme="https" />
            </intent-filter>
        </activity>

Sample from demo

You must also update webpack.config.js to include the redirect activity

    // Add your custom Activities, Services and other android app components here.
    const appComponents = [
        "tns-core-modules/ui/frame",
        "tns-core-modules/ui/frame/activity",
        "nativescript-auth0/android/provider/redirectActivity" // <-- add this line
    ];

Sample from demo

Usage

Import Auth0 in a shared helper or something

import { Auth0 } from 'nativescript-auth0';

Create your Auth0 object

    this.auth0 = new Auth0('<your clientid>', '<your domain>');

Start the web authentication flow, returns a promise

    /// Promise returns credentials object
    this.auth0.webAuthentication({
        scope: 'openid offline_access'
    }).then((res) => {
        // goToHomeOrWhatevs(); 
    }, (error) => {
        // console.log(error);
    });

Methods

NameDescriptionDocsReturns
webAuthentication(options)Starts the web authentication flow to login a userLinkPromise\
renewCredentials(refreshToken)Renews credentials using refresh tokenLinkPromise\
revokeRefreshToken(refreshToken)Revokes refresh tokenLinkPromise\
getUserInfo(accessToken)Returns the current user details, might want to cache the resultsLinkPromise\

ISSUES

  • No known issues.
4.1.0

2 years ago

4.1.0-alpha.1

2 years ago

4.1.0-alpha.0

2 years ago

4.0.0

4 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.2.7

6 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.1.10

8 years ago

0.1.9

8 years ago

0.1.8

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.0

8 years ago