pg_session_jwt
pg_session_jwt · Manage authentication sessions using JWTs
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 7060 | pg_session_jwt | pg_session_jwt | 0.5.0 | SEC | Apache-2.0 | Rust |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-dt- | No | Yes | No | Yes | no | yes |
| Relationships | |
|---|---|
| Schemas | auth |
| See Also | pg_oidc_validator pgjwt login_hook oidc_validator pg_auth_mon pgsodium auth_delay set_user sslinfo sslutils |
Packages
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| el8.aarch64 | N/A | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| el9.x86_64 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| el9.aarch64 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| el10.x86_64 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| el10.aarch64 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| d12.x86_64 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| d12.aarch64 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| d13.x86_64 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| d13.aarch64 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| u22.x86_64 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| u22.aarch64 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| u24.x86_64 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| u24.aarch64 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| u26.x86_64 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
| u26.aarch64 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 | PIGSTY 0.5.0 |
Source
github.com/neondatabase/pg_session_jwt
pg_session_jwt-0.5.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
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.