pgjwt

JSON Web Token API for Postgresql

Overview

PackageVersionCategoryLicenseLanguage
pgjwt0.2.0UTILMITSQL
IDExtensionBinLibLoadCreateTrustRelocSchema
4160pgjwtNoYesNoYesYesNo-
Relatedpgcrypto http pg_net pg_curl pgjq sparql pgcrypto gzip bzip

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.2.01817161514pgjwtpgcrypto
RPMPIGSTY0.2.01817161514pgjwt_$v-
DEBPIGSTY0.2.01817161514postgresql-$v-pgjwt-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
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

Build

You can build the RPM / DEB packages for pgjwt using pig build:

pig build pkg pgjwt         # build RPM / DEB packages

Install

You can install pgjwt directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

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

Install the extension using pig or apt/yum/dnf:

pig install pgjwt;          # Install for current active PG version
pig ext install -y pgjwt -v 18  # PG 18
pig ext install -y pgjwt -v 17  # PG 17
pig ext install -y pgjwt -v 16  # PG 16
pig ext install -y pgjwt -v 15  # PG 15
pig ext install -y pgjwt -v 14  # PG 14
dnf install -y pgjwt_18       # PG 18
dnf install -y pgjwt_17       # PG 17
dnf install -y pgjwt_16       # PG 16
dnf install -y pgjwt_15       # PG 15
dnf install -y pgjwt_14       # PG 14
apt install -y postgresql-18-pgjwt   # PG 18
apt install -y postgresql-17-pgjwt   # PG 17
apt install -y postgresql-16-pgjwt   # PG 16
apt install -y postgresql-15-pgjwt   # PG 15
apt install -y postgresql-14-pgjwt   # PG 14

Create Extension:

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 Modified 2026-03-12: add pg extension catalog (95749bf)