WebAuthn 开源项目使用教程

随笔3周前发布 落凡
34 0 0

WebAuthn 开源项目使用教程

webauthnWin32 APIs for WebAuthn standard项目地址:https://gitcode.com/gh_mirrors/webauthn1/webauthn

1. 项目的目录结构及介绍

  1. webauthn/

  2. ├── README.md

  3. ├── package.json

  4. ├── src/

  5. │ ├── index.js

  6. │ ├── config/

  7. │ │ ├── default.json

  8. │ │ ├── production.json

  9. │ ├── routes/

  10. │ │ ├── auth.js

  11. │ │ ├── index.js

  12. │ ├── models/

  13. │ │ ├── user.js

  14. │ ├── controllers/

  15. │ │ ├── authController.js

  16. │ ├── utils/

  17. │ │ ├── webauthn.js

  18. ├── public/

  19. │ ├── index.html

  20. │ ├── styles.css

  21. ├── tests/

  22. │ ├── auth.test.js

目录结构说明

  • README.md: 项目说明文档。
  • package.json: 项目依赖和脚本配置文件。
  • src/: 源代码目录。
    • index.js: 项目入口文件。
    • config/: 配置文件目录。
      • default.json: 默认配置文件。
      • production.json: 生产环境配置文件。
    • routes/: 路由文件目录。
      • auth.js: 认证路由文件。
      • index.js: 主路由文件。
    • models/: 数据模型文件目录。
      • user.js: 用户模型文件。
    • controllers/: 控制器文件目录。
      • authController.js: 认证控制器文件。
    • utils/: 工具文件目录。
      • webauthn.js: WebAuthn 工具文件。
  • public/: 静态文件目录。
    • index.html: 主页HTML文件。
    • styles.css: 样式文件。
  • tests/: 测试文件目录。
    • auth.test.js: 认证测试文件。

2. 项目的启动文件介绍

src/index.js

  1. const express = require('express');

  2. const bodyParser = require('body-parser');

  3. const config = require('config');

  4. const routes = require('./routes');

  5. const app = express();

  6. app.use(bodyParser.json());

  7. app.use('/', routes);

  8. const port = config.get('port') || 3000;

  9. app.listen(port, () => {

  10. console.log(`Server is running on port ${port}`);

  11. });

启动文件说明

  • 引入 express 框架和 body-parser 中间件。
  • 加载配置文件 config
  • 引入并使用路由文件 routes
  • 监听配置文件中定义的端口,默认为 3000。

3. 项目的配置文件介绍

src/config/default.json

  1. {

  2. "port": 3000,

  3. "webauthn": {

  4. "rpName": "Example Corp",

  5. "rpID": "example.com",

  6. "origin": "https://example.com"

  7. }

  8. }

src/config/production.json

  1. {

  2. "port": 8080,

  3. "webauthn": {

  4. "rpName": "Production Corp",

  5. "rpID": "prod.example.com",

  6. "origin": "https://prod.example.com"

  7. }

  8. }

配置文件说明

  • port: 服务器监听的端口。
  • webauthn: WebAuthn 相关配置。
    • rpName: 依赖方名称。
    • rpID: 依赖方ID。
    • origin: 认证请求的来源。

以上是基于 https://github.com/microsoft/webauthn.git 项目的使用教程,包含了项目的目录结构、启动文件和配置文件的详细介绍。希望对您有所帮助!

webauthnWin32 APIs for WebAuthn standard项目地址:https://gitcode.com/gh_mirrors/webauthn1/webauthn

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...