pgjwt

pgjwt : JSON Web Token API for Postgresql

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4160
pgjwt
pgjwt
0.2.0
UTIL
MIT
SQL
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d--
No
Yes
No
Yes
no
no
Relationships
Requires
pgcrypto
See Also
http
pg_net
pg_curl
pgjq
sparql
pgcrypto
gzip
bzip

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
0.2.0
18
17
16
15
14
pgjwtpgcrypto
RPM
PIGSTY
0.2.0
18
17
16
15
14
pgjwt_$v-
DEB
PIGSTY
0.2.0
18
17
16
15
14
postgresql-$v-pgjwt-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
el8.aarch64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
el9.x86_64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
el9.aarch64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
el10.x86_64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
el10.aarch64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
d12.x86_64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
d12.aarch64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
d13.x86_64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
d13.aarch64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
u22.x86_64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
u22.aarch64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
u24.x86_64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
u24.aarch64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0

Source

pig build pkg pgjwt;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pgjwt;		# install via package name, for the active PG version

pig install pgjwt -v 18;   # install for PG 18
pig install pgjwt -v 17;   # install for PG 17
pig install pgjwt -v 16;   # install for PG 16
pig install pgjwt -v 15;   # install for PG 15
pig install pgjwt -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pgjwt CASCADE; -- requires pgcrypto

Usage

pgjwt: JSON Web Tokens for PostgreSQL

Requires the pgcrypto extension.

Sign a Token

SELECT sign(
    '{"sub":"1234567890","name":"John Doe","admin":true}',
    'secret'
);

Returns a JWT string like: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOi...

Verify a Token

SELECT * FROM verify(
    'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ',
    'secret'
);

Returns:

headerpayloadvalid
{"alg":"HS256","typ":"JWT"}{"sub":"1234567890","name":"John Doe","admin":true}t

Algorithm Selection

sign() and verify() accept an optional third argument for the algorithm: 'HS256' (default), 'HS384', or 'HS512'.

SELECT sign('{"data":"value"}', 'secret', 'HS384');
Last updated on