@kne/fastify-signature 1.0.0-alpha.4 → 1.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -31,6 +31,10 @@ module.exports = fp(async (fastify, options) => {
31
31
  throw new Error('fastify-account plugin must be registered before fastify-trtc-conference,or set options.getUserModel');
32
32
  }
33
33
  return fastify.account.models.user;
34
+ },
35
+ getOpenApiParams: request => {
36
+ const { appid: appId, timestamp, expire, signature } = request.headers;
37
+ return { appId, timestamp, expire, signature };
34
38
  }
35
39
  },
36
40
  options
@@ -53,16 +57,11 @@ module.exports = fp(async (fastify, options) => {
53
57
  'authenticate',
54
58
  {
55
59
  openApi: async request => {
56
- const { appId, timestamp, expire, signature } = request.headers;
57
- const { result, message } = await fastify[options.name].services.verify({
58
- appId,
59
- timestamp,
60
- expire,
61
- signature
62
- });
60
+ const { result, message, userId } = await fastify[options.name].services.verify(options.getOpenApiParams(request));
63
61
  if (result !== true) {
64
62
  throw new Unauthorized(message);
65
63
  }
64
+ request.openApiPayload = await options.getUserModel().findByPk(userId);
66
65
  }
67
66
  }
68
67
  ]
@@ -42,7 +42,8 @@ module.exports = fp(async (fastify, options) => {
42
42
 
43
43
  return {
44
44
  result: true,
45
- message: 'signature valid'
45
+ message: 'signature valid',
46
+ userId: secret.userId
46
47
  };
47
48
  };
48
49
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-signature",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.6",
4
4
  "description": "用于实现一个签名和验证算法",
5
5
  "main": "index.js",
6
6
  "scripts": {