pgjwt
pgjwt
pgjwt : JSON Web Token API for Postgresql
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4160 | pgjwt | pgjwt | 0.2.0 | UTIL | MIT | SQL |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-- | No | Yes | No | Yes | no | no |
| Relationships | |
|---|---|
| Requires | pgcrypto |
| See Also | http pg_net pg_curl pgjq sparql pgcrypto gzip bzip |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.2.0 | 18 17 16 15 14 | pgjwt | pgcrypto |
| 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 / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
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/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Create this extension with:
CREATE EXTENSION pgjwt CASCADE; -- requires pgcryptoUsage
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:
| header | payload | valid |
|---|---|---|
{"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