Coder Social home page Coder Social logo

auth0-cordova's Introduction

Auth0 Cordova

Library to make it easy to integrate Auth0 login in your Cordova applications.

Requirements

The library requires these two cordova plugins to work:

  • cordova-plugin-safariviewcontroller: Shows Safari/Chrome browser ViewController/CustomTab
  • cordova-plugin-customurlscheme: Handles the custom scheme url intents for callback

you'll need to run

cordova plugin add cordova-plugin-safariviewcontroller
cordova plugin add cordova-plugin-customurlscheme --variable URL_SCHEME={application package name} --variable ANDROID_SCHEME={application package name} --variable ANDROID_HOST={auth0 domain} --variable ANDROID_PATHPREFIX=/cordova/{application package name}/callback

In cordova applications, the application package name is the widget's identifier in config.xml

So if you have the following values

  • application package name or widget identifier: com.auth0.cordova.example
  • auth0 domain: samples.auth0.com

in your config you should have some entries like

<preference name="AndroidLaunchMode" value="singleTask" />
<plugin name="cordova-plugin-customurlscheme" spec="~4.2.0">
    <variable name="URL_SCHEME" value="com.auth0.cordova.example" />
    <variable name="ANDROID_SCHEME" value="com.auth0.cordova.example" />
    <variable name="ANDROID_HOST" value="sample.auth0.com" />
    <variable name="ANDROID_PATHPREFIX" value="/cordova/com.auth0.cordova.example/callback" />
</plugin>
<plugin name="cordova-plugin-safariviewcontroller" spec="~1.4.6" />

Setup

From npm

npm install @auth0/cordova

then in your index.js you need to register the url handler ondeviceready

var Auth0Cordova = require('@auth0/cordova');

function main() {
    function handlerUrl(url) {
        Auth0Cordova.onRedirectUri(url);
    }
    window.handleOpenURL = handlerUrl;
    // init your application
}

document.addEventListener('deviceready', main);

Usage

const auth0 = new Auth0Cordova({
  domain: "{YOUR_AUTH0_DOMAIN}",
  clientId: "{YOUR_AUTH0_CLIENT_ID}",
  packageIdentifier: "{WIDGET_ID_IN_CONFIG_XML}"
});

const options = {
  scope: 'openid profile',
};

auth0.authorize(options, function (err, result) {
  if (err) {
    // failure
  }
  // success!
});

This will open your tenant's hosted login page in the OS browser and will use OAuth 2.0 code grant flow with Proof Key for Code Exchange.

API

For more information about our API please check our online documentation

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.

For auth0 related questions/support please use the Support Center.

Common Issues

  1. The plugin is not working in Ionic / Cordova dev app.

    The plugin needs to be deployed on a real device to function, this is so because the dev apps do not add the necessary plugins needed for this library to function correctly. You'll need to either create a clone / fork of the Dev App or need to deploy it to a real device to test.

  2. The app hangs after authentication

    If 1 does not solve your problem, please make sure you have cordova-plugin-customurlscheme installed or an appropirate plugin to handle the callback (like deeplinks / universal links) and you are handling the callback appropriately

Author

Auth0

License

This project is licensed under the MIT license. See the LICENSE file for more info.

auth0-cordova's People

Contributors

aaguiarz avatar annyv2 avatar chenkie avatar cocojoe avatar damieng avatar darkyen avatar decates avatar hzalaz avatar johnmclear avatar joshcanhelp avatar lbalmaceda avatar luisrudge avatar mehreencs87 avatar mgonto avatar mpaktiti avatar ntotten avatar siacomuzzi avatar snyk-bot avatar vmartynets avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.