Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sitefinitysteve/nativescript-auth0

Nativescript Auth0 https://auth0.com/ social authentication plugin
https://github.com/sitefinitysteve/nativescript-auth0

auth0 nativescript social-login

Last synced: 17 days ago
JSON representation

Nativescript Auth0 https://auth0.com/ social authentication plugin

Awesome Lists containing this project

README

        

# NativeScript Auth0

[Auth0](https://auth0.com) is a social login provider for NativeScript allowing you to choose between [50 different providers](https://auth0.com/docs/identityproviders). 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](https://auth0.com/pricing) 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](https://auth0.com/why-auth0) and services.

Requires NativeScript version `>=7.0.0`.

## Installation

```terminal
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](https://auth0.com/docs/quickstart/native/ios-swift/00-getting-started#configure-callback-urls)

Syntax should be:

```

{YOUR_BUNDLE_IDENTIFIER}://${YOUR_AUTH0_DOMAIN}/ios/{YOUR_BUNDLE_IDENTIFIER}/callback

https://{YOUR_AUTH0_DOMAIN}/android/{YOUR_APP_PACKAGE_NAME}/callback
```

### iOS

Add this to your [Info.plist](./demo/app/App_Resources/iOS/Info.plist#L46-L58)

```xml
CFBundleURLTypes


CFBundleTypeRole
None
CFBundleURLName
auth0
CFBundleURLSchemes

{YOUR_APP_BUNDLE_IDENTIFIER}

```

#### Implement Delegate

[Sample Delegate](./demo/app/custom-app-delegate.ts)

[How to initalize it in app.ts](./demo/app/app.ts#L3-L13)

### Android

Add this to your [AndroidManifest.xml](./demo/app/App_Resources/Android/src/main/AndroidManifest.xml#L44-L60)

```xml




```

### Include RedirectActivity file

Create a [custom webpack configuration](https://docs.nativescript.org/tooling/custom-webpack-configuration) and add `'nativescript-auth0/android/provider/redirectActivity'` to `appComponents`.

See the demo's [nativescript.config.js#L11](./demo/webpack.config.js) and [webpack.custom.config.js](./demo/webpack.custom.config.js) for an example.

## Usage

Import Auth0 in a shared helper or something

```ts
import { Auth0, Credentials, WebAuthException } from 'nativescript-auth0';
```

Create your Auth0 object

```ts
this.auth0 = new Auth0('', '');
```

Start the web authentication flow, returns a promise

```ts
this.auth0.webAuthentication({
scope: 'openid offline_access'
}).then((result: Credentials) => {
console.log(result);
}).catch((error: Error | WebAuthException) => {
console.log(error);
});
```

## Methods

| Name | Description | Docs | Returns |
|----------------------------------|-----------------------------------------------------------------------------|-------------------------------------------------------------------------|---------------------:|
| webAuthentication(options) | Starts the web authentication flow to login a user | [Link](https://auth0.com/docs/api/authentication#login) | Promise\ |
| renewCredentials(refreshToken) | Renews credentials using refresh token | [Link](https://auth0.com/docs/api/authentication#refresh-token) | Promise\ |
| revokeRefreshToken(refreshToken) | Revokes refresh token | [Link](https://auth0.com/docs/api/authentication#revoke-refresh-token) | Promise\ |
| getUserInfo(accessToken) | Returns the current user details, might want to cache the results | [Link](https://auth0.com/docs/api/authentication#get-user-info) | Promise\ |