Skip to content

Commit 17b20d3

Browse files
committed
Ability to decode JWT headers
1 parent 9ca7f2b commit 17b20d3

3 files changed

Lines changed: 108 additions & 91 deletions

File tree

README.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
Docker image which echoes various HTTP request properties back to client, as well as in docker logs.
1+
Docker image which echoes various HTTP request properties back to client, as well as in the Docker container logs.
2+
You can use your own certificates, choose your ports, decode JWT headers and filter out certain paths
23

34
![browser](https://raw.githubusercontent.com/mendhak/docker-http-https-echo/master/screenshots/screenshot.png)
45

5-
## Usage
6+
## Basic Usage
67

78
Run with Docker
89

@@ -17,20 +18,6 @@ Then, issue a request via your browser or curl, and watch the response, as well
1718
curl -k -X PUT -H "Arbitrary:Header" -d aaa=bbb https://localhost:8443/hello-world
1819

1920

20-
## Use your own certificates
21-
22-
You can substitute the certificate and private key with your own. This example uses the snakeoil cert.
23-
24-
my-http-listener:
25-
image: mendhak/http-https-echo
26-
ports:
27-
- "8080:80"
28-
- "8443:443"
29-
volumes:
30-
- /etc/ssl/certs/ssl-cert-snakeoil.pem:/app/fullchain.pem
31-
- /etc/ssl/private/ssl-cert-snakeoil.key:/app/privkey.pem
32-
33-
3421
## Choose your ports
3522

3623
You can choose a different internal port instead of 80 and 443 with the `HTTP_PORT` and `HTTPS_PORT` environment variables.
@@ -51,6 +38,35 @@ With docker compose, this would be:
5138
- "8080:8888"
5239
- "8443:9999"
5340

41+
42+
## Use your own certificates
43+
44+
Use volume mounting to substitute the certificate and private key with your own. This example uses the snakeoil cert.
45+
46+
my-http-listener:
47+
image: mendhak/http-https-echo
48+
ports:
49+
- "8080:80"
50+
- "8443:443"
51+
volumes:
52+
- /etc/ssl/certs/ssl-cert-snakeoil.pem:/app/fullchain.pem
53+
- /etc/ssl/private/ssl-cert-snakeoil.key:/app/privkey.pem
54+
55+
56+
57+
## Decode JWT header
58+
59+
If you specify the header that contains the JWT, the echo output will contain the decoded JWT. Use the `JWT_HEADER` environment variable for this.
60+
61+
docker run -e JWT_HEADER=Authentication -p 8080:80 -p 8443:443 --rm -it mendhak/http-https-echo
62+
63+
64+
Now make your request with `Authentication: eyJ...` header (it should also work with the `Authentication: Bearer eyJ...` schema too):
65+
66+
curl -k -H "Authentication: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" http://localhost:8080/
67+
68+
And in the output you should see a `jwt` section.
69+
5470
## Do not log specific path
5571

5672
Set the environment variable `LOG_IGNORE_PATH` to a path you would like to exclude from verbose logging to stdout.

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ app.all('*', (req, res) => {
4242
}
4343
};
4444
if (process.env.JWT_HEADER) {
45-
const token = req.headers[process.env.JWT_HEADER.toLowerCase()];
45+
let token = req.headers[process.env.JWT_HEADER.toLowerCase()];
4646
if (!token) {
4747
echo.jwt = token;
4848
} else {
49+
token = token.split(" ").pop();
4950
const decoded = jwt.decode(token, {complete: true});
5051
echo.jwt = decoded;
5152
}

package-lock.json

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

0 commit comments

Comments
 (0)