npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aurelia-simple-auth0

v1.0.22

Published

A simple aurelia plugin to implement auth0's hosted login page.

Downloads

9

Readme

aurelia-simple-auth0

A simple aurelia plugin to implement auth0's hosted login page.

Installation

npm install aurelia-simple-auth0 --save

aurelia.json

Add the following to bundles.dependencies:

{
    "name": "auth0",
    "path": "../node_modules/auth0-js/build",
    "main": "auth0"
}, {
    "name": "aurelia-simple-auth0",
    "path": "../node_modules/aurelia-simple-auth0/dist/amd",
    "main": "index"
}

main.js

aurelia.use
    .plugin('aurelia-simple-auth0', {
			domain: 'YOUR-DOMAIN.auth0.com',
			clientID: 'YOUR-AUTH0-CLIENT-ID',
			redirectUri: 'CALLBACK-URL',
			audience: 'THE-AUDIENCE',
			responseType: 'token id_token', // OPTIONAL: If not specified, this value is used.
			scope: 'openid', // OPTIONAL: If not specified, this value is used.
			storageLocation: localStorage // OPTIONAL: This is the default. Can also be set to sessionStorage.
		});
  • The required values supplied to the plugin are found in your auth0 dashboard.

  • The redirectUri specifies a callback to route to after successful or unsuccessful login. This is usually an aurelia custom element set up to handle the return values. See Standard Callback Custom Element.

  • storageLocation is either localStorage or sessionStorage. The auth0 returned values are written here after successful login.

Accessing Auth0Service

Auth0Service contains the plugin's high-level interface to auth0.

import {inject} from 'aurelia-framework';
import {Auth0Service} from 'aurelia-simple-auth0';

@inject(Auth0Service)
export class MyClass {
	constructor(auth0Service) {
		this.auth0Service = auth0Service;
	}
}

Standard Callback Custom Element

You must create a callback custom element and add it to your main router configuration for the route given in the redirectUri plugin configuration option. That way, this element will be routed to after the user is done with auth0's hosted login page so it can retrieve returned auth0 values using the authenticate() method and perform the appropriate tasks after the login is successful or not.

This custom element's view can be anything you like. Typically you would display a progress indicator.

The following shows a standard template for the callback element's view-model:

import {inject} from 'aurelia-framework';
import {Auth0Service} from 'aurelia-simple-auth0';

@inject(Auth0Service)
export class Callback {
    constructor(auth0Service) {
        auth0Service.authenticate().then(() => {
            //Handle a successful login, usually by going to a new route.
        }).catch(e => {
            //Handle an unsuccessful login, usually by displaying an error, and then going to a new route.
        });
    }
}

Auth0Service Methods

authenticate()

Call this method in your callback's constructor. It returns a promise to parse the response from auth0 and, if the user successfully logged in, write the returned values into the storageLocation. When the promise resolves, the user has successfully logged in. If the promise rejects, the user has not successfully logged in.

login()

Call this method to display the auth0 hosted login page. Upon success or failure, auth0 will redirect to your designated callback custom element.

Example:

import {inject} from 'aurelia-framework';
import {Auth0Service} from 'aurelia-simple-auth0';

@inject(Auth0Service)
export class MyClass {
	constructor(auth0Service) {
		this.auth0Service = auth0Service;
	}
	
	loginButtonClicked() {
		this.auth0Service.login();	
	}
}

logout()

Call this method to logout the user. Doing so will erase all auth0 information added to your designated storageLocation.

Example:

import {inject} from 'aurelia-framework';
import {Auth0Service} from 'aurelia-simple-auth0';

@inject(Auth0Service)
export class MyClass {
	constructor(auth0Service) {
		this.auth0Service = auth0Service;
	}
	
	logoutButtonClicked() {
		this.auth0Service.logout();	
	}
}

Auth0Service Properties

accessToken

The last access token passed back by auth0 after a successful user login.

expiresAt

The expiration date/time in milliseconds of the current user session.

idToken

The last id token passed back by auth0 after a successful user login.

isAuthenticated

This value is true if the user successfully logged in and their session has not expired. Otherwise it is false.