Skip to content

Commit 49ea4c9

Browse files
committed
Finish Simple Example
1 parent cdd1238 commit 49ea4c9

File tree

5 files changed

+58
-44
lines changed

5 files changed

+58
-44
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@ N8N 1.76.1 and above.
3535

3636
## Usage
3737

38-
Se examples folder
38+
1. Run `cd examples`;
39+
2. Run `docker compose up -d`;
40+
3. Access [http://localhost:8081](http://localhost:8081) and setup N8N;
41+
4. Create a **Redis Credential** and change **Host** field to **redis**;
42+
5. Create a workflow and import the **Simple_Workflow.json** file;
43+
6. Use that credential in **HTTP Forward Auth Trigger** and **HTTP Forward Auth** nodes;
44+
7. Activate the workflow and access [http://localhost:8080](http://localhost:8080).
45+
3946

4047
## Resources
4148

4249
* [n8n community nodes documentation](https://docs.n8n.io/integrations/community-nodes/)
4350
* [Caddy Forward Auth](https://caddyserver.com/docs/caddyfile/directives/forward_auth)
51+
* [RedisVectorStore](https://js.langchain.com/docs/integrations/vectorstores/redis/)

examples/Caddyfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
}
1616

1717
handle /_auth/login {
18-
uri replace /_auth/login webhook/{$WEBHOOK_ID}/login
18+
uri replace _auth webhook/{$WEBHOOK_ID}
1919
reverse_proxy n8n:5678 {
2020
header_up X-Real-IP {remote_host}
2121
}
2222
}
2323

2424
handle /_auth/logout {
25-
uri replace /_auth/logout webhook/{$WEBHOOK_ID}/logout
25+
uri replace _auth webhook/{$WEBHOOK_ID}
2626
reverse_proxy n8n:5678
2727
}
2828

examples/Simple_Workflow.json

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2-
"name": "My workflow",
2+
"name": "Simple Workflow",
33
"nodes": [
44
{
55
"parameters": {
6-
"loginURL": "http://localhost:8080/login",
7-
"afterLoginURL": "http://localhost:8080/protected",
8-
"logoutURL": "http://localhost:8080/login",
6+
"authURL": "http://localhost:8080/_auth",
7+
"loginRedirectURL": "http://localhost:8080",
8+
"logoutRedirectURL": "http://localhost:8080/signed-out",
99
"enableHTTP": true
1010
},
1111
"type": "CUSTOM.httpForwardAuthTrigger",
1212
"typeVersion": 1,
1313
"position": [
14-
-360,
15-
20
14+
0,
15+
0
1616
],
17-
"id": "de7c6620-31c8-4701-b870-dc6825487f35",
17+
"id": "69c907ff-c556-458f-89e4-cd68c6d2bfa8",
1818
"name": "HTTP Forward Auth Trigger",
1919
"webhookId": "aa1e42ef-7492-4235-9f22-e3c007358d15"
2020
},
@@ -26,23 +26,23 @@
2626
"type": "CUSTOM.httpForwardAuth",
2727
"typeVersion": 1,
2828
"position": [
29-
920,
30-
20
29+
1280,
30+
0
3131
],
32-
"id": "3368c9bf-3dab-4bd8-9d7f-d5f1abe7610e",
32+
"id": "5c5bd1f9-68ca-45cc-9c3d-169bd5fed21b",
3333
"name": "HTTP Forward Auth"
3434
},
3535
{
3636
"parameters": {
37-
"jsCode": "const db = {\n \"test1@example.com\": \"g9QaXzlc34l4dEw1c6HOHcBrVP6SFswS|BIVTqZnqdUbrS8JiuugWKl1Ch0NaADWaFcIiDpc4Tac=\",\n \"[email protected]\": \"eSOLsrieYnZ96jNCXfalGF15sJxdluc2|cXFQ/PT1VNb/CRM6SA/d+ADQlS1hwDgtg/tuWipDbbo=\",\n \"[email protected]\": \"kos8kWXOH7Nr7v72q3kXUzxUwxmKx2uo|Rj3A2BLRCtpKFVjxb6IxuSgLIigbt3wlKazsFGmO5ic=\"\n};\n\nconst userRaw = db[$input.first().json.user];\n\nif(userRaw) {\n const [salt, hash] = userRaw.split(\"|\");\n return { salt, hash }\n}\n\nreturn { salt: \"\", hash: \"\" }"
37+
"jsCode": "const db = {\n \"admin@example.com\": \"g9QaXzlc34l4dEw1c6HOHcBrVP6SFswS|Q5LA5FkQb1HpuRz0ppjnQPm13kpyjy7PdgRKIb+VRPI=\" \n};\n\nconst userRaw = db[$input.first().json.user];\n\nif(userRaw) {\n const [salt, hash] = userRaw.split(\"|\");\n return { salt, hash }\n}\n\nreturn { salt: \"\", hash: \"\" }"
3838
},
3939
"type": "n8n-nodes-base.code",
4040
"typeVersion": 2,
4141
"position": [
42-
-60,
43-
20
42+
300,
43+
0
4444
],
45-
"id": "87fa2215-c45c-4950-ae1a-97216eb30e9f",
45+
"id": "1dfbe11d-385d-4eea-9a0f-ebe3425fa6c3",
4646
"name": "Get Data From DB"
4747
},
4848
{
@@ -55,10 +55,10 @@
5555
"type": "n8n-nodes-base.crypto",
5656
"typeVersion": 1,
5757
"position": [
58-
280,
59-
20
58+
640,
59+
0
6060
],
61-
"id": "4ac9ba87-0753-4ad9-af56-acbfdb8ecabf",
61+
"id": "ba283396-0f28-43d7-b460-df3291d5d867",
6262
"name": "Hash Password"
6363
},
6464
{
@@ -68,11 +68,24 @@
6868
"type": "n8n-nodes-base.code",
6969
"typeVersion": 2,
7070
"position": [
71-
600,
72-
20
71+
960,
72+
0
7373
],
74-
"id": "c3c058a6-eb0d-418e-81f2-9cf142360e34",
74+
"id": "6810f87d-f5b4-40ec-872e-9108167f2dcd",
7575
"name": "Verify Password"
76+
},
77+
{
78+
"parameters": {
79+
"content": "## Access Info\nuser: [email protected]\npassword: password"
80+
},
81+
"type": "n8n-nodes-base.stickyNote",
82+
"position": [
83+
240,
84+
-180
85+
],
86+
"typeVersion": 1,
87+
"id": "ad36117b-104b-4f40-9240-c83f909a8085",
88+
"name": "Sticky Note"
7689
}
7790
],
7891
"pinData": {},
@@ -124,19 +137,12 @@
124137
},
125138
"active": true,
126139
"settings": {
127-
"executionOrder": "v1",
128-
"saveDataErrorExecution": "none",
129-
"saveDataSuccessExecution": "none",
130-
"saveExecutionProgress": false,
131-
"saveManualExecutions": false,
132-
"callerPolicy": "workflowsFromSameOwner",
133-
"executionTimeout": -1
140+
"executionOrder": "v1"
134141
},
135-
"versionId": "9b417754-d9d0-4377-8863-e604f59f97f1",
142+
"versionId": "86c9094b-196d-49e0-be04-60f19353569a",
136143
"meta": {
137-
"templateCredsSetupCompleted": true,
138-
"instanceId": "505a91c807f383cfa51524b51406539ed2a13b65faca94769375174ae416a1e6"
144+
"templateCredsSetupCompleted": true
139145
},
140-
"id": "4hi91Jg1ssmzLJwF",
146+
"id": "DRLuFvbB6tyPxGpi",
141147
"tags": []
142148
}

examples/docker-compose.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@ services:
4040
- ./data/grist:/persist
4141
environment:
4242
- GRIST_SESSION_SECRET=invent-a-secret-here
43-
- GRIST_DEFAULT_EMAIL=your-email@example.com
43+
- GRIST_DEFAULT_EMAIL=admin@example.com
4444
- GRIST_SANDBOX_FLAVOR=gvisor
4545
- APP_HOME_URL=http://localhost:8080
4646
- GRIST_SINGLE_ORG=example-com
4747
- COOKIE_MAX_AGE=604800000
4848
- GRIST_HIDE_UI_ELEMENTS=helpCenter,billing,templates,createSite,multiSite,multiAccounts,sendToDrive,tutorials,supportGrist
49-
- GRIST_PAGE_TITLE_SUFFIX=" - Example.com"
49+
- GRIST_PAGE_TITLE_SUFFIX=
5050
- GRIST_WIDGET_LIST_URL="https://github.com/gristlabs/grist-widget/releases/download/latest/manifest.json"
5151
- ALLOWED_WEBHOOK_DOMAINS=n8n:5678
5252
- GRIST_FORWARD_AUTH_HEADER=X-Forwarded-User
5353
- GRIST_FORWARD_AUTH_LOGOUT_PATH=/_auth/logout
54-
# - GRIST_DOCS_MINIO_ACCESS_KEY=grist
55-
# - GRIST_DOCS_MINIO_SECRET_KEY=grist
56-
# - GRIST_DOCS_MINIO_ENDPOINT=s3
57-
# - GRIST_DOCS_MINIO_PORT=8333
58-
# - GRIST_DOCS_MINIO_USE_SSL=0
59-
# - GRIST_DOCS_MINIO_BUCKET=grist
6054
- REDIS_URL=redis://redis:6379
55+
# - GRIST_DOCS_MINIO_ACCESS_KEY=
56+
# - GRIST_DOCS_MINIO_SECRET_KEY=
57+
# - GRIST_DOCS_MINIO_ENDPOINT=
58+
# - GRIST_DOCS_MINIO_PORT=
59+
# - GRIST_DOCS_MINIO_USE_SSL=
60+
# - GRIST_DOCS_MINIO_BUCKET=
6161
depends_on:
6262
redis:
6363
condition: service_healthy

nodes/HttpForwardAuth/HttpForwardAuthTrigger.node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class HttpForwardAuthTrigger implements INodeType {
8282
}
8383
} else if (webhookName === 'default') {
8484
// CSRF protection
85-
const origin = req.headers.Origin;
85+
const { origin } = req.headers;
8686
if (!origin || origin !== new URL(authURL).origin) {
8787
res.status(403).send('Error 403 - Forbidden').end();
8888
} else if (rateLimit && remoteIp && !(await rateLimitConsume(redis, remoteIp))) {
@@ -108,7 +108,7 @@ export class HttpForwardAuthTrigger implements INodeType {
108108
res.status(200).send(pageContent).end();
109109
} else if (webhookName === 'logout') {
110110
// CSRF protection
111-
const origin = req.headers.Origin;
111+
const { origin } = req.headers;
112112
if (!origin || origin !== new URL(authURL).origin) {
113113
res.status(403).send('Error 403 - Forbidden').end();
114114
} else {

0 commit comments

Comments
 (0)