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

@criipto/auth-js

v3.6.10

Published

Accept logins from MitID, NemID, Swedish BankID, Norwegian BankID and other e-ID providers in your Javascript app with `@criipto/auth-js`.

Downloads

3,947

Readme

@criipto/auth-js

Accept logins from MitID, NemID, Swedish BankID, Norwegian BankID and other e-ID providers in your Javascript app with @criipto/auth-js.

Index

Install

npm install --save @criipto/auth-js

Usage

import CriiptoAuth from '@criipto/auth-js';

var criiptoAuth = new CriiptoAuth({
  domain: '{YOUR_CRIIPTO_DOMAIN}',
  clientID: '{YOUR_CRIIPTO_APPLICATION_ID}',
  store: sessionStorage
});

criiptoAuth.popup.authorize({
  width: 300,
  height: 400,
  redirectUri: 'http://localhost:8000/example/popup-callback.html',
  acrValues: 'urn:grn:authn:dk:nemid:poces'
});

criiptoAuth.redirect.authorize({
  redirectUri: 'http://localhost:8000/example/index.html',
  acrValues: 'urn:grn:authn:dk:nemid:poces'
});

Auth

Initialize/Constructor

var criiptoAuth = new CriiptoAuth({
  domain: '{YOUR_CRIIPTO_DOMAIN}',
  clientID: '{YOUR_CRIIPTO_APPLICATION_ID}',
  store: sessionStorage
});

var criiptoAuth = new CriiptoAuth({
  domain: '{YOUR_CRIIPTO_DOMAIN}',
  clientID: '{YOUR_CRIIPTO_APPLICATION_ID}',
  store: sessionStorage,
  redirectUri: 'http://localhost:8000/example/index.html',
  acrValues: 'urn:grn:authn:dk:nemid:poces'
});

Parameters:

  • domain (required, string): The domain which your Criipto Application belongs to, such as example.criipto.id.
  • clientID (required, string): The Client ID/realm for your Criipto Application.
  • additional authorization parameters: See Authorization parameters

Authorization parameters

All authorization methods like criiptoAuth.popup.authorize, criiptoAuth.redirect.authorize and criiptoAuth.authorizeResponsive take a set of authorization parameters. These authorization parameters can also be provided by default via the CriiptoAuth constructor.

  • redirectUri (string): The URL where Criipto will call back to with the result of a successful or failed authentication. It must be whitelisted in the "Callback URLs" in your Criipto application settings.
  • acrValues (string): What EID to use for authentication, such as urn:grn:authn:dk:nemid:poces, a list of acceptable values can be found at https://{YOUR_CRIIPTO_DOMAIN}/.well-known/openid-configuration

authorizeResponsive

criiptoAuth.authorizeResponsive({
  '(min-width: 768px)': {
    via: 'popup',
    redirectUri: 'http://localhost:8000/example/popup-callback.html',
    acrValues: 'urn:grn:authn:dk:nemid:poces',
    width: 320,
    height: 460
  },
  '(max-width: 767px)': {
    via: 'redirect',
    redirectUri: 'http://localhost:8000/example/index.html',
    acrValues: 'urn:grn:authn:dk:nemid:poces'
  }
});

Provides a convenient way to pick authorization method (popup or redirect) based on a CSS media query (screen size).

Auth.popup

authorize

const response = await criiptoAuth.popup.authorize({
  width: 300,
  height: 400,
  redirectUri: 'http://localhost:8000/example/popup-callback.html',
  acrValues: 'urn:grn:authn:dk:nemid:poces'
});
console.log(response.id_token, response.claims);

Auth.redirect

authorize

criiptoAuth.redirect.authorize({
  redirectUri: 'http://localhost:8000/example/index.html',
  acrValues: 'urn:grn:authn:dk:nemid:poces'
});

Redirects the users browser tab to the authorization url. After authorization the user will be redirected back to the provided redirectUri.

match

const match = await criiptoAuth.redirect.match();
console.log(match.code);
console.log(match.id_token, match.claims);

Returns an object with a code or id_token key if present in the window.location search (query params) or hash.

Logout

If you have SSO enabled for your domain and you are not using prompt=login you can use logout() to clear the users SSO session.

criiptoAuth.logout({
  redirectUri: 'http://localhost:8000/example/index.html',
});

QRCode

criiptoAuth.qr.authorize(document.getElementById('qr_code_div', {
  acrValues: 'urn:grn:authn:dk:nemid:poces',
}).then(session => {
  // onAcknowledged is executed when the QR code is first scanned
  session.onAcknowledged = () => {
    console.log('Session acknowledged.');
  };

  return session.then(result => {
    console.log(result.id_token ?? result.code);
  });
}).catch(error => {
  console.error(`${error.error}: ${error.error_description}`);
});

A canvas with a QR code will be rendered inside the target element. The user can scan the QR code and then complete the Criipto login flow on their phone, however the result will end up in the initating browser (usually a desktop browser).