@pgpm/jwt-claims 0.15.2 → 0.15.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Makefile +1 -1
- package/README.md +27 -35
- package/__tests__/__snapshots__/jwt.test.ts.snap +0 -10
- package/__tests__/jwt.test.ts +3 -14
- package/deploy/schemas/ctx/procedures/ip_address.sql +3 -0
- package/deploy/schemas/ctx/procedures/origin.sql +3 -0
- package/deploy/schemas/ctx/procedures/security_definer.sql +5 -0
- package/deploy/schemas/ctx/procedures/uagent.sql +18 -0
- package/deploy/schemas/ctx/procedures/uid.sql +18 -0
- package/deploy/schemas/jwt_private/procedures/current_database_id.sql +4 -0
- package/deploy/schemas/jwt_private/procedures/current_token_id.sql +3 -0
- package/deploy/schemas/jwt_public/procedures/current_ip_address.sql +4 -0
- package/deploy/schemas/jwt_public/procedures/current_origin.sql +3 -0
- package/deploy/schemas/jwt_public/procedures/current_user_agent.sql +4 -0
- package/deploy/schemas/jwt_public/procedures/current_user_id.sql +4 -0
- package/package.json +4 -4
- package/pgpm-jwt-claims.control +1 -1
- package/pgpm.plan +2 -3
- package/revert/schemas/ctx/procedures/uagent.sql +8 -0
- package/revert/schemas/ctx/procedures/uid.sql +8 -0
- package/sql/{pgpm-jwt-claims--0.14.0.sql → pgpm-jwt-claims--0.15.2.sql} +2 -22
- package/verify/schemas/ctx/procedures/uagent.sql +8 -0
- package/verify/schemas/ctx/procedures/uid.sql +8 -0
- package/deploy/schemas/ctx/procedures/user_agent.sql +0 -15
- package/deploy/schemas/ctx/procedures/user_id.sql +0 -15
- package/deploy/schemas/jwt_public/procedures/current_group_ids.sql +0 -30
- package/revert/schemas/ctx/procedures/user_agent.sql +0 -8
- package/revert/schemas/ctx/procedures/user_id.sql +0 -8
- package/revert/schemas/jwt_public/procedures/current_group_ids.sql +0 -7
- package/verify/schemas/ctx/procedures/user_agent.sql +0 -8
- package/verify/schemas/ctx/procedures/user_id.sql +0 -8
- package/verify/schemas/jwt_public/procedures/current_group_ids.sql +0 -7
package/Makefile
CHANGED
package/README.md
CHANGED
|
@@ -21,7 +21,6 @@ JWT claim handling and validation functions.
|
|
|
21
21
|
## Features
|
|
22
22
|
|
|
23
23
|
- **User Context Functions**: Extract user ID from JWT claims
|
|
24
|
-
- **Group Membership**: Access user's group IDs
|
|
25
24
|
- **Request Metadata**: Get IP address and user agent from requests
|
|
26
25
|
- **Database Context**: Access database ID from JWT claims
|
|
27
26
|
- **Type-Safe Extraction**: Proper error handling for invalid claim values
|
|
@@ -41,7 +40,7 @@ This is a quick way to get started. The sections below provide more detailed ins
|
|
|
41
40
|
### Prerequisites
|
|
42
41
|
|
|
43
42
|
```bash
|
|
44
|
-
# Install pgpm CLI
|
|
43
|
+
# Install pgpm CLI
|
|
45
44
|
npm install -g pgpm
|
|
46
45
|
|
|
47
46
|
# Start local Postgres (via Docker) and export env vars
|
|
@@ -58,7 +57,7 @@ eval "$(pgpm env)"
|
|
|
58
57
|
pgpm install @pgpm/jwt-claims
|
|
59
58
|
|
|
60
59
|
# 2. Deploy locally
|
|
61
|
-
pgpm deploy
|
|
60
|
+
pgpm deploy
|
|
62
61
|
```
|
|
63
62
|
|
|
64
63
|
### **Add to a New Project**
|
|
@@ -93,18 +92,6 @@ SELECT jwt_public.current_user_id();
|
|
|
93
92
|
|
|
94
93
|
**JWT Claim:** `jwt.claims.user_id`
|
|
95
94
|
|
|
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
|
-
|
|
108
95
|
### jwt_public.current_ip_address()
|
|
109
96
|
Extracts the client's IP address from JWT claims.
|
|
110
97
|
|
|
@@ -151,9 +138,6 @@ JWT claims are set as PostgreSQL session variables, typically by your authentica
|
|
|
151
138
|
-- Set user ID claim
|
|
152
139
|
SELECT set_config('jwt.claims.user_id', 'user-uuid-here', false);
|
|
153
140
|
|
|
154
|
-
-- Set group IDs claim
|
|
155
|
-
SELECT set_config('jwt.claims.group_ids', '{uuid1,uuid2,uuid3}', false);
|
|
156
|
-
|
|
157
141
|
-- Set IP address claim
|
|
158
142
|
SELECT set_config('jwt.claims.ip_address', '192.168.1.1', false);
|
|
159
143
|
|
|
@@ -176,11 +160,6 @@ CREATE POLICY user_posts ON posts
|
|
|
176
160
|
TO authenticated
|
|
177
161
|
USING (user_id = jwt_public.current_user_id());
|
|
178
162
|
|
|
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()));
|
|
184
163
|
```
|
|
185
164
|
|
|
186
165
|
### Using Claims in Functions
|
|
@@ -195,18 +174,11 @@ BEGIN
|
|
|
195
174
|
INSERT INTO posts (user_id, title, content)
|
|
196
175
|
VALUES (jwt_public.current_user_id(), title, content)
|
|
197
176
|
RETURNING id INTO new_post_id;
|
|
198
|
-
|
|
177
|
+
|
|
199
178
|
RETURN new_post_id;
|
|
200
179
|
END;
|
|
201
180
|
$$ LANGUAGE plpgsql;
|
|
202
181
|
|
|
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;
|
|
210
182
|
```
|
|
211
183
|
|
|
212
184
|
### Audit Logging with JWT Claims
|
|
@@ -279,6 +251,30 @@ SELECT * FROM status_public.steps_required('newbie');
|
|
|
279
251
|
-- Uses jwt_public.current_user_id() internally
|
|
280
252
|
```
|
|
281
253
|
|
|
254
|
+
### With PGPM roles
|
|
255
|
+
|
|
256
|
+
Ensure the standard roles exist (pgpm admin-users bootstrap), then combine JWT claims with role-based access:
|
|
257
|
+
|
|
258
|
+
```sql
|
|
259
|
+
-- Set role based on JWT claim
|
|
260
|
+
CREATE FUNCTION set_user_role()
|
|
261
|
+
RETURNS void AS $$
|
|
262
|
+
DECLARE
|
|
263
|
+
user_role text;
|
|
264
|
+
BEGIN
|
|
265
|
+
user_role := current_setting('jwt.claims.role', true);
|
|
266
|
+
|
|
267
|
+
IF user_role = 'admin' THEN
|
|
268
|
+
SET LOCAL ROLE administrator;
|
|
269
|
+
ELSIF user_role = 'user' THEN
|
|
270
|
+
SET LOCAL ROLE authenticated;
|
|
271
|
+
ELSE
|
|
272
|
+
SET LOCAL ROLE anonymous;
|
|
273
|
+
END IF;
|
|
274
|
+
END;
|
|
275
|
+
$$ LANGUAGE plpgsql;
|
|
276
|
+
```
|
|
277
|
+
|
|
282
278
|
## Error Handling
|
|
283
279
|
|
|
284
280
|
All functions include error handling for invalid claim values:
|
|
@@ -287,10 +283,6 @@ All functions include error handling for invalid claim values:
|
|
|
287
283
|
-- If jwt.claims.user_id is not a valid UUID
|
|
288
284
|
SELECT jwt_public.current_user_id();
|
|
289
285
|
-- Returns NULL and raises NOTICE: 'Invalid UUID value'
|
|
290
|
-
|
|
291
|
-
-- If jwt.claims.group_ids is not a valid UUID array
|
|
292
|
-
SELECT jwt_public.current_group_ids();
|
|
293
|
-
-- Returns empty array [] and raises NOTICE: 'Invalid UUID value'
|
|
294
286
|
```
|
|
295
287
|
|
|
296
288
|
## Security Considerations
|
|
@@ -19,16 +19,6 @@ exports[`get values 3`] = `
|
|
|
19
19
|
`;
|
|
20
20
|
|
|
21
21
|
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`] = `
|
|
32
22
|
{
|
|
33
23
|
"user_id": "b9d22af1-62c7-43a5-b8c4-50630bbd4962",
|
|
34
24
|
}
|
package/__tests__/jwt.test.ts
CHANGED
|
@@ -5,12 +5,7 @@ let teardown: () => Promise<void>;
|
|
|
5
5
|
|
|
6
6
|
const jwt = {
|
|
7
7
|
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'
|
|
14
9
|
};
|
|
15
10
|
|
|
16
11
|
beforeAll(async () => {
|
|
@@ -28,15 +23,13 @@ it('get values', async () => {
|
|
|
28
23
|
set_config('jwt.claims.user_agent', $1, true),
|
|
29
24
|
set_config('jwt.claims.ip_address', $2, true),
|
|
30
25
|
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)
|
|
33
27
|
`,
|
|
34
28
|
[
|
|
35
29
|
'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',
|
|
36
30
|
'127.0.0.1',
|
|
37
31
|
jwt.database_id,
|
|
38
|
-
jwt.user_id
|
|
39
|
-
`{${jwt.group_ids.join(',')}}`
|
|
32
|
+
jwt.user_id
|
|
40
33
|
]
|
|
41
34
|
);
|
|
42
35
|
|
|
@@ -49,9 +42,6 @@ it('get values', async () => {
|
|
|
49
42
|
const { database_id } = await pg.one(
|
|
50
43
|
`select jwt_private.current_database_id() as database_id`
|
|
51
44
|
);
|
|
52
|
-
const { group_ids } = await pg.one(
|
|
53
|
-
`select jwt_public.current_group_ids() as group_ids`
|
|
54
|
-
);
|
|
55
45
|
const { user_id } = await pg.one(
|
|
56
46
|
`select jwt_public.current_user_id() as user_id`
|
|
57
47
|
);
|
|
@@ -60,6 +50,5 @@ it('get values', async () => {
|
|
|
60
50
|
expect({ user_agent }).toMatchSnapshot();
|
|
61
51
|
expect({ ip_address }).toMatchSnapshot();
|
|
62
52
|
expect({ database_id }).toMatchSnapshot();
|
|
63
|
-
expect({ group_ids }).toMatchSnapshot();
|
|
64
53
|
expect({ user_id }).toMatchSnapshot();
|
|
65
54
|
});
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
-- Deploy schemas/ctx/procedures/ip_address to pg
|
|
2
|
+
-- Retrieves the client's IP address from JWT claims
|
|
2
3
|
|
|
3
4
|
-- requires: schemas/ctx/schema
|
|
4
5
|
|
|
5
6
|
BEGIN;
|
|
6
7
|
|
|
8
|
+
-- Returns the client's IP address from the JWT claims
|
|
9
|
+
-- Useful for logging, rate limiting, and geo-based features
|
|
7
10
|
CREATE FUNCTION ctx.ip_address()
|
|
8
11
|
RETURNS inet
|
|
9
12
|
AS $$
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
-- Deploy schemas/ctx/procedures/origin to pg
|
|
2
|
+
-- Retrieves the request origin from JWT claims
|
|
2
3
|
|
|
3
4
|
-- requires: schemas/ctx/schema
|
|
4
5
|
|
|
5
6
|
BEGIN;
|
|
6
7
|
|
|
8
|
+
-- Returns the request origin from the JWT claims
|
|
9
|
+
-- Used for CORS validation and origin-based access control
|
|
7
10
|
CREATE FUNCTION ctx.origin()
|
|
8
11
|
RETURNS origin
|
|
9
12
|
AS $$
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
-- Deploy schemas/ctx/procedures/security_definer to pg
|
|
2
|
+
-- Creates functions for security definer context checks
|
|
2
3
|
|
|
3
4
|
-- requires: schemas/ctx/schema
|
|
4
5
|
|
|
5
6
|
BEGIN;
|
|
6
7
|
|
|
8
|
+
-- Creates two helper functions for security definer context:
|
|
9
|
+
-- ctx.security_definer() - Returns the name of the security definer user
|
|
10
|
+
-- ctx.is_security_definer() - Returns true if current user is the security definer
|
|
11
|
+
-- These are useful for RLS policies that need to bypass checks for system operations
|
|
7
12
|
DO $LQLMIGRATION$
|
|
8
13
|
DECLARE
|
|
9
14
|
BEGIN
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-- Deploy schemas/ctx/procedures/uagent to pg
|
|
2
|
+
-- Retrieves the current user's agent string from JWT claims
|
|
3
|
+
|
|
4
|
+
-- requires: schemas/ctx/schema
|
|
5
|
+
|
|
6
|
+
BEGIN;
|
|
7
|
+
|
|
8
|
+
-- Returns the current user agent string from the JWT claims
|
|
9
|
+
-- This is a shorthand for jwt_public.current_user_agent()
|
|
10
|
+
CREATE FUNCTION ctx.uagent()
|
|
11
|
+
RETURNS text
|
|
12
|
+
AS $$
|
|
13
|
+
SELECT nullif(current_setting('jwt.claims.user_agent', true), '');
|
|
14
|
+
$$
|
|
15
|
+
LANGUAGE 'sql' STABLE;
|
|
16
|
+
|
|
17
|
+
COMMIT;
|
|
18
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-- Deploy schemas/ctx/procedures/uid to pg
|
|
2
|
+
-- Retrieves the current user's ID from JWT claims
|
|
3
|
+
|
|
4
|
+
-- requires: schemas/ctx/schema
|
|
5
|
+
|
|
6
|
+
BEGIN;
|
|
7
|
+
|
|
8
|
+
-- Returns the current user's UUID from the JWT claims
|
|
9
|
+
-- This is a shorthand for jwt_public.current_user_id()
|
|
10
|
+
CREATE FUNCTION ctx.uid()
|
|
11
|
+
RETURNS uuid
|
|
12
|
+
AS $$
|
|
13
|
+
SELECT nullif(current_setting('jwt.claims.user_id', true), '')::uuid;
|
|
14
|
+
$$
|
|
15
|
+
LANGUAGE 'sql' STABLE;
|
|
16
|
+
|
|
17
|
+
COMMIT;
|
|
18
|
+
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
-- Deploy schemas/jwt_private/procedures/current_database_id to pg
|
|
2
|
+
-- Retrieves the current database ID from JWT claims (private/internal use)
|
|
2
3
|
|
|
3
4
|
-- requires: schemas/jwt_private/schema
|
|
4
5
|
|
|
5
6
|
BEGIN;
|
|
6
7
|
|
|
8
|
+
-- Returns the current database UUID from the JWT claims
|
|
9
|
+
-- Used for multi-tenant database isolation
|
|
10
|
+
-- Returns NULL if the claim is not set or invalid
|
|
7
11
|
CREATE FUNCTION jwt_private.current_database_id()
|
|
8
12
|
RETURNS uuid
|
|
9
13
|
AS $$
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
-- Deploy schemas/jwt_private/procedures/current_token_id to pg
|
|
2
|
+
-- Retrieves the current JWT token ID from claims (private/internal use)
|
|
2
3
|
|
|
3
4
|
-- requires: schemas/jwt_private/schema
|
|
4
5
|
|
|
5
6
|
BEGIN;
|
|
6
7
|
|
|
8
|
+
-- Returns the current JWT token UUID from the claims
|
|
9
|
+
-- Used for token tracking, revocation, and audit logging
|
|
7
10
|
CREATE FUNCTION jwt_private.current_token_id()
|
|
8
11
|
RETURNS uuid
|
|
9
12
|
AS $$
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
-- Deploy schemas/jwt_public/procedures/current_ip_address to pg
|
|
2
|
+
-- Retrieves the client's IP address from JWT claims with validation
|
|
2
3
|
|
|
3
4
|
-- requires: schemas/jwt_public/schema
|
|
4
5
|
|
|
5
6
|
BEGIN;
|
|
6
7
|
|
|
8
|
+
-- Returns the client's IP address from the JWT claims
|
|
9
|
+
-- Includes error handling for invalid IP address values
|
|
10
|
+
-- Returns NULL if the claim is not set or invalid
|
|
7
11
|
CREATE FUNCTION jwt_public.current_ip_address()
|
|
8
12
|
RETURNS inet
|
|
9
13
|
AS $$
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
-- Deploy schemas/jwt_public/procedures/current_origin to pg
|
|
2
|
+
-- Retrieves the request origin from JWT claims
|
|
2
3
|
|
|
3
4
|
-- requires: schemas/jwt_public/schema
|
|
4
5
|
|
|
5
6
|
BEGIN;
|
|
6
7
|
|
|
8
|
+
-- Returns the request origin from the JWT claims
|
|
9
|
+
-- Used for CORS validation and origin-based access control
|
|
7
10
|
CREATE FUNCTION jwt_public.current_origin()
|
|
8
11
|
RETURNS origin
|
|
9
12
|
AS $$
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
-- Deploy schemas/jwt_public/procedures/current_user_agent to pg
|
|
2
|
+
-- Retrieves the client's user agent string from JWT claims with validation
|
|
2
3
|
|
|
3
4
|
-- requires: schemas/jwt_public/schema
|
|
4
5
|
|
|
5
6
|
BEGIN;
|
|
6
7
|
|
|
8
|
+
-- Returns the client's user agent string from the JWT claims
|
|
9
|
+
-- Includes error handling for invalid values
|
|
10
|
+
-- Returns NULL if the claim is not set or invalid
|
|
7
11
|
CREATE FUNCTION jwt_public.current_user_agent()
|
|
8
12
|
RETURNS text
|
|
9
13
|
AS $$
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
-- Deploy schemas/jwt_public/procedures/current_user_id to pg
|
|
2
|
+
-- Retrieves the current user's ID from JWT claims with validation
|
|
2
3
|
|
|
3
4
|
-- requires: schemas/jwt_public/schema
|
|
4
5
|
|
|
5
6
|
BEGIN;
|
|
6
7
|
|
|
8
|
+
-- Returns the current user's UUID from the JWT claims
|
|
9
|
+
-- Includes error handling for invalid UUID values
|
|
10
|
+
-- Returns NULL if the claim is not set or invalid
|
|
7
11
|
CREATE FUNCTION jwt_public.current_user_id()
|
|
8
12
|
RETURNS uuid
|
|
9
13
|
AS $$
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpm/jwt-claims",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.3",
|
|
4
4
|
"description": "JWT claim handling and validation functions",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
6
|
"contributors": [
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"pgpm": "^1.0.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@pgpm/types": "0.15.
|
|
28
|
-
"@pgpm/verify": "0.15.
|
|
27
|
+
"@pgpm/types": "0.15.3",
|
|
28
|
+
"@pgpm/verify": "0.15.3"
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"bugs": {
|
|
36
36
|
"url": "https://github.com/constructive-io/pgpm-modules/issues"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "187ed37f6b731132fe930acf5b5996b1e63ecca0"
|
|
39
39
|
}
|
package/pgpm-jwt-claims.control
CHANGED
package/pgpm.plan
CHANGED
|
@@ -5,15 +5,14 @@
|
|
|
5
5
|
schemas/ctx/schema 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/ctx/schema
|
|
6
6
|
schemas/ctx/procedures/ip_address [schemas/ctx/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/ctx/procedures/ip_address
|
|
7
7
|
schemas/ctx/procedures/origin [schemas/ctx/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/ctx/procedures/origin
|
|
8
|
-
schemas/ctx/procedures/
|
|
9
|
-
schemas/ctx/procedures/
|
|
8
|
+
schemas/ctx/procedures/uagent [schemas/ctx/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/ctx/procedures/uagent
|
|
9
|
+
schemas/ctx/procedures/uid [schemas/ctx/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/ctx/procedures/uid
|
|
10
10
|
schemas/ctx/procedures/security_definer [schemas/ctx/schema] 2021-04-20T04:04:08Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/ctx/procedures/security_definer
|
|
11
11
|
schemas/jwt_public/schema 2020-12-17T06:47:29Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_public/schema
|
|
12
12
|
schemas/jwt_public/procedures/current_user_id [schemas/jwt_public/schema] 2020-12-17T06:48:56Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_public/procedures/current_user_id
|
|
13
13
|
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
|
|
14
14
|
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
|
|
15
15
|
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
|
|
17
16
|
schemas/jwt_private/schema 2020-12-17T06:47:34Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_private/schema
|
|
18
17
|
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
|
|
19
18
|
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
|
|
@@ -14,11 +14,11 @@ CREATE FUNCTION ctx.origin() RETURNS origin AS $EOFCODE$
|
|
|
14
14
|
SELECT nullif(current_setting('jwt.claims.origin', true), '')::origin;
|
|
15
15
|
$EOFCODE$ LANGUAGE sql STABLE;
|
|
16
16
|
|
|
17
|
-
CREATE FUNCTION ctx.
|
|
17
|
+
CREATE FUNCTION ctx.uagent() RETURNS text AS $EOFCODE$
|
|
18
18
|
SELECT nullif(current_setting('jwt.claims.user_agent', true), '');
|
|
19
19
|
$EOFCODE$ LANGUAGE sql STABLE;
|
|
20
20
|
|
|
21
|
-
CREATE FUNCTION ctx.
|
|
21
|
+
CREATE FUNCTION ctx.uid() RETURNS uuid AS $EOFCODE$
|
|
22
22
|
SELECT nullif(current_setting('jwt.claims.user_id', true), '')::uuid;
|
|
23
23
|
$EOFCODE$ LANGUAGE sql STABLE;
|
|
24
24
|
|
|
@@ -111,26 +111,6 @@ CREATE FUNCTION jwt_public.current_origin() RETURNS origin AS $EOFCODE$
|
|
|
111
111
|
SELECT nullif(current_setting('jwt.claims.origin', true), '')::origin;
|
|
112
112
|
$EOFCODE$ LANGUAGE sql STABLE;
|
|
113
113
|
|
|
114
|
-
CREATE FUNCTION jwt_public.current_group_ids() RETURNS uuid[] AS $EOFCODE$
|
|
115
|
-
DECLARE
|
|
116
|
-
v_identifier_ids uuid[];
|
|
117
|
-
BEGIN
|
|
118
|
-
IF current_setting('jwt.claims.group_ids', TRUE)
|
|
119
|
-
IS NOT NULL THEN
|
|
120
|
-
BEGIN
|
|
121
|
-
v_identifier_ids = current_setting('jwt.claims.group_ids', TRUE)::uuid[];
|
|
122
|
-
EXCEPTION
|
|
123
|
-
WHEN OTHERS THEN
|
|
124
|
-
RAISE NOTICE 'Invalid UUID value';
|
|
125
|
-
RETURN ARRAY[]::uuid[];
|
|
126
|
-
END;
|
|
127
|
-
RETURN v_identifier_ids;
|
|
128
|
-
ELSE
|
|
129
|
-
RETURN ARRAY[]::uuid[];
|
|
130
|
-
END IF;
|
|
131
|
-
END;
|
|
132
|
-
$EOFCODE$ LANGUAGE plpgsql STABLE;
|
|
133
|
-
|
|
134
114
|
CREATE SCHEMA jwt_private;
|
|
135
115
|
|
|
136
116
|
GRANT USAGE ON SCHEMA jwt_private TO authenticated, anonymous;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
-- Deploy schemas/ctx/procedures/user_agent to pg
|
|
2
|
-
|
|
3
|
-
-- requires: schemas/ctx/schema
|
|
4
|
-
|
|
5
|
-
BEGIN;
|
|
6
|
-
|
|
7
|
-
CREATE FUNCTION ctx.user_agent()
|
|
8
|
-
RETURNS text
|
|
9
|
-
AS $$
|
|
10
|
-
SELECT nullif(current_setting('jwt.claims.user_agent', true), '');
|
|
11
|
-
$$
|
|
12
|
-
LANGUAGE 'sql' STABLE;
|
|
13
|
-
|
|
14
|
-
COMMIT;
|
|
15
|
-
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
-- Deploy schemas/ctx/procedures/user_id to pg
|
|
2
|
-
|
|
3
|
-
-- requires: schemas/ctx/schema
|
|
4
|
-
|
|
5
|
-
BEGIN;
|
|
6
|
-
|
|
7
|
-
CREATE FUNCTION ctx.user_id()
|
|
8
|
-
RETURNS uuid
|
|
9
|
-
AS $$
|
|
10
|
-
SELECT nullif(current_setting('jwt.claims.user_id', true), '')::uuid;
|
|
11
|
-
$$
|
|
12
|
-
LANGUAGE 'sql' STABLE;
|
|
13
|
-
|
|
14
|
-
COMMIT;
|
|
15
|
-
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
-- Deploy schemas/jwt_public/procedures/current_group_ids to pg
|
|
2
|
-
|
|
3
|
-
-- requires: schemas/jwt_public/schema
|
|
4
|
-
|
|
5
|
-
BEGIN;
|
|
6
|
-
|
|
7
|
-
CREATE FUNCTION jwt_public.current_group_ids()
|
|
8
|
-
RETURNS uuid[]
|
|
9
|
-
AS $$
|
|
10
|
-
DECLARE
|
|
11
|
-
v_identifier_ids uuid[];
|
|
12
|
-
BEGIN
|
|
13
|
-
IF current_setting('jwt.claims.group_ids', TRUE)
|
|
14
|
-
IS NOT NULL THEN
|
|
15
|
-
BEGIN
|
|
16
|
-
v_identifier_ids = current_setting('jwt.claims.group_ids', TRUE)::uuid[];
|
|
17
|
-
EXCEPTION
|
|
18
|
-
WHEN OTHERS THEN
|
|
19
|
-
RAISE NOTICE 'Invalid UUID value';
|
|
20
|
-
RETURN ARRAY[]::uuid[];
|
|
21
|
-
END;
|
|
22
|
-
RETURN v_identifier_ids;
|
|
23
|
-
ELSE
|
|
24
|
-
RETURN ARRAY[]::uuid[];
|
|
25
|
-
END IF;
|
|
26
|
-
END;
|
|
27
|
-
$$
|
|
28
|
-
LANGUAGE 'plpgsql' STABLE;
|
|
29
|
-
|
|
30
|
-
COMMIT;
|