Code Monkey home page Code Monkey logo

auth0.js's Introduction

Client Side JavaScript toolkot for Auth0 API

Release Codecov Downloads License CircleCI

๐Ÿ“š Documentation - ๐Ÿš€ Getting Started - ๐Ÿ’ป API Reference - ๐Ÿ’ฌ Feedback

Documentation

  • Library docs - a complete reference and examples.
  • Sample App - a sample application integrated with Auth0.
  • Examples - code samples for common auth0-js authentication scenario's.
  • Docs site - explore our docs site and learn more about Auth0.

Getting started

Installation

From CDN:

<!-- Latest patch release -->
<script src="https://cdn.auth0.com/js/auth0/9.26.1/auth0.min.js"></script>

From npm:

npm install auth0-js

After installing the auth0-js module using npm, you'll need to bundle it up along with all of its dependencies, or import it using:

import auth0 from 'auth0-js';

Configure the SDK

auth0.WebAuth

Provides support for all the authentication flows.

var auth0 = new auth0.WebAuth({
  domain: '{YOUR_AUTH0_DOMAIN}',
  clientID: '{YOUR_AUTH0_CLIENT_ID}'
});

auth0.Authentication

Provides an API client for the Auth0 Authentication API.

var auth0 = new auth0.Authentication({
  domain: '{YOUR_AUTH0_DOMAIN}',
  clientID: '{YOUR_AUTH0_CLIENT_ID}'
});

auth0.Management

Provides an API Client for the Auth0 Management API (only methods meant to be used from the client with the user token). You should use an access_token with the https://YOUR_DOMAIN.auth0.com/api/v2/ audience to make this work. For more information, read the user management section of the Auth0.js documentation.

var auth0 = new auth0.Management({
  domain: '{YOUR_AUTH0_DOMAIN}',
  token: '{ACCESS_TOKEN_FROM_THE_USER}'
});

API reference

auth0.webAuth

auth0.Authentication

auth0.Management

Feedback

Contributing

We appreciate feedback and contribution to this repo! Before you get started, please see the following:

Raise an issue

To provide feedback or report a bug, please raise an issue on our issue tracker.

Vulnerability Reporting

Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.


Auth0 Logo

Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?

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

auth0.js's People

Contributors

aaguiarz avatar akmjenkins avatar alexkoumarianos-okta avatar anion155 avatar cocojoe avatar damien-gl avatar damieng avatar dependabot-preview[bot] avatar dependabot[bot] avatar dominickbattistini avatar evansims avatar frederikprijck avatar glena avatar hzalaz avatar jfromaniello avatar joshcanhelp avatar lbalmaceda avatar luisrudge avatar nyholm avatar peterblazejewicz avatar pmalouin avatar poovamraj avatar radekk avatar ramasilveyra avatar robinbijlani avatar scottrudiger avatar srijonsaha avatar stevehobbsdev avatar widcket avatar xurei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

auth0.js's Issues

Add tests for IE11

There are some odd behaviors reported with IE11 not working as expected.

Seems to be some rare bug with uglify and ascii: true.

API v3.0

Redirect will be the default from now on. Popup is optional,

Usage will be:

var auth0 = new Auth0({
  clientID: 'xxx',
  clientSecret: 'yyy',
  callbackOnLocationHash: true,
  //etc
});

//handle login success
widget.on('success', function (profile, id_token, access_token) {
  alert('welcome ' + profile.name);
});

//handle errors
widget.on('error', function (err) {
  alert('error' + err.message);
});

document.getElementById('login-button').onclick = function () {
  //trigger login
  widget.signin({ conenction: 'google-oauth2' });
};

When logging in with Username and Password and not using `/ro` and there's an error, redirect should be used

When you send a callback to auth0.js with less or equal than 1 parameter (just the error), redirect mode is used to log the user in.

However, when there's an error logging the user in, instead of actually doing a redirect as well and returning the error there, it's returning the error after the requests finishes which is not consistent.

This brings some consistency errors like auth0/auth0-angular#118

Question: Trigger Forgot Password

Hi All,

I have had to build a custom logon form in my current app and signing in or changing password is no problem but I can't figure out how I would trigger a forgot password mail to be sent, is there a way to trigger this?

Thanks for the help and auth0 has been great so far, nice and easy to implement compared to some other implementations for auth I've tried.

Thanks

Don't expect `window` to exist

For those of us who like to build "universal" (a.k.a. isomorphic) apps, this causes issues when doing require('auth0-js') in node.

Not saying everything has to work, but it'd be cool if it didn't error, something like this:

if (typeof window !== 'undefined') {
  // here you can safely reference `window`
}

Also, would suggested testing in both browserify and webpack as they're slightly different and webpack keeps growing in popularity.

When offline and popup mode, it should not create the popup

Steps to reproduce:

  1. Setup auth0.js to use popup mode and a social provider.
  2. Disconnect
  3. Call the signin method with the social provider.

What should happen? It should detect that the browser is offline using navigator.onLine and don't launch the popup. Show an error message instead.

What happens instead? It launches a popup that displays a browser error page as its disconnected. After closing the popup, a message appears that the user closed it.

Support for IE9

We need to bring back support for CORS on IE9 (i.e. not using jsonp to send user/pass).

Bower component?

Can this be published as a Bower component?

Right now I'm grabbing it with bower using the repo address, but then I still have to cd into the local dir and do an npm install to get all dependencies so that browserify will work correctly on "standalone.js"

Need to be robust against corrupt cookies (idToken)

When upgrading from one version to another, it happened to me twice that I had to delete persistent cookies to make the auth0 libraries (angular and this one) not crash.

The libraries should be robust against corrupt cookies or changes in cookie format between versions. Website developers can't expect their end-users to clear cookies and neither should developers have knowledge about and need to write code to delete invalid cookie data.

In the last occurrence, the cookie idToken contained the value "undefined" (string) which causes auth0.js to crash here: https://github.com/auth0/auth0.js/blob/master/build/auth0.js#L53

The cookies seem to get set to "undefined" when _serialize in auth0-angular gets called with this._serialize(undefined, undefined, undefined); (https://github.com/auth0/auth0-angular/blob/master/build/auth0-angular.js#L172). That's probably a bug by itself, yet auth0 should not crash. (It might not even be related to auth0-angular, but to my version of angular, but again, auth0 should just disregard such cookies.)

Package naming causes common Grunt tasks to fail

When running "usemin" and "rev:dist" tasks with a common options (i.e. includes = */.js), Grunt builds fail due to this module being named "auth0.js" (it tries to open it as a JS file). Not strictly your fault, but the nonstandard naming convention makes it impossible for me to use bower to manage the auth0 dependency at this point since I need to rename it and rewire my local dependencies manually. I haven't run into any other packages that do this.

I would recommend publishing as "auth0-js" or just "auth0" and switching to that as the default package for your other dependencies (auth0-angular, etc).

Obtain an actual email_verified value without re-login?

After registration (and login after that) I have {email_verified: false}

After verification of email this method returns the same value (email_verified: false)

  • getProfile() or /tokeninfo

even after renewIdToken or refreshToken

only re-login helps to obtain actual value: (email_verified: true)

Is there any possibility to obtain it without re-login?

package.json postinstall: bower install with Heroku

having a few problems trying to complete a bower install on heroku with the "auth0.js": "latest" dependency getting the error...

package.json

"scripts": {
    "start": "node node_modules/grunt-cli/bin/grunt",
    "postinstall": "node node_modules/bower/bin/bower install"
  },

error

bower Base64#* ECMDERR Failed to execute "git checkout 277e9adeecce7c376692b772aec60baf63114592", exit code of #128
Additional error details: fatal: Not a git repository: '.'

bower.json

{
    "name": "myApp",
    "version": "0.1.0",
    "dependencies": {
        "angular": "latest",
        "angular-bootstrap": "0.10.0",
        "angular-cookies": "latest",
        "angular-ui-router": "#master",
        "auth0.js": "latest",
        "auth0-angular": "latest",
        "bootstrap": "3.0.3"
    }
}

Once i remove "auth0.js": "latest" from bower.json the heroku build completes successfully.

Redirect and Popup modes are inconsistent

There're inconsistencies when using redirect and popup mode after the login has succeeded or failed.

Let's see how they work now:

Popup mode

Code

auth0.login({}, function(err, token, profile) {
  // first check for errors when authenticating or when getting the profile
  if (err) {
     // do something
  } 

  // save profile and token
  window.token = token;
  window.profile = profile
})

Advantages

  • Error for both Authentication and getting a profile is in a single point
  • We don't have nested callbacks
  • We can save the token and profile together

Disadvantages

  • The profile is fetched for us and we don't know/understand how.

Redirect mode

// login.js
auth.signin({});

// boot.js
var authHash = auth.parseHash(window.location.hash);
if (authHash && authHash.id_token) {
  window.token = authHash.id_token;
  auth.getProfile(authHash.id_token, function(err, profile) {
    // Check profile fetch errors
    if (err) {
      // do sth
    } 
    window.profile = profile;
  });
}
if (authHash && authHash.error) {
  // Handle authentication errors here
}

Advantages

  • We know everything that's going on. We know how the profile is fetched and when.

Disadvantages

  • We have nested callbacks
  • We do error handling twice in 2 different places
  • It requires much more code which doesn't add value to us

Proposal

My proposal is to make popup and redirect mode consistent by making the redirect mode also return a callback with the profile and default to check window.location.hash.

Code for redirect

auth.processAuthenticationHash(function(err, token, profile) {
  // first check for errors when authenticating or when getting the profile
  if (err) {
     // do something
  } 

  // save profile and token
  window.token = token;
  window.profile = profile
});

Important parts

  • Internally the processAuthenticationHash function will check if there's a hash or search. If there's not, it just won't call the callback
  • It'll do error handling for both authentication part as well as profile fetching

Thoughts?

@woloski @jfromaniello @cristiandouce

Check for callback by counting args is wrong

Right now, Auth0.js code to check if I sent a callback to do /ro for Username & password does the following:

if (callback && callback.length > 1) {

This means my callback HAS to have 2 parameters to be considered a "callback".

Therefore, the following code we have on auth0-angular doesn't work:

var applied = function(fn) {
        return function () {
          var argsCall = arguments;
          safeApply(function() {
            fn.apply(null, argsCall);
          });

        };
      };

signIn(options, applied(onSignInCallback));

As you can see I always forward all arguemnts. To make this work, I had to add 2 arguments that I don't use.

I just wanted to know WHY it checks for the amount of args of the function and if it can be changed.

Thanks!

/cc @jfromaniello

Throw a specific error to the user if the Authentication mode asked is not available in the current platform/app

We have right now 3 Authentication modes:

  • Popup
  • Redirect
  • Post to /ro

Not all the calls can be made in all devices.

For example, redirect cannot be used in Cordova and Phonegap.

We should add a mechanism in auth0.js to detect in what platform / app we're currently and if we're asked to perform an Authentication mode that we cannot do, we should throw a specific error for that.

Firebase is doing something similar.

Not properly handeling "Connection Timeout" and "Connection Refused" exceptions

auth0.6.1.0.js is not handling "Connection Timeout" and "Connection Refused" exceptions.

There was a recent fix to handle "Internet Disconnected" [commit 68aea5d], but the fix does not cover the situation when the browser can't connect to Auth0 (for example: Auth0 service is down or some network issues). The error reported is "invalid_password" which may be confusing to users.

Create a flag to disable the JSONP fallback

Right now if CORS is not supported in the browser auth0.js fallbacks to JSONP.

This is not a good security practice since it sends passwords in urls.

We want to provide the ability to disable this fallback.

implement a getProfile(window.location.hash, callback)

Call the parseHash function, if the profile returned just have the user_id (it means that the scope was just openid) call GET /api/users/:id with the jwt in auth header or qs for jsonp.

Make sure it works with JSONP.

Distinguish no internet connection error

In our client application, we want to be able to set apart the case where the user does not have an internet connection and display a message accordingly on the login screen.

It seems to me though that the error status code for the "no connection" error is transformed into a 401 because of this line that fixes an IE 10 error, judging from the code comment.

Is there a way to distinguish the "no connection" error from other errors and have everything also work under IE10?

"wrong password" message stays on Signup screen

  1. Put wrong email/password and click SignIn
  2. Widget displays "Wrong email or password" error message.
  3. Click SignUp button. The message is still there but it does not make sense on that screen. It should be hidden on Signup page.

Show alert if no callbackURL is defined and a callback is set

Right now, we show the World Domination message when the callback is missing and the user is trying a Social IdP. However, if the user tries to do a regular Username/Password Auth, a CORS error is thrown.

We should parse the s3 information to see if theres a callbackURL. If there's not and no callback is set to handle the success of the login, then we should show a message sayingPlease add currentURL as a CallbackURL on your application settings`.

Thanks!

Extra fields on signup

Hi,
Found during working on auth0/lock#142
I was wondering why it's not possible to pass extra fields in the signUp method? I presume internally it's similar to /users/create api which allows to pass extra fields.

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.