@criipto/verify-express

中文文档
1.0.4发布于 2025/06/03MITTypeScriptCommonJS近 30 天下载 2123

接受MitID、NemID、瑞典BankID、挪威BankID以及更多使用Passport或plain Express的Node.js应用程序登录

中文使用文档
文档目录9 节
  1. 安装
  2. 开始
  3. 调试
  4. 带会话的网络应用并重定向.
  5. 护照
  6. 普通快递
  7. 单页应用程序
  8. 护照
  9. 普通快递

criipto 验证- 表达式

接受MitID、NemID、瑞典BankID、挪威BankID以及更多使用Passport或plain Express的Node.js应用程序登录

安装

使用 无

npm install @criipto/verify-express

开始

您可以在您的域名和应用程序客户端 ID 上找到 Criipto 盘。 。 。 .

如果您没有您的客户端秘密存储在任何地方, 请确保启用代码流和/或重现您的客户端秘密 .

以下为单页应用程序和Web应用程序使用例。 你也可以这样 从 GitHub 下载完整样本

调试

DEBUG=@criipto/verify-express*

带会话的网络应用并重定向.

在使用基于方向的认证时必须设置会话 .

您还必须在您的 Criipto 应用程序上注册一个符合您方向处理路径的 URL 的 Callback URL .

// server.js

const express = require('express');
const expressSesssion = require('express-session');
const app = express();

app.use(
  expressSesssion({
    secret: '{{YOUR_SESSION_SECRET}}',
    resave: false,
    saveUninitialized: true
  })
);

护照

// server.js

app.use(passport.initialize());
app.use(passport.session());
passport.serializeUser(function(user, done) {
  done(null, user);
});
passport.deserializeUser(function(user, done) {
  done(null, user);
});

const redirectPassport = new CriiptoVerifyRedirectPassportStrategy(
  {
    domain: "{{YOUR_CRIIPTO_DOMAIN}}",
    clientID: "{{YOUR_CLIENT_ID}}",
    clientSecret: CRIIPTO_CLIENT_SECRET,
    // Should match an express route that is an allowed callback URL in your application
    // This route should also have the authentication middleware applied.
    redirectUri: '/login',
    postLogoutRedirectUri: '/',

    // Ammend authorize request if you wish
    beforeAuthorize(req, options) {
      return {
        ...options,
        acr_values: req.query.acr_values,
        prompt: req.query.prompt
      }
    }
  },
  // Map claims to an express user
  async (jwtClaims) => {
    return jwtClaims;
  }
);

// Route to both trigger and handle redirect
app.get('/login', passport.authenticate('criiptoVerifyRedirect', {failureRedirect: '/error', successReturnToOrRedirect: '/passport/protected'}), (req, res) => {
  res.json(req.user);
});
app.get('/protected', passport.authenticate('criiptoVerifyRedirect', {}), (req, res) => {
  res.json(req.user);
});
app.get('/logout', redirectPassport.logout.bind(redirectPassport));
app.get('/error', function (req, res, next) {
  res.json({
    error: req.query.error,
    error_description: req.query.error_description,
  });
});

普通快递

const expressRedirect = new CriiptoVerifyExpressRedirect({
  domain: "{{YOUR_CRIIPTO_DOMAIN}}",
  clientID: "{{YOUR_CLIENT_ID}}",
  clientSecret: CRIIPTO_CLIENT_SECRET,
  // Should match an express route that is an allowed callback URL in your application
  // This route should also have the authentication middleware applied.
  redirectUri: '/login',
  postLogoutRedirectUri: '/',

  // Ammend authorize request if you wish
  beforeAuthorize(req, options) {
    return {
      ...options,
      acr_values: req.query.acr_values,
      prompt: req.query.prompt
    }
  }
});

// Route to both trigger and handle redirect
app.get('/login', expressRedirect.middleware({failureRedirect: '/error', successReturnToOrRedirect: '/plain/protected'}), (req, res) => {
  res.json(req.claims);
});
app.get('/protected', expressRedirect.middleware({}), (req, res) => {
  res.json(req.claims);
});

app.get('/logout', expressRedirect.logout.bind(expressRedirect));

app.get('/error', function (req, res, next) {
  res.json({
    error: req.query.error,
    error_description: req.query.error_description,
  });
});

单页应用程序

SPA 可以利用前端框架,例如 校对:soup 或者说 @criipto/验证-反应 用于处理前端的登录,然后向它们的API发送一个 Bearer 令牌.

您必须在匹配 Criipto 应用程序的 Criipto 中注册回调 URL href 您正在触发 SPA 登录的 URL .

护照

// server.js
const express = require('express');
const passport = require('passport');
const CriiptoVerifyJwtPassportStrategy = require('@criipto/verify-express').CriiptoVerifyJwtPassportStrategy;

const app = express();

app.use(passport.initialize());
passport.serializeUser(function(user, done) {
  done(null, user);
});
passport.deserializeUser(function(user, done) {
  done(null, user);
});

passport.use(
  'criiptoVerifyJwt',
  new CriiptoVerifyJwtPassportStrategy({
    domain: "{{YOUR_CRIIPTO_DOMAIN}}",
    clientID: "{{YOUR_CLIENT_ID}}"
  },
  // Map claims to an express user
  async (jwtClaims) => {
    return jwtClaims;
  })
);

app.get('/jwt-protected-route', passport.authenticate('criiptoVerifyJwt', { session: false }), (req, res) => {
  res.json({
    ...req.user,
    passport: 'says hi'
  });
});

// client.js
const {id_token} = login();

fetch(`{server}/jwt-protected-route`, {
  headers: {
    Authorization: `Bearer ${id_token}`
  }
})

普通快递

// server.js

const express = require('express');
const CriiptoVerifyExpressJwt = require('@criipto/verify-express').CriiptoVerifyExpressJwt;
const app = express();

const expressJwt = new CriiptoVerifyExpressJwt({
  domain: "{{YOUR_CRIIPTO_DOMAIN}}",
  clientID: "{{YOUR_CLIENT_ID}}"
});

app.get('/jwt-protected-route', expressJwt.middleware(), (req, res) => {
  res.json({
    ...req.user,
    express: 'says hi'
  });
});

// client.js
const {id_token} = login();

fetch(`{server}/jwt-protected-route`, {
  headers: {
    Authorization: `Bearer ${id_token}`
  }
})

版本与发布记录

@criipto/verify-express 共发布 5 个版本,首次发布于 2022/11/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.4latest2025/06/031.4 年前
1.0.32022/12/063 年前
1.0.22022/11/163 年前
1.0.12022/11/163 年前
1.0.02022/11/163 年前

关于 @criipto/verify-express 的常见问题

@criipto/verify-express 是什么?

接受MitID、NemID、瑞典BankID、挪威BankID以及更多使用Passport或plain Express的Node.js应用程序登录

如何安装 @criipto/verify-express?

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

@criipto/verify-express 支持 TypeScript 吗?

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

@criipto/verify-express 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@criipto/verify-express 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@criipto/verify-express 可以商用吗?

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

@criipto/verify-express 的下载量有多少?

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

@criipto/verify-express 还在维护吗?

最新版本 1.0.4 发布于 2025/06/03(1.4 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/11/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。