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

webmaker-auth-client

v0.2.8

Published

This is the client-side library that adds support for Webmaker Login to your app. In order for it to work, you will need the following on your app's server:

Downloads

7

Readme

Webmaker auth client

This is the client-side library that adds support for Webmaker Login to your app. In order for it to work, you will need the following on your app's server:

If you choose to use the create user form assets included in this package, you will also need node-webmaker-l18n for localization and nunjucks for server-side rendering.

Install

bower install webmaker-auth-client --save

What's included?


# Main js file
webmaker-auth-client.js

# Create new user form assets
create-user/
    create-user-form.css
    create-user-form.html

# Localized strings for create new user form
locale/
    en_US/
        create-user-form.json

# Minified file (~11kb) packaged with dependencies.
dist/
    webmaker-auth-client.min.js

Example

There is a fully-featured example in the examples directory that you can run locally. It uses server-side rendering with nunjucks and webmaker-i18n, so you may need to modify the example to get it to work in your environment.

<html>
  <head></head>
  <body>

    <button id="login"></button>
    <button id="logout"></button>

    <script src="https://login.persona.org/include.js"></script>
    <script src="bower_components/webmaker-auth-client/dist/webmaker-auth-client.min.js"></script>
    <script>
      var loginEl = document.querySelector('#login');
      var logoutEl = document.querySelector('#logout');

      var auth = new WebmakerAuthClient();

      // Attach event listeners!
      auth.on('login', function(user, debuggingInfo) {
        console.log('login', user, debuggingInfo);
      });
      auth.on('logout', function() {
        console.log('logout');
      });

      // Run this function to automatically log-in users with a session set.
      auth.verify();

      // Use auth.login and auth.logout to login and out!
      loginEl.addEventListener('click', auth.login, false);
      logoutEl.addEventListener('click', auth.logout, false);

    </script>
  </body>
</html>

Require-js

requirejs.config({
  paths: {
    'analytics': '/bower/webmaker-analytics',
    'eventEmitter': '/bower/eventEmitter',
    'webmaker-auth-client': '/bower/webmaker-auth-client'
  }
});

define(['webmaker-auth-client/webmaker-auth-client'],
  function(WebmakerAuthClient) {
    var auth = new WebmakerAuthClient();
    ...
  });

Configure

var auth = new WebmakerAuthClient({
  host: '',
  paths: {
    authenticate: '/authenticate',
    create: '/create',
    verify: '/verify',
    logout: '/logout'
  },
  csrfToken: 'YOURCSRFTOKEN',
  audience: window.location.origin,
  prefix: 'webmaker-', // for local storage
  timeout: 10,
  handleNewUserUI: true // Do you want to auto-open/close the new user UI?
});

Listen to events

auth.on('event', callback);
auth.off('event', callback);

login (userData, [message])

When a user logs in or a session is automatically restored.

The message parameter is one of:

  • null: on a successful check from the server
  • restored: if the data was restored from local storage
  • email mismatch: if the email was different in local storage v.s. on the server
  • user created: if a new user was created an logged in

###error (errorMessage)

When an error happens. Check the error message for more information.

logout (no parameters)

When user logs out or is logged out due to an error, or when no user session exists.

Session restore and SSO

To automatically login users and set up SSO, you must call

auth.verify();

Login/Logout

auth.login();
auth.logout();