pg_session_jwt
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_session_jwt | 0.5.0 | SEC | Apache-2.0 | Rust |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 7060 | pg_session_jwt | No | Yes | No | Yes | Yes | No | auth |
| Related | pg_oidc_validator pgjwt login_hook oidc_validator pg_auth_mon pgsodium auth_delay set_user sslinfo sslutils |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.5.0 | 1817161514 | pg_session_jwt | - |
| RPM | PIGSTY | 0.5.0 | 1817161514 | pg_session_jwt_$v | - |
| DEB | PIGSTY | 0.5.0 | 1817161514 | postgresql-$v-pg-session-jwt | - |
Build
You can build the RPM / DEB packages for pg_session_jwt using pig build:
Install
You can install pg_session_jwt directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
Usage
Sources: README, v0.5.0 tag, control file
pg_session_jwt handles authenticated sessions through JWTs. When configured with a JWK, it verifies JWT authenticity. Without a JWK, it falls back to PostgREST-compatible request.jwt.claims.
Mode 1: JWK Validation
Set the JWK at connection time via libpq options:
Then within the session:
Mode 2: PostgREST-Compatible (No JWK)
Works out of the box with PostgREST. No initialization needed:
Functions
| Function | Returns | Description |
|---|---|---|
auth.init() | void | Initialize session using JWK |
auth.jwt_session_init(jwt text) | void | Set and validate a JWT |
auth.session() | jsonb | Get JWT payload or fallback claims |
auth.jwt() | jsonb | Alias for auth.session() |
auth.user_id() | text | Get the sub claim |
auth.uid() | uuid | Get sub as UUID (or NULL) |
auth.organization() | jsonb | Neon Auth organization claim helper |
auth.organization_id() | uuid | Neon Auth organization id helper |
Configuration
| Parameter | Description |
|---|---|
pg_session_jwt.jwk | JWK for JWT validation (set at startup or connection) |
pg_session_jwt.audit_log | Enable audit logging (on/off) |
RLS Example
For Neon Auth organization-scoped policies, use the o claim helpers:
Version Notes
The v0.5.0 README adds Neon Auth organization helpers and explicitly separates portable helpers such as auth.jwt(), auth.user_id(), and auth.uid() from Neon-specific auth.organization() and auth.organization_id(). Other auth providers should use auth.jwt() and extract provider-specific claims directly.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)