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

autharmor-jsclient-sdk

v1.4.1

Published

## 🏁 Installation

Downloads

15

Readme

AuthArmor Javascript Client-side SDK

🏁 Installation

You can integrate the AuthArmor SDK into your website by installing and importing our NPM package:

# Via NPM
npm i -s autharmor-jsclient-sdk

# Via Yarn
yarn add autharmor-jsclient-sdk

You can also load the SDK via our CDN by placing this script tag in your app's <head>

<script src="https://cdn.autharmor.com/scripts/autharmor-sdk.js"></script>

🧭 Usage

πŸš€ Initializing the SDK

In order to initialize the SDK, you'll have to create a new instance of the AuthArmor SDK with the url of your backend API specified in it.

const SDK = new AuthArmorSDK("https://api.example.com/"); // specify your backend's url

🧲 Invites

Generating a new invite

You can easily generate invites to your app by doing the following:

// Initialize the SDK
const SDK = new AuthArmorSDK("https://api.example.com/");

// Generate a new invite
const invite = await SDK.invite.generateInviteCode({
  nickname: "", // Specify the invite's nickname
  referenceId: "" // Specify a reference ID for the invite
});

console.log(invite);
/**
 * Returns:
 * {
 *   "nickname": "string",
 *   "invite_code": "string",
 *   "date_expires": "ISODate string",
 *   "invite_type": "string",
 *   "aa_sig": "string"
 * }
 */

Using an invite

Once an invite is generated, there are two methods for having the user consume the invite. You can either have your app show a QR Code which is then scannable using the AuthArmor app, or you can show a browser popup which prompts the user to accept the invite directly through the AuthArmor site:

// Display QR Code for user to scan using the AuthArmor app
invite.getQRCode(); // Returns a base64 representation of the QR Code image which can be used by supplying it to an <img> tag

// Or open the invite link in a popup window
invite.useInviteLink();

Confirming an invite

After generating an invite and having the user scan it, you'll need to confirm that the profile is fully setup in the user's device before sending authentication requests to his/her device.

console.log("Confirming invite ID:", invite.nickname);
await SDK.invite.confirmInvite(invite.nickname);
console.log("Invite has been confirmed successfully!");

What happens when confirming an invite?

The SDK sends a request to your backend containing an ID of the profile (nickname) the user just imported to his/her phone. The backend then sends a test authentication message to the user's phone, if the user approved it, this means the profile was setup successfully. Otherwise, the user must have incorrectly setup the profile

πŸ” Authentication

Initializing an authentication request

In order to initialize a login request for authenticating users to your site, you can simply call the authenticate() function with the nickname you wish to request an authentication request for. Once you call the authenticate() function, an AuthArmor overlay will appear on top of your app which reacts accordingly to the authentication request's status.

try {
  console.log("Authenticating user...");
  await SDK.auth.authenticate("nickname");
  console.log("User authenticated!");
} catch (err) {
  console.error("The request was declined or has timed out!", err);
}

πŸ’₯ Events

There are several events emitted by the SDK which you can attach to and have your app react accordingly.

Available Events

| Event Name | Description | | ------------------ | -------------------------------------------------------------------------- | | inviteWindowOpened | Triggered as soon as the invite popup window is open | | popupOverlayOpened | Triggered once the AuthArmor overlay for invite/auth shows | | popupOverlayClosed | Triggered once the AuthArmor overlay for invite/auth is removed | | inviteWindowClosed | Triggered as soon as the invite popup window is closed | | inviteAccepted | Triggered once a user opens the invite popup and accepts it | | inviteCancelled | Triggered once a user opens the invite popup and presses the cancel button | | error | Triggered once an error occurs while accepting/declining an invite |

Attaching an event listener

Attaching an event listener is pretty simple, all you'll have to do is call the on function with the event you wish to attach a function to followed by a callback function:

SDK.on("<event_name>", () => {
  // Do something...
});