Skip to content

Commit 4ac0ef5

Browse files
committed
fixed issue as per review comments
1 parent 993778a commit 4ac0ef5

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

functions/jwt-parser/1.0.0/README.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A Serverless Workflow 1.x function that decodes JWT (JSON Web Token) payloads us
44

55
## Technical Implementation
66

7-
This function implements JWT payload extraction through a `set` task using jq expressions:
7+
This function implements JWT payload extraction through a `run` task using jq expressions:
88

99
**Core JWT Decoding Logic:**
1010
```jq
@@ -36,10 +36,10 @@ document:
3636
version: 1.0.0
3737
do:
3838
- decodeJWT:
39-
use: jwt-parser
39+
call: jwt-parser
4040
with:
4141
token: ${ .headers.authorization }
42-
# Returns: { claims: {...}, result: {...} }
42+
# Returns: complete JWT payload as JSON object
4343
```
4444

4545
### Specific Claim Extraction
@@ -52,17 +52,17 @@ document:
5252
version: 1.0.0
5353
do:
5454
- extractSubject:
55-
use: jwt-parser
55+
call: jwt-parser
5656
with:
5757
token: ${ .headers.authorization }
5858
claimPath: ".sub"
59-
# Returns: { claims: {...}, result: "user-id-123" }
59+
# Returns: "user-id-123"
6060
- extractNestedClaim:
61-
use: jwt-parser
61+
call: jwt-parser
6262
with:
6363
token: ${ .headers.authorization }
6464
claimPath: ".custom.department"
65-
# Returns: { claims: {...}, result: "engineering" }
65+
# Returns: "engineering"
6666
```
6767

6868
### Token Format Handling
@@ -75,11 +75,11 @@ document:
7575
version: 1.0.0
7676
do:
7777
- parseRawToken:
78-
use: jwt-parser
78+
call: jwt-parser
7979
with:
8080
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.signature"
8181
- parseBearerToken:
82-
use: jwt-parser
82+
call: jwt-parser
8383
with:
8484
token: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.signature"
8585
# Both handle the token format automatically
@@ -94,19 +94,27 @@ do:
9494
| `claimPath` | string | No | jq path expression for specific claim extraction |
9595

9696
### Output Structure
97+
98+
**When `claimPath` is NOT provided** (complete payload):
9799
```json
98100
{
99-
"claims": {
100-
"sub": "user-123",
101-
"preferred_username": "john.doe",
102-
"email": "[email protected]",
103-
"exp": 1234567890,
104-
"iat": 1234567800
105-
},
106-
"result": "..." // Complete payload or specific claim based on claimPath
101+
"sub": "user-123",
102+
"preferred_username": "john.doe",
103+
"email": "[email protected]",
104+
"exp": 1234567890,
105+
"iat": 1234567800
107106
}
108107
```
109108

109+
**When `claimPath` is provided** (specific claim value):
110+
```json
111+
"user-123"
112+
```
113+
or
114+
```json
115+
"engineering"
116+
```
117+
110118
## Technical Details
111119

112120
### JWT Token Structure

functions/jwt-parser/1.0.0/function.yaml

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,18 @@ input:
1515
output:
1616
schema:
1717
document:
18-
type: object
19-
description: The parsed JWT payload or extracted claim as a JSON object
20-
use: set
21-
set:
22-
claims: >-
23-
(if (.token | startswith("Bearer ")) then .token[7:] else .token end) |
24-
split(".") |
25-
if length != 3 then error("Invalid JWT format: must have 3 parts") else .[1] end |
26-
@base64d |
27-
fromjson
28-
result: >-
29-
((if (.token | startswith("Bearer ")) then .token[7:] else .token end) |
30-
split(".") |
31-
if length != 3 then error("Invalid JWT format: must have 3 parts") else .[1] end |
32-
@base64d |
33-
fromjson) as $decoded |
34-
if (.claimPath // null) != null then
35-
(.claimPath | split(".") | map(select(. != ""))) as $path |
36-
$decoded | getpath($path)
37-
else
38-
$decoded
39-
end
18+
description: The parsed JWT payload (when claimPath not provided) or the specific claim value (when claimPath provided)
19+
run:
20+
set:
21+
result: >-
22+
((if (.token | startswith("Bearer ")) then .token[7:] else .token end) |
23+
split(".") |
24+
if length != 3 then error("Invalid JWT format: must have 3 parts") else .[1] end |
25+
@base64d |
26+
fromjson) as $decoded |
27+
if (.claimPath // null) != null then
28+
(.claimPath | split(".") | map(select(. != ""))) as $path |
29+
$decoded | getpath($path)
30+
else
31+
$decoded
32+
end

0 commit comments

Comments
 (0)