# @criipto/auth-js 中文文档

规范地址：https://npmcn.com/package/%40criipto/auth-js/

版本：5\.0\.1
npm 元数据更新时间：2026-09-25T07:52:48.218Z
中文译文更新时间：2026-11-11T00:43:02.239Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40criipto/auth-js
原文对照：https://npmcn.com/package/%40criipto/auth-js/?lang=original
项目主页：https://github.com/criipto/criipto-auth.js#readme
源码仓库：https://github.com/criipto/criipto-auth.js

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：198 kB，7 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2021-08-09T12:49:06.183Z
- 最新版本发布：2026-09-25T07:52:47.888Z
- 近 30 天下载量：70465（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：91（近 12 个月 7 个）

## 中文简介

在您的 Javascript 应用程序中接受 MitID、NemID、瑞典银行ID、挪威银行ID 和其他电子ID供应商的登录 `@criipto/auth-js`。 。 。 .

## 安装

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

也可以使用：`pnpm add @criipto/auth-js`、`yarn add @criipto/auth-js`、`bun add @criipto/auth-js`

## README

# 校对:soup

在您的 Javascript 应用程序中接受 MitID、NemID、瑞典银行ID、挪威银行ID 和其他电子ID供应商的登录 `@criipto/auth-js`。 。 。 .

## 指数

-   [安装](https://npmcn.com/package/%40criipto/auth-js/#readme-install%5D)
-   [使用量](https://npmcn.com/package/%40criipto/auth-js/#readme-usage%5D)
-   [认证](https://npmcn.com/package/%40criipto/auth-js/#readme-auth)
-   [弹出](https://npmcn.com/package/%40criipto/auth-js/#readme-authpopup)
-   [自动方向](https://npmcn.com/package/%40criipto/auth-js/#readme-authredirect)

## 安装

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

## 使用量

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

## 认证

### 初始化/构建者

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

参数:

-   **域( 需要, 字符串)**: 您的 Criipto 应用程序所属域, 例如 `example.criipto.id`。 。 。 .
-   **客户端ID( 需要, 字符串)**: Criipto 应用程序的客户端 ID/ realm.
-   **额外授权参数**: 见 [授权参数](https://npmcn.com/package/%40criipto/auth-js/#readme-authorization-parameters)

### 授权参数

所有授权方法,如 `criiptoAuth.popup.authorize`, (中文(简体) ), `criiptoAuth.redirect.authorize` 财务报告和审定财务报表 `criiptoAuth.authorizeResponsive` 使用一组授权参数。 这些授权参数也可以默认情况下通过 `CriiptoAuth` 建筑师.

-   **重定向Uri (字符串)**: Criipto 将随认证成功或失败的结果调回的 URL 。 它必须在您的 Criipto 应用程序设置中的“ 召回 URL” 中被白列.
-   **字符串(字符串)**: 用于认证的 EID, 如 `urn:grn:authn:dk:mitid:substantial`中,可找到可接受值列表 `https://{YOUR_CRIIPTO_DOMAIN}/.well-known/openid-configuration`

### 授权响应

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

为选择授权方法提供了方便的方法(第1条)`popup` 或者说 `redirect`)基于CSS媒体查询(屏幕大小).

-   **{\[媒体查询:字符串\]:{通过:'poup' }\`rediction', [授权参数](https://npmcn.com/package/%40criipto/auth-js/#readme-authorization-parameters)}}**

## 弹出

### 授权

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

-   **宽度( 可选的, 数字)**:弹出处的宽.
-   **高度( 可选的, 数字)**: 弹出高度
-   **[授权参数](https://npmcn.com/package/%40criipto/auth-js/#readme-authorization-parameters)**

## 自动方向

### 授权

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

将用户浏览器标签重定向到授权 URL 。 经批准后,用户将重新定向到所提供的位置 `redirectUri`。 。 。 .

-   **[授权参数](https://npmcn.com/package/%40criipto/auth-js/#readme-authorization-parameters)**

### 匹配

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

返回带有代码或 id token 密钥的对象(如果在其中存在) `window.location` 搜索(query params)或散列.

## 注销

如果您为您的域启用了 SSO 而您没有使用 `prompt=login` 您可以使用 `logout()` 清除用户SSO会话.

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

## 常见问题

### @criipto/auth-js 是什么？

在您的 Javascript 应用程序中接受 MitID、NemID、瑞典银行ID、挪威银行ID 和其他电子ID供应商的登录 @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 和提交记录判断。

