# @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`.

Latest version **5.0.1** (published 2026-09-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @criipto/auth-js
pnpm add @criipto/auth-js
yarn add @criipto/auth-js
bun add @criipto/auth-js
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 5.0.1 |
| Published | 2026-09-25 |
| First published | 2021-08-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 193.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Maintainers | sgryt, mickhansen, janaameier |

## Links

- npm: https://www.npmjs.com/package/@criipto/auth-js
- Repository: https://github.com/criipto/criipto-auth.js
- Homepage: https://github.com/criipto/criipto-auth.js#readme
- Issues: https://github.com/criipto/criipto-auth.js/issues
- npm.io page: https://npm.io/package/@criipto/auth-js

## Dependencies (1)

- [jose](https://npm.io/package/jose.md) ^6.2.2

## Recent versions

- 5.0.1 (latest) — 2026-09-25
- 5.0.0 — 2026-09-16
- 4.0.3 — 2026-03-24
- 4.0.2 — 2026-03-19
- 4.0.1 — 2026-03-06
- 4.0.0 — 2026-03-06
- 3.8.2 — 2026-03-03
- 3.8.0 — 2025-10-21
- 3.7.2 — 2024-08-05
- 3.7.1 — 2024-08-05
- 3.7.0 — 2024-06-27
- 3.6.11 — 2024-05-30
- 3.6.10 — 2024-03-13
- 3.6.9 — 2024-02-06
- 3.6.8 — 2023-10-20
- … 76 more at https://npm.io/package/@criipto/auth-js/versions

## 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](#install])
- [Usage](#usage])
- [Auth](#auth)
- [Auth.popup](#authpopup)
- [Auth.redirect](#authredirect)

## Install

```
npm install --save @criipto/auth-js
```

## Usage

```javascript
import CriiptoAuth from "@criipto/auth-js";
import "@criipto/auth-js/index.css";

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:mitid:substantial",
});

criiptoAuth.redirect.authorize({
  redirectUri: "http://localhost:8000/example/index.html",
  acrValues: "urn:grn:authn:dk:mitid:substantial",
});
```

## Auth

### Initialize/Constructor

```javascript
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:mitid:substantial",
});
```

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)

### 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:mitid:substantial`, a list of acceptable values can be found at `https://{YOUR_CRIIPTO_DOMAIN}/.well-known/openid-configuration`

### authorizeResponsive

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

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

- **{[mediaQuery: string]: {via: 'popup' | 'redirect', [Authorization parameters](#authorization-parameters)}}**

## Auth.popup

### authorize

```javascript
const response = await criiptoAuth.popup.authorize({
  width: 300,
  height: 400,
  redirectUri: "http://localhost:8000/example/popup-callback.html",
  acrValues: "urn:grn:authn:dk:mitid:substantial",
  /** Using a random state is helpful,
   * if your users are able to
   * trigger new popups while a request
   * is still pending */
  state: Math.random().toString(),
});
console.log(response.id_token, response.claims);
```

- **width (optional, number)**: Width of the popup.
- **height (optional, number)**: Height of the popup
- **[Authorization parameters](#authorization-parameters)**

## Auth.redirect

### authorize

```javascript
criiptoAuth.redirect.authorize({
  redirectUri: "http://localhost:8000/example/index.html",
  acrValues: "urn:grn:authn:dk:mitid:substantial",
});
```

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

- **[Authorization parameters](#authorization-parameters)**

### match

```javascript
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.

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

---
_Source: https://npm.io/package/@criipto/auth-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
