@criipto/auth-js

中文文档
5.0.1发布于 2026/09/25MITTypeScriptES Module构建来源已验证近 30 天下载 7万

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

原始使用文档
文档目录13 节
  1. Index
  2. Install
  3. Usage
  4. Auth
  5. Initialize/Constructor
  6. Authorization parameters
  7. authorizeResponsive
  8. Auth.popup
  9. authorize
  10. Auth.redirect
  11. authorize
  12. match
  13. Logout

@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";
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

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

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

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).

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: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);

Auth.redirect

authorize

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.

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

版本与发布记录

@criipto/auth-js 共发布 91 个版本,首次发布于 2021/08/09;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.0.1latest2026/09/251 个月前
5.0.02026/09/161 个月前
4.0.32026/03/247 个月前
4.0.22026/03/197 个月前
4.0.12026/03/068 个月前
4.0.02026/03/068 个月前

关于 @criipto/auth-js 的常见问题

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

如何安装 @criipto/auth-js?

在项目目录运行 npm install @criipto/auth-js,或使用 pnpm add / yarn add / bun add。

@criipto/auth-js 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@criipto/auth-js 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@criipto/auth-js 可以商用吗?

@criipto/auth-js 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@criipto/auth-js 的下载量有多少?

根据 npm 官方下载统计,@criipto/auth-js 在 2026/10/11 – 2026/11/09 这 30 天内被下载 70,465 次,日均约 2,349 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@criipto/auth-js 还在维护吗?

最新版本 5.0.1 发布于 2026/09/25(1 个月前);至今共发布 91 个版本,其中过去 12 个月发布了 7 个;首次发布于 2021/08/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。