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

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);
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
 
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.0",
4
4
  "description": "用于实现一个签名和验证算法",
5
5
  "main": "index.js",
6
6
  "scripts": {