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/autharmor-js

v4.0.0-rc.4

Published

Auth Armor provides a SaaS solution to authenticate your users exclusively using passwordless authentication methods such as WebAuthn, magic links and the proprietary Auth Armor mobile app.

Downloads

26

Readme

Auth Armor JavaScript Client-Side SDK

Auth Armor provides a SaaS solution to authenticate your users exclusively using passwordless authentication methods such as WebAuthn, magic links and the proprietary Auth Armor mobile app.

This package allows you to access the client-side SDK for Auth Armor so that you can authenticate users on the client side and get a validation token whose legitimacy you can verify server-side and so you can register users using any of the supported methods you would like to offer.

This package does not come with a UI; if you want a pre-made UI that will work with this package and will allow you to get started with very little configuration, check out autharmor-js-ui.

Installation

This package is available on the NPM registry as @autharmor/autharmor-js. Use your project's package manager to install it:

# NPM
npm install @autharmor/autharmor-js

# PNPM
pnpm add @autharmor/autharmor-js

# Yarn
yarn add @autharmor/autharmor-js

In projects without an NPM package manager, we also serve an IIFE bundle from our CDN which you can load as follows.

<script src="https://cdn.autharmor.com/scripts/autharmor-js/4.0.0-rc.1/global/autharmor-js.js"></script>

This module's exports will then be available in the authArmor global variable. Instead of import statements, you can use destructuring:

const { AuthArmorClient } = authArmor;

Getting Started

This section will demonstrate how you can set up a client and make requests.

Creating the Configuration Object

You will need to create a configuration object of type AuthArmorClientConfiguration. At a minimum, you must provide a client SDK API key (clientSdkApiKey). You can also provide a WebAuthn client ID (webAuthnClientId) if you wish to have WebAuthn support in your client.

const authArmorConfig: AuthArmorClientConfiguration = {
    clientSdkApiKey: "[Your client SDK API key goes here]",
    webAuthnClientId: "[Your WebAuthn client ID goes here]"
};

If you're using TypeScript, you must import AuthArmorClientConfiguration at the top of your file:

import { AuthArmorClientConfiguration } from "@autharmor/sdk";

If you're not using TypeScript, you must omit the : AuthArmorClientConfiguration type annotation.

Instantiating a Client

Once you have the configuration object prepared, you can instantiate AuthArmorClient passing it the configuration as a parameter:

const authArmorClient = new AuthArmorClient(authArmorConfig);

You must import AuthArmorClient at the top of your file:

import { AuthArmorClient } from "@autharmor/sdk";

This client contains all the methods necessary to make requests to Auth Armor.

Initializing the Client

All methods that require the client to be initialized will initialize it as necessary. You only need to initialize the client manually if you want control over when this happens.

A client needs to make some initial requests to set itself up to make other requests. The ensureInitialized method can be used to initialize it:

await authArmorClient.ensureInitialized();

If the client is already initialized, the method does not do anything.

Check Available Authentication Methods

To authenticate a user, in most cases, you must first get their available authentication methods. The getAvailableAuthenticationMethodsAsync method will return an AvailableAuthenticationMethods object.

const availableMethods = await authArmorClient.getAvailableAuthenticationMethodsAsync("username");

The object returned will look similar to this (depending on which methods the user has enabled):

{
    authenticator: true,
    magicLinkEmail: false,
    webAuthn: true
}

If the user was not found, an ApiError will be thrown with statusCode set to 404.

Authenticator Authentication

To authenticate a user using their authenticator app, use the authenticateWithAuthenticatorAsync method. It returns a QrResult which contains an authentication URL which can either be displayed as a QR code, or, on mobile devices, be navigated to on a separate tab to launch the Auth Armor authenticator app or prompt to install it. Calling the resultAsync method on the QrResult will return the AuthenticationResult.

const qrResult = await authArmorClient.authenticateWithAuthenticatorAsync("username");

// You can generate a QR code using this URL and display it on the page.
const { qrCodeUrl } = qrResult;

const authenticationResult = await qrResult.resultAsync();

if (authenticationResult.succeeded) {
    // If the authentication succeeds, you can access the validation token. Send it to the server for validation.
    const { requestId, validationToken } = authenticationResult;
} else {
    // Otherwise, you can access the reason the authentication request failed.
    const { failureReason } = authenticationResult;
}

You can provide a list of options as the second parameter of authenticateWithAuthenticatorAsync like so:

await authArmorClient.authenticateWithAuthenticatorAsync("username", {
    sendPushNotification: false,
    actionName: "Authorize Request",
    shortMessage: "Authorize your special request"
});

Next Steps

Other authentication and registration methods also follow a similar pattern. Refer to the in-code documentation for details on how they work. If you are using an IDE, you will also be able to view the documentation from within your editor.

As a summary, these are the methods available for you:

| Method | Options Object | Return Type | Description | | ------------------------------------------------ | ----------------------------------------------------------------------------------------------- | ----------------------------------------- | ------------------------------------------------------------------------------ | | authenticateWithAuthenticatorAsync | IAuthenticatorUserSpecificAuthenticateOptions | Promise<QrResult<AuthenticationResult>> | Authenticates a user using their authenticator app. | | authenticateWithAuthenticatorUsernamelessAsync | IAuthenticatorUsernamelessAuthenticateOptions | Promise<QrResult<AuthenticationResult>> | Authenticates a user using an authenticator QR code that is not user-specific. | | authenticateWithPasskeyAsync | None | Promise<AuthenticationResult> | Authenticates a user using a passkey. | | sendAuthenticateMagicLinkEmailAsync | IMagicLinkEmailAuthenticateOptions | Promise<void> | Sends an authentication magic link to the user's email address. | | registerWithAuthenticatorAsync | IAuthenticatorRegisterOptions | Promise<QrResult<RegistrationResult>> | Registers a user using an authenticator QR code. | | registerWithPasskeyAsync | IPasskeyRegisterOptions | Promise<RegistrationResult> | Registers a user using a passkey. | | sendRegisterMagicLinkEmailAsync | IMagicLinkEmailRegisterOptions | Promise<void> | Sends a registration magic link to the user's email address. |