Skip to content

Commit 1cb8818

Browse files
committed
Remove unused jwt_public.current_group_ids() function
- Remove deploy/revert/verify SQL files for current_group_ids - Update pgpm.plan to remove the change entry - Update bundled SQL file to remove the function - Update tests to remove group_ids references - Update README to remove group_ids documentation Co-Authored-By: Dan Lynch <pyramation@gmail.com>
1 parent a8b1df7 commit 1cb8818

8 files changed

Lines changed: 3 additions & 125 deletions

File tree

packages/jwt-claims/README.md

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ JWT claim handling and validation functions.
2121
## Features
2222

2323
- **User Context Functions**: Extract user ID from JWT claims
24-
- **Group Membership**: Access user's group IDs
2524
- **Request Metadata**: Get IP address and user agent from requests
2625
- **Database Context**: Access database ID from JWT claims
2726
- **Type-Safe Extraction**: Proper error handling for invalid claim values
@@ -93,18 +92,6 @@ SELECT jwt_public.current_user_id();
9392

9493
**JWT Claim:** `jwt.claims.user_id`
9594

96-
### jwt_public.current_group_ids()
97-
Extracts the user's group IDs from JWT claims.
98-
99-
**Returns:** `uuid[]` - Array of group IDs, or empty array if not set
100-
101-
**Usage:**
102-
```sql
103-
SELECT jwt_public.current_group_ids();
104-
```
105-
106-
**JWT Claim:** `jwt.claims.group_ids`
107-
10895
### jwt_public.current_ip_address()
10996
Extracts the client's IP address from JWT claims.
11097

@@ -151,9 +138,6 @@ JWT claims are set as PostgreSQL session variables, typically by your authentica
151138
-- Set user ID claim
152139
SELECT set_config('jwt.claims.user_id', 'user-uuid-here', false);
153140

154-
-- Set group IDs claim
155-
SELECT set_config('jwt.claims.group_ids', '{uuid1,uuid2,uuid3}', false);
156-
157141
-- Set IP address claim
158142
SELECT set_config('jwt.claims.ip_address', '192.168.1.1', false);
159143

@@ -176,11 +160,6 @@ CREATE POLICY user_posts ON posts
176160
TO authenticated
177161
USING (user_id = jwt_public.current_user_id());
178162

179-
-- Users can see posts from their groups
180-
CREATE POLICY group_posts ON posts
181-
FOR SELECT
182-
TO authenticated
183-
USING (group_id = ANY(jwt_public.current_group_ids()));
184163
```
185164

186165
### Using Claims in Functions
@@ -200,13 +179,6 @@ BEGIN
200179
END;
201180
$$ LANGUAGE plpgsql;
202181

203-
-- Function that checks group membership
204-
CREATE FUNCTION user_in_group(group_id uuid)
205-
RETURNS boolean AS $$
206-
BEGIN
207-
RETURN group_id = ANY(jwt_public.current_group_ids());
208-
END;
209-
$$ LANGUAGE plpgsql;
210182
```
211183

212184
### Audit Logging with JWT Claims
@@ -311,10 +283,6 @@ All functions include error handling for invalid claim values:
311283
-- If jwt.claims.user_id is not a valid UUID
312284
SELECT jwt_public.current_user_id();
313285
-- Returns NULL and raises NOTICE: 'Invalid UUID value'
314-
315-
-- If jwt.claims.group_ids is not a valid UUID array
316-
SELECT jwt_public.current_group_ids();
317-
-- Returns empty array [] and raises NOTICE: 'Invalid UUID value'
318286
```
319287

320288
## Security Considerations

packages/jwt-claims/__tests__/__snapshots__/jwt.test.ts.snap

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ exports[`get values 3`] = `
1919
`;
2020

2121
exports[`get values 4`] = `
22-
{
23-
"group_ids": [
24-
"f12c75c2-47d5-43fd-9223-d42d08f51942",
25-
"d96d32b4-e819-4cb1-8a27-e27e763e0d7f",
26-
"c8a27b31-1d40-4f40-9cb0-e96a44e68072",
27-
],
28-
}
29-
`;
30-
31-
exports[`get values 5`] = `
3222
{
3323
"user_id": "b9d22af1-62c7-43a5-b8c4-50630bbd4962",
3424
}

packages/jwt-claims/__tests__/jwt.test.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ let teardown: () => Promise<void>;
55

66
const jwt = {
77
user_id: 'b9d22af1-62c7-43a5-b8c4-50630bbd4962',
8-
database_id: '44744c94-93cf-425a-b524-ce6f1466e327',
9-
group_ids: [
10-
'f12c75c2-47d5-43fd-9223-d42d08f51942',
11-
'd96d32b4-e819-4cb1-8a27-e27e763e0d7f',
12-
'c8a27b31-1d40-4f40-9cb0-e96a44e68072'
13-
]
8+
database_id: '44744c94-93cf-425a-b524-ce6f1466e327'
149
};
1510

1611
beforeAll(async () => {
@@ -28,15 +23,13 @@ it('get values', async () => {
2823
set_config('jwt.claims.user_agent', $1, true),
2924
set_config('jwt.claims.ip_address', $2, true),
3025
set_config('jwt.claims.database_id', $3, true),
31-
set_config('jwt.claims.user_id', $4, true),
32-
set_config('jwt.claims.group_ids', $5, true)
26+
set_config('jwt.claims.user_id', $4, true)
3327
`,
3428
[
3529
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
3630
'127.0.0.1',
3731
jwt.database_id,
38-
jwt.user_id,
39-
`{${jwt.group_ids.join(',')}}`
32+
jwt.user_id
4033
]
4134
);
4235

@@ -49,9 +42,6 @@ it('get values', async () => {
4942
const { database_id } = await pg.one(
5043
`select jwt_private.current_database_id() as database_id`
5144
);
52-
const { group_ids } = await pg.one(
53-
`select jwt_public.current_group_ids() as group_ids`
54-
);
5545
const { user_id } = await pg.one(
5646
`select jwt_public.current_user_id() as user_id`
5747
);
@@ -60,6 +50,5 @@ it('get values', async () => {
6050
expect({ user_agent }).toMatchSnapshot();
6151
expect({ ip_address }).toMatchSnapshot();
6252
expect({ database_id }).toMatchSnapshot();
63-
expect({ group_ids }).toMatchSnapshot();
6453
expect({ user_id }).toMatchSnapshot();
6554
});

packages/jwt-claims/deploy/schemas/jwt_public/procedures/current_group_ids.sql

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

packages/jwt-claims/pgpm.plan

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ schemas/jwt_public/procedures/current_user_id [schemas/jwt_public/schema] 2020-1
1313
schemas/jwt_public/procedures/current_ip_address [schemas/jwt_public/schema] 2020-12-17T23:19:17Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_public/procedures/current_ip_address
1414
schemas/jwt_public/procedures/current_user_agent [schemas/jwt_public/schema] 2020-12-17T23:20:04Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_public/procedures/current_user_agent
1515
schemas/jwt_public/procedures/current_origin [schemas/jwt_public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/jwt_public/procedures/current_origin
16-
schemas/jwt_public/procedures/current_group_ids [schemas/jwt_public/schema] 2020-12-17T23:30:50Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_public/procedures/current_group_ids
1716
schemas/jwt_private/schema 2020-12-17T06:47:34Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_private/schema
1817
schemas/jwt_private/procedures/current_database_id [schemas/jwt_private/schema] 2020-12-17T23:22:28Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_private/procedures/current_database_id
1918
schemas/jwt_private/procedures/current_token_id [schemas/jwt_private/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/jwt_private/procedures/current_token_id

packages/jwt-claims/revert/schemas/jwt_public/procedures/current_group_ids.sql

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

packages/jwt-claims/sql/pgpm-jwt-claims--0.15.2.sql

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,6 @@ CREATE FUNCTION jwt_public.current_origin() RETURNS origin AS $EOFCODE$
115115
SELECT nullif(current_setting('jwt.claims.origin', true), '')::origin;
116116
$EOFCODE$ LANGUAGE sql STABLE;
117117

118-
CREATE FUNCTION jwt_public.current_group_ids() RETURNS uuid[] AS $EOFCODE$
119-
DECLARE
120-
v_identifier_ids uuid[];
121-
BEGIN
122-
IF current_setting('jwt.claims.group_ids', TRUE)
123-
IS NOT NULL THEN
124-
BEGIN
125-
v_identifier_ids = current_setting('jwt.claims.group_ids', TRUE)::uuid[];
126-
EXCEPTION
127-
WHEN OTHERS THEN
128-
RAISE NOTICE 'Invalid UUID value';
129-
RETURN ARRAY[]::uuid[];
130-
END;
131-
RETURN v_identifier_ids;
132-
ELSE
133-
RETURN ARRAY[]::uuid[];
134-
END IF;
135-
END;
136-
$EOFCODE$ LANGUAGE plpgsql STABLE;
137-
138118
CREATE SCHEMA jwt_private;
139119

140120
GRANT USAGE ON SCHEMA jwt_private TO authenticated, anonymous;

packages/jwt-claims/verify/schemas/jwt_public/procedures/current_group_ids.sql

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

0 commit comments

Comments
 (0)