@pgpm/jwt-claims 0.4.0

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.
Files changed (32) hide show
  1. package/LICENSE +22 -0
  2. package/Makefile +6 -0
  3. package/README.md +5 -0
  4. package/__tests__/__snapshots__/jwt.test.ts.snap +35 -0
  5. package/__tests__/jwt.test.ts +65 -0
  6. package/deploy/schemas/jwt_private/procedures/current_database_id.sql +30 -0
  7. package/deploy/schemas/jwt_private/schema.sql +15 -0
  8. package/deploy/schemas/jwt_public/procedures/current_group_ids.sql +30 -0
  9. package/deploy/schemas/jwt_public/procedures/current_ip_address.sql +30 -0
  10. package/deploy/schemas/jwt_public/procedures/current_user_agent.sql +30 -0
  11. package/deploy/schemas/jwt_public/procedures/current_user_id.sql +30 -0
  12. package/deploy/schemas/jwt_public/schema.sql +15 -0
  13. package/jest.config.js +15 -0
  14. package/launchql-jwt-claims.control +8 -0
  15. package/launchql.plan +11 -0
  16. package/package.json +29 -0
  17. package/revert/schemas/jwt_private/procedures/current_database_id.sql +7 -0
  18. package/revert/schemas/jwt_private/schema.sql +7 -0
  19. package/revert/schemas/jwt_public/procedures/current_group_ids.sql +7 -0
  20. package/revert/schemas/jwt_public/procedures/current_ip_address.sql +7 -0
  21. package/revert/schemas/jwt_public/procedures/current_user_agent.sql +7 -0
  22. package/revert/schemas/jwt_public/procedures/current_user_id.sql +7 -0
  23. package/revert/schemas/jwt_public/schema.sql +7 -0
  24. package/sqitch.plan +13 -0
  25. package/sql/launchql-jwt-claims--0.4.6.sql +114 -0
  26. package/verify/schemas/jwt_private/procedures/current_database_id.sql +7 -0
  27. package/verify/schemas/jwt_private/schema.sql +7 -0
  28. package/verify/schemas/jwt_public/procedures/current_group_ids.sql +7 -0
  29. package/verify/schemas/jwt_public/procedures/current_ip_address.sql +7 -0
  30. package/verify/schemas/jwt_public/procedures/current_user_agent.sql +7 -0
  31. package/verify/schemas/jwt_public/procedures/current_user_id.sql +7 -0
  32. package/verify/schemas/jwt_public/schema.sql +7 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
4
+ Copyright (c) 2025 Interweb, Inc.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/Makefile ADDED
@@ -0,0 +1,6 @@
1
+ EXTENSION = launchql-jwt-claims
2
+ DATA = sql/launchql-jwt-claims--0.4.6.sql
3
+
4
+ PG_CONFIG = pg_config
5
+ PGXS := $(shell $(PG_CONFIG) --pgxs)
6
+ include $(PGXS)
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @pgpm/jwt-claims
2
+
3
+ JWT claim handling and validation functions.
4
+
5
+ Provides functions for processing JWT claims, validating tokens, and extracting user information from JWT payloads.
@@ -0,0 +1,35 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`get values 1`] = `
4
+ {
5
+ "user_agent": "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",
6
+ }
7
+ `;
8
+
9
+ exports[`get values 2`] = `
10
+ {
11
+ "ip_address": "127.0.0.1",
12
+ }
13
+ `;
14
+
15
+ exports[`get values 3`] = `
16
+ {
17
+ "database_id": "44744c94-93cf-425a-b524-ce6f1466e327",
18
+ }
19
+ `;
20
+
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
+ {
33
+ "user_id": "b9d22af1-62c7-43a5-b8c4-50630bbd4962",
34
+ }
35
+ `;
@@ -0,0 +1,65 @@
1
+ import { getConnections, PgTestClient } from 'pgsql-test';
2
+
3
+ let pg: PgTestClient;
4
+ let teardown: () => Promise<void>;
5
+
6
+ const jwt = {
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
+ ]
14
+ };
15
+
16
+ beforeAll(async () => {
17
+ ({ pg, teardown } = await getConnections());
18
+ });
19
+
20
+ afterAll(async () => {
21
+ await teardown?.();
22
+ });
23
+
24
+ it('get values', async () => {
25
+ await pg.any(`BEGIN`);
26
+ await pg.any(
27
+ `SELECT
28
+ set_config('jwt.claims.user_agent', $1, true),
29
+ set_config('jwt.claims.ip_address', $2, true),
30
+ 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)
33
+ `,
34
+ [
35
+ '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
+ '127.0.0.1',
37
+ jwt.database_id,
38
+ jwt.user_id,
39
+ `{${jwt.group_ids.join(',')}}`
40
+ ]
41
+ );
42
+
43
+ const { user_agent } = await pg.one(
44
+ `select jwt_public.current_user_agent() as user_agent`
45
+ );
46
+ const { ip_address } = await pg.one(
47
+ `select jwt_public.current_ip_address() as ip_address`
48
+ );
49
+ const { database_id } = await pg.one(
50
+ `select jwt_private.current_database_id() as database_id`
51
+ );
52
+ const { group_ids } = await pg.one(
53
+ `select jwt_public.current_group_ids() as group_ids`
54
+ );
55
+ const { user_id } = await pg.one(
56
+ `select jwt_public.current_user_id() as user_id`
57
+ );
58
+ await pg.any(`ROLLBACK`);
59
+
60
+ expect({ user_agent }).toMatchSnapshot();
61
+ expect({ ip_address }).toMatchSnapshot();
62
+ expect({ database_id }).toMatchSnapshot();
63
+ expect({ group_ids }).toMatchSnapshot();
64
+ expect({ user_id }).toMatchSnapshot();
65
+ });
@@ -0,0 +1,30 @@
1
+ -- Deploy schemas/jwt_private/procedures/current_database_id to pg
2
+
3
+ -- requires: schemas/jwt_private/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE FUNCTION jwt_private.current_database_id()
8
+ RETURNS uuid
9
+ AS $$
10
+ DECLARE
11
+ v_identifier_id uuid;
12
+ BEGIN
13
+ IF current_setting('jwt.claims.database_id', TRUE)
14
+ IS NOT NULL THEN
15
+ BEGIN
16
+ v_identifier_id = current_setting('jwt.claims.database_id', TRUE)::uuid;
17
+ EXCEPTION
18
+ WHEN OTHERS THEN
19
+ RAISE NOTICE 'Invalid UUID value';
20
+ RETURN NULL;
21
+ END;
22
+ RETURN v_identifier_id;
23
+ ELSE
24
+ RETURN NULL;
25
+ END IF;
26
+ END;
27
+ $$
28
+ LANGUAGE 'plpgsql' STABLE;
29
+
30
+ COMMIT;
@@ -0,0 +1,15 @@
1
+ -- Deploy schemas/jwt_private/schema to pg
2
+
3
+
4
+ BEGIN;
5
+
6
+ CREATE SCHEMA jwt_private;
7
+
8
+ GRANT USAGE ON SCHEMA jwt_private
9
+ TO authenticated, anonymous;
10
+
11
+ ALTER DEFAULT PRIVILEGES IN SCHEMA jwt_private
12
+ GRANT EXECUTE ON FUNCTIONS
13
+ TO authenticated;
14
+
15
+ COMMIT;
@@ -0,0 +1,30 @@
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;
@@ -0,0 +1,30 @@
1
+ -- Deploy schemas/jwt_public/procedures/current_ip_address to pg
2
+
3
+ -- requires: schemas/jwt_public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE FUNCTION jwt_public.current_ip_address()
8
+ RETURNS inet
9
+ AS $$
10
+ DECLARE
11
+ v_ip_addr inet;
12
+ BEGIN
13
+ IF current_setting('jwt.claims.ip_address', TRUE)
14
+ IS NOT NULL THEN
15
+ BEGIN
16
+ v_ip_addr = trim(current_setting('jwt.claims.ip_address', TRUE))::inet;
17
+ EXCEPTION
18
+ WHEN OTHERS THEN
19
+ RAISE NOTICE 'Invalid IP';
20
+ RETURN NULL;
21
+ END;
22
+ RETURN v_ip_addr;
23
+ ELSE
24
+ RETURN NULL;
25
+ END IF;
26
+ END;
27
+ $$
28
+ LANGUAGE 'plpgsql' STABLE;
29
+
30
+ COMMIT;
@@ -0,0 +1,30 @@
1
+ -- Deploy schemas/jwt_public/procedures/current_user_agent to pg
2
+
3
+ -- requires: schemas/jwt_public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE FUNCTION jwt_public.current_user_agent()
8
+ RETURNS text
9
+ AS $$
10
+ DECLARE
11
+ v_uagent text;
12
+ BEGIN
13
+ IF current_setting('jwt.claims.user_agent', TRUE)
14
+ IS NOT NULL THEN
15
+ BEGIN
16
+ v_uagent = current_setting('jwt.claims.user_agent', TRUE);
17
+ EXCEPTION
18
+ WHEN OTHERS THEN
19
+ RAISE NOTICE 'Invalid UserAgent';
20
+ RETURN NULL;
21
+ END;
22
+ RETURN v_uagent;
23
+ ELSE
24
+ RETURN NULL;
25
+ END IF;
26
+ END;
27
+ $$
28
+ LANGUAGE 'plpgsql' STABLE;
29
+
30
+ COMMIT;
@@ -0,0 +1,30 @@
1
+ -- Deploy schemas/jwt_public/procedures/current_user_id to pg
2
+
3
+ -- requires: schemas/jwt_public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE FUNCTION jwt_public.current_user_id()
8
+ RETURNS uuid
9
+ AS $$
10
+ DECLARE
11
+ v_identifier_id uuid;
12
+ BEGIN
13
+ IF current_setting('jwt.claims.user_id', TRUE)
14
+ IS NOT NULL THEN
15
+ BEGIN
16
+ v_identifier_id = current_setting('jwt.claims.user_id', TRUE)::uuid;
17
+ EXCEPTION
18
+ WHEN OTHERS THEN
19
+ RAISE NOTICE 'Invalid UUID value';
20
+ RETURN NULL;
21
+ END;
22
+ RETURN v_identifier_id;
23
+ ELSE
24
+ RETURN NULL;
25
+ END IF;
26
+ END;
27
+ $$
28
+ LANGUAGE 'plpgsql' STABLE;
29
+
30
+ COMMIT;
@@ -0,0 +1,15 @@
1
+ -- Deploy schemas/jwt_public/schema to pg
2
+
3
+
4
+ BEGIN;
5
+
6
+ CREATE SCHEMA jwt_public;
7
+
8
+ GRANT USAGE ON SCHEMA jwt_public
9
+ TO authenticated, anonymous;
10
+
11
+ ALTER DEFAULT PRIVILEGES IN SCHEMA jwt_public
12
+ GRANT EXECUTE ON FUNCTIONS
13
+ TO authenticated;
14
+
15
+ COMMIT;
package/jest.config.js ADDED
@@ -0,0 +1,15 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+
6
+ // Match both __tests__ and colocated test files
7
+ testMatch: ['**/?(*.)+(test|spec).{ts,tsx,js,jsx}'],
8
+
9
+ // Ignore build artifacts and type declarations
10
+ testPathIgnorePatterns: ['/dist/', '\\.d\\.ts$'],
11
+ modulePathIgnorePatterns: ['<rootDir>/dist/'],
12
+ watchPathIgnorePatterns: ['/dist/'],
13
+
14
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
15
+ };
@@ -0,0 +1,8 @@
1
+ # launchql-jwt-claims extension
2
+ comment = 'launchql-jwt-claims extension'
3
+ default_version = '0.4.6'
4
+ module_pathname = '$libdir/launchql-jwt-claims'
5
+ requires = 'plpgsql,uuid-ossp,launchql-verify'
6
+ relocatable = false
7
+ superuser = false
8
+
package/launchql.plan ADDED
@@ -0,0 +1,11 @@
1
+ %syntax-version=1.0.0
2
+ %project=launchql-jwt-claims
3
+ %uri=launchql-jwt-claims
4
+
5
+ schemas/jwt_public/schema 2020-12-17T06:47:29Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_public/schema
6
+ schemas/jwt_private/schema 2020-12-17T06:47:34Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_private/schema
7
+ 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
8
+ 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
9
+ 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
10
+ 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
11
+ 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
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@pgpm/jwt-claims",
3
+ "version": "0.4.0",
4
+ "description": "JWT claim handling and validation functions",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "scripts": {
9
+ "bundle": "lql package",
10
+ "test": "jest",
11
+ "test:watch": "jest --watch"
12
+ },
13
+ "devDependencies": {
14
+ "@launchql/cli": "^4.9.0"
15
+ },
16
+ "dependencies": {
17
+ "@pgpm/types": "0.4.0",
18
+ "@pgpm/verify": "0.4.0"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/launchql/extensions"
23
+ },
24
+ "homepage": "https://github.com/launchql/extensions",
25
+ "bugs": {
26
+ "url": "https://github.com/launchql/extensions/issues"
27
+ },
28
+ "gitHead": "cc9f52a335caa6e21ee7751b04b77c84ce6cb809"
29
+ }
@@ -0,0 +1,7 @@
1
+ -- Revert schemas/jwt_private/procedures/current_database_id from pg
2
+
3
+ BEGIN;
4
+
5
+ DROP FUNCTION jwt_private.current_database_id;
6
+
7
+ COMMIT;
@@ -0,0 +1,7 @@
1
+ -- Revert schemas/jwt_private/schema from pg
2
+
3
+ BEGIN;
4
+
5
+ DROP SCHEMA jwt_private;
6
+
7
+ COMMIT;
@@ -0,0 +1,7 @@
1
+ -- Revert schemas/jwt_public/procedures/current_group_ids from pg
2
+
3
+ BEGIN;
4
+
5
+ DROP FUNCTION jwt_public.current_group_ids;
6
+
7
+ COMMIT;
@@ -0,0 +1,7 @@
1
+ -- Revert schemas/jwt_public/procedures/current_ip_address from pg
2
+
3
+ BEGIN;
4
+
5
+ DROP FUNCTION jwt_public.current_ip_address;
6
+
7
+ COMMIT;
@@ -0,0 +1,7 @@
1
+ -- Revert schemas/jwt_public/procedures/current_user_agent from pg
2
+
3
+ BEGIN;
4
+
5
+ DROP FUNCTION jwt_public.current_user_agent;
6
+
7
+ COMMIT;
@@ -0,0 +1,7 @@
1
+ -- Revert schemas/jwt_public/procedures/current_user_id from pg
2
+
3
+ BEGIN;
4
+
5
+ DROP FUNCTION jwt_public.current_user_id;
6
+
7
+ COMMIT;
@@ -0,0 +1,7 @@
1
+ -- Revert schemas/jwt_public/schema from pg
2
+
3
+ BEGIN;
4
+
5
+ DROP SCHEMA jwt_public;
6
+
7
+ COMMIT;
package/sqitch.plan ADDED
@@ -0,0 +1,13 @@
1
+ %syntax-version=1.0.0
2
+ %project=launchql-jwt-claims
3
+ %uri=launchql-jwt-claims
4
+
5
+ schemas/jwt_public/schema 2020-12-17T06:47:29Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_public/schema
6
+ schemas/jwt_private/schema 2020-12-17T06:47:34Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_private/schema
7
+ 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
8
+ 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
9
+ 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
10
+ 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
11
+ 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
12
+
13
+ [This file mirrors launchql.plan for harness compatibility during tests and local deploys. Do not hand-edit one without the other.]
@@ -0,0 +1,114 @@
1
+ \echo Use "CREATE EXTENSION launchql-jwt-claims" to load this file. \quit
2
+ CREATE SCHEMA jwt_public;
3
+
4
+ GRANT USAGE ON SCHEMA jwt_public TO authenticated, anonymous;
5
+
6
+ ALTER DEFAULT PRIVILEGES IN SCHEMA jwt_public
7
+ GRANT EXECUTE ON FUNCTIONS TO authenticated;
8
+
9
+ CREATE SCHEMA jwt_private;
10
+
11
+ GRANT USAGE ON SCHEMA jwt_private TO authenticated, anonymous;
12
+
13
+ ALTER DEFAULT PRIVILEGES IN SCHEMA jwt_private
14
+ GRANT EXECUTE ON FUNCTIONS TO authenticated;
15
+
16
+ CREATE FUNCTION jwt_public.current_user_id() RETURNS uuid AS $EOFCODE$
17
+ DECLARE
18
+ v_identifier_id uuid;
19
+ BEGIN
20
+ IF current_setting('jwt.claims.user_id', TRUE)
21
+ IS NOT NULL THEN
22
+ BEGIN
23
+ v_identifier_id = current_setting('jwt.claims.user_id', TRUE)::uuid;
24
+ EXCEPTION
25
+ WHEN OTHERS THEN
26
+ RAISE NOTICE 'Invalid UUID value';
27
+ RETURN NULL;
28
+ END;
29
+ RETURN v_identifier_id;
30
+ ELSE
31
+ RETURN NULL;
32
+ END IF;
33
+ END;
34
+ $EOFCODE$ LANGUAGE plpgsql STABLE;
35
+
36
+ CREATE FUNCTION jwt_public.current_ip_address() RETURNS inet AS $EOFCODE$
37
+ DECLARE
38
+ v_ip_addr inet;
39
+ BEGIN
40
+ IF current_setting('jwt.claims.ip_address', TRUE)
41
+ IS NOT NULL THEN
42
+ BEGIN
43
+ v_ip_addr = trim(current_setting('jwt.claims.ip_address', TRUE))::inet;
44
+ EXCEPTION
45
+ WHEN OTHERS THEN
46
+ RAISE NOTICE 'Invalid IP';
47
+ RETURN NULL;
48
+ END;
49
+ RETURN v_ip_addr;
50
+ ELSE
51
+ RETURN NULL;
52
+ END IF;
53
+ END;
54
+ $EOFCODE$ LANGUAGE plpgsql STABLE;
55
+
56
+ CREATE FUNCTION jwt_public.current_user_agent() RETURNS text AS $EOFCODE$
57
+ DECLARE
58
+ v_uagent text;
59
+ BEGIN
60
+ IF current_setting('jwt.claims.user_agent', TRUE)
61
+ IS NOT NULL THEN
62
+ BEGIN
63
+ v_uagent = current_setting('jwt.claims.user_agent', TRUE);
64
+ EXCEPTION
65
+ WHEN OTHERS THEN
66
+ RAISE NOTICE 'Invalid UserAgent';
67
+ RETURN NULL;
68
+ END;
69
+ RETURN v_uagent;
70
+ ELSE
71
+ RETURN NULL;
72
+ END IF;
73
+ END;
74
+ $EOFCODE$ LANGUAGE plpgsql STABLE;
75
+
76
+ CREATE FUNCTION jwt_private.current_database_id() RETURNS uuid AS $EOFCODE$
77
+ DECLARE
78
+ v_identifier_id uuid;
79
+ BEGIN
80
+ IF current_setting('jwt.claims.database_id', TRUE)
81
+ IS NOT NULL THEN
82
+ BEGIN
83
+ v_identifier_id = current_setting('jwt.claims.database_id', TRUE)::uuid;
84
+ EXCEPTION
85
+ WHEN OTHERS THEN
86
+ RAISE NOTICE 'Invalid UUID value';
87
+ RETURN NULL;
88
+ END;
89
+ RETURN v_identifier_id;
90
+ ELSE
91
+ RETURN NULL;
92
+ END IF;
93
+ END;
94
+ $EOFCODE$ LANGUAGE plpgsql STABLE;
95
+
96
+ CREATE FUNCTION jwt_public.current_group_ids() RETURNS uuid[] AS $EOFCODE$
97
+ DECLARE
98
+ v_identifier_ids uuid[];
99
+ BEGIN
100
+ IF current_setting('jwt.claims.group_ids', TRUE)
101
+ IS NOT NULL THEN
102
+ BEGIN
103
+ v_identifier_ids = current_setting('jwt.claims.group_ids', TRUE)::uuid[];
104
+ EXCEPTION
105
+ WHEN OTHERS THEN
106
+ RAISE NOTICE 'Invalid UUID value';
107
+ RETURN ARRAY[]::uuid[];
108
+ END;
109
+ RETURN v_identifier_ids;
110
+ ELSE
111
+ RETURN ARRAY[]::uuid[];
112
+ END IF;
113
+ END;
114
+ $EOFCODE$ LANGUAGE plpgsql STABLE;
@@ -0,0 +1,7 @@
1
+ -- Verify schemas/jwt_private/procedures/current_database_id on pg
2
+
3
+ BEGIN;
4
+
5
+ SELECT verify_function ('jwt_private.current_database_id');
6
+
7
+ ROLLBACK;
@@ -0,0 +1,7 @@
1
+ -- Verify schemas/jwt_private/schema on pg
2
+
3
+ BEGIN;
4
+
5
+ SELECT verify_schema ('jwt_private');
6
+
7
+ ROLLBACK;
@@ -0,0 +1,7 @@
1
+ -- Verify schemas/jwt_public/procedures/current_group_ids on pg
2
+
3
+ BEGIN;
4
+
5
+ SELECT verify_function ('jwt_public.current_group_ids');
6
+
7
+ ROLLBACK;
@@ -0,0 +1,7 @@
1
+ -- Verify schemas/jwt_public/procedures/current_ip_address on pg
2
+
3
+ BEGIN;
4
+
5
+ SELECT verify_function ('jwt_public.current_ip_address');
6
+
7
+ ROLLBACK;
@@ -0,0 +1,7 @@
1
+ -- Verify schemas/jwt_public/procedures/current_user_agent on pg
2
+
3
+ BEGIN;
4
+
5
+ SELECT verify_function ('jwt_public.current_user_agent');
6
+
7
+ ROLLBACK;
@@ -0,0 +1,7 @@
1
+ -- Verify schemas/jwt_public/procedures/current_user_id on pg
2
+
3
+ BEGIN;
4
+
5
+ SELECT verify_function ('jwt_public.current_user_id');
6
+
7
+ ROLLBACK;
@@ -0,0 +1,7 @@
1
+ -- Verify schemas/jwt_public/schema on pg
2
+
3
+ BEGIN;
4
+
5
+ SELECT verify_schema ('jwt_public');
6
+
7
+ ROLLBACK;