Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 595902c

Browse files
small update
1 parent cdf6e0a commit 595902c

File tree

8 files changed

+90
-55
lines changed

8 files changed

+90
-55
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.formatOnSave": true
3+
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Alessio Dionisi
3+
Copyright (c) 2018-present Alessio Dionisi
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# HTTP Signature for Insomnia REST Client
2+
23
This is a plugin for the [Insomnia REST Client](https://insomnia.rest/)
34

45
IETF Draft: https://tools.ietf.org/html/draft-cavage-http-signatures-10
56

67
## Install
8+
79
Go to Preferences->Plugins, install `insomnia-plugin-http-signature`
810

911
## How to use
12+
1013
1. Set authentication type to Bearer Token
1114
2. Set Prefix value to Signature
1215
3. Set Token value to HTTP Signature template

package-lock.json

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"name": "insomnia-plugin-http-signature",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"author": "Alessio Dionisi <hello@adns.io>",
55
"description": "HTTP Signature for Insomnia REST Client",
66
"repository": "github:adnsio/insomnia-plugin-http-signature",
7-
"bugs": "https://github.com/adnsio/insomnia-plugin-http-signature/issues",
8-
"homepage": "https://github.com/adnsio/insomnia-plugin-http-signature#readme",
97
"license": "MIT",
10-
"main": "./src/plugin.js",
8+
"main": "plugin.js",
119
"insomnia": {
12-
"name": "http-signature",
13-
"description": "HTTP Signature"
10+
"name": "httpsignature",
11+
"description": "HTTP Signature for Insomnia REST Client"
12+
},
13+
"devDependencies": {
14+
"prettier": "^1.18.2"
1415
}
1516
}

plugin.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const crypto = require('crypto')
2+
const { URL } = require('url')
3+
4+
module.exports.templateTags = [
5+
{
6+
name: 'httpsignature',
7+
displayName: 'HTTP Signature',
8+
description: 'sign http requests',
9+
10+
args: [
11+
{
12+
displayName: 'Key ID',
13+
type: 'string',
14+
},
15+
{
16+
displayName: 'Private Key',
17+
type: 'string',
18+
},
19+
],
20+
21+
async run(context, keyId, privateKey) {
22+
const request = await context.util.models.request.getById(
23+
context.meta.requestId
24+
)
25+
const requestUrl = await context.util.render(request.url)
26+
27+
if (!keyId) throw new Error('missing keyId')
28+
if (!privateKey) throw new Error('missing privateKey')
29+
30+
const parsedUrl = new URL(requestUrl)
31+
for (const parameter of request.parameters) {
32+
if (!parameter.disabled)
33+
parsedUrl.searchParams.append(parameter.name, parameter.value)
34+
}
35+
36+
const algorithmBits = 256
37+
const signAlgorithm = `RSA-SHA${algorithmBits}`
38+
39+
const signatureString = []
40+
signatureString.push(
41+
`(request-target): ${request.method.toLowerCase()} ${
42+
parsedUrl.pathname
43+
}${parsedUrl.search}`
44+
)
45+
signatureString.push(`host: ${parsedUrl.host}`)
46+
const signature = signatureString.join('\n')
47+
48+
const signatureSign = crypto.createSign(signAlgorithm)
49+
const signedSignature = signatureSign
50+
.update(signature)
51+
.sign(
52+
`-----BEGIN RSA PRIVATE KEY-----\n${privateKey}\n-----END RSA PRIVATE KEY-----`,
53+
'base64'
54+
)
55+
56+
const authorization = `keyId="${keyId}", algorithm="${signAlgorithm.toLowerCase()}", headers="(request-target) host", signature="${signedSignature}"`
57+
return authorization
58+
},
59+
},
60+
]

prettier.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
semi: false,
3+
singleQuote: true,
4+
trailingComma: 'es5',
5+
}

src/plugin.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)