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

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
@@ -33,8 +33,8 @@ module.exports = fp(async (fastify, options) => {
33
33
  return fastify.account.models.user;
34
34
  },
35
35
  getOpenApiParams: request => {
36
- const { appid: appId, timestamp, expire, signature } = request.headers;
37
- return { appId, timestamp, expire, signature };
36
+ const { ['x-openapi-appid']: appId, ['x-openapi-timestamp']: timestamp, ['x-openapi-expire']: expire, ['x-openapi-signature']: signature } = request.headers;
37
+ return Object.assign({}, { appId, timestamp, expire, signature }, request.body?.openApiParams);
38
38
  }
39
39
  },
40
40
  options
@@ -4,10 +4,10 @@ const crypto = require('crypto');
4
4
  module.exports = fp(async (fastify, options) => {
5
5
  const { models, services } = fastify[options.name];
6
6
 
7
- const create = async (authenticatePayload, { description }) => {
7
+ const create = async (authenticatePayload, { description, userId: targetUserId }) => {
8
8
  const { id: userId } = authenticatePayload;
9
9
  const secretKey = crypto.randomBytes(options.secretLength).toString('hex');
10
- const newSecret = await models.secret.create({ secretKey, description, userId });
10
+ const newSecret = await models.secret.create({ secretKey, description, userId: targetUserId || userId });
11
11
  return { appId: newSecret.id, secretKey: newSecret.secretKey };
12
12
  };
13
13
 
@@ -34,7 +34,7 @@ module.exports = fp(async (fastify, options) => {
34
34
  if (expectedSignature !== signature) {
35
35
  return {
36
36
  result: false,
37
- message: 'Invalid signature'
37
+ message: `Invalid signature [${appId},${signature},${timestamp},${expire}]`
38
38
  };
39
39
  }
40
40
 
@@ -50,9 +50,8 @@ module.exports = fp(async (fastify, options) => {
50
50
  const list = async (authenticatePayload, { perPage, currentPage }) => {
51
51
  const { id: userId } = authenticatePayload;
52
52
  const { count, rows } = await models.secret.findAndCountAll({
53
- where: {
54
- userId
55
- },
53
+ include: options.getUserModel(),
54
+ where: {},
56
55
  limit: perPage,
57
56
  offset: (currentPage - 1) * perPage
58
57
  });
@@ -62,6 +61,7 @@ module.exports = fp(async (fastify, options) => {
62
61
  id: item.id,
63
62
  appId: item.id,
64
63
  secretKey: item.secretKey.substring(0, 3) + '*'.repeat(8) + item.secretKey.substring(item.secretKey.length - 3),
64
+ user: item.user,
65
65
  description: item.description,
66
66
  lastVisitedAt: item.lastVisitedAt,
67
67
  status: item.status,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-signature",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.2",
4
4
  "description": "用于实现一个签名和验证算法",
5
5
  "main": "index.js",
6
6
  "scripts": {