Skip to content

add: config jwt-schema-claim-key for schema selection in JWT#4779

Draft
taimoorzaeem wants to merge 2 commits intoPostgREST:mainfrom
taimoorzaeem:add/jwt-schema-claim-key
Draft

add: config jwt-schema-claim-key for schema selection in JWT#4779
taimoorzaeem wants to merge 2 commits intoPostgREST:mainfrom
taimoorzaeem:add/jwt-schema-claim-key

Conversation

@taimoorzaeem
Copy link
Copy Markdown
Member

@taimoorzaeem taimoorzaeem commented Apr 3, 2026

It follows the same JSPath grammar as jwt-role-claim-key. If
the schema is specified in JWT claims, it overides the Accept-Profile
and Content-Profile headers.

Closes #4608.

  • Implementation
  • Tests
  • Docs
  • Changelog entry

@taimoorzaeem taimoorzaeem marked this pull request as draft April 3, 2026 04:09
@taimoorzaeem taimoorzaeem force-pushed the add/jwt-schema-claim-key branch 2 times, most recently from 11fffc6 to c56a332 Compare April 8, 2026 12:11
@taimoorzaeem taimoorzaeem marked this pull request as ready for review April 8, 2026 12:11
@taimoorzaeem taimoorzaeem added the enhancement a feature, ready for implementation label Apr 8, 2026
@taimoorzaeem taimoorzaeem marked this pull request as draft April 13, 2026 11:55
@taimoorzaeem taimoorzaeem force-pushed the add/jwt-schema-claim-key branch from c56a332 to c4ac255 Compare April 13, 2026 14:18
@taimoorzaeem taimoorzaeem marked this pull request as ready for review April 13, 2026 14:19
@taimoorzaeem taimoorzaeem marked this pull request as draft April 13, 2026 17:20
Comment thread src/PostgREST/ApiRequest.hs
Comment thread docs/references/auth.rst Outdated
Comment thread docs/references/auth.rst Outdated
Comment thread docs/references/auth.rst Outdated
@taimoorzaeem taimoorzaeem force-pushed the add/jwt-schema-claim-key branch from c4ac255 to 6d2173d Compare April 14, 2026 04:09
@taimoorzaeem
Copy link
Copy Markdown
Member Author

Maybe we should also link the JWT Schema Extraction section somewhere in https://docs.postgrest.org/en/v14/references/api/schemas.html? Not sure where though.

@taimoorzaeem taimoorzaeem marked this pull request as ready for review April 14, 2026 04:16
Comment thread docs/references/auth.rst Outdated
It follows the same JSPath grammar as `jwt-role-claim-key`. If
the schema is specified in JWT claims, it overides the `Accept-Profile`
and `Content-Profile` headers.

Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
@taimoorzaeem taimoorzaeem force-pushed the add/jwt-schema-claim-key branch from 6d2173d to 1455a88 Compare April 16, 2026 06:17
Comment thread docs/references/api/schemas.rst Outdated
JWT Schema Extraction
~~~~~~~~~~~~~~~~~~~~~

Schema can be specified in JWT claims. It is configured by :ref:`jwt-schema-claim-key`. This feature can be used for JWT-driven schema-based multitenancy. It allows fully hidden schema selection without exposing the schema in :ref:`profile headers <profile_headers>`. The schema specified in JWT takes precedence over profile headers.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit shorter

Suggested change
Schema can be specified in JWT claims. It is configured by :ref:`jwt-schema-claim-key`. This feature can be used for JWT-driven schema-based multitenancy. It allows fully hidden schema selection without exposing the schema in :ref:`profile headers <profile_headers>`. The schema specified in JWT takes precedence over profile headers.
The schema can be extracted from the JWT claims using the :ref:`jwt-schema-claim-key`. This feature can be used for schema-based multitenancy. It allows hidden schema selection without exposing the schema in :ref:`profile headers <profile_headers>`. The schema specified in JWT takes precedence over profile headers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taimoorzaeem Sorry, I rushed into commiting this suggestion. You can squash it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, that's cool.


=============== =================================
**Type** String
**Default** .schema
Copy link
Copy Markdown
Member

@steve-chavez steve-chavez Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this one almost slips by. It should be empty by default, consider:

  • User upgrades to next major
  • Some of their JWTs somehow contained a schema key (unrelated to the database schema)
  • Now they'll run into some requests failing saying "schema X does not exist" and be confused about it.

So users should be conscious and careful about this key name. Maybe we even suggest an example JWT containing a db_schema key. (just schema can mean lots of different things)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, good catch. 👍

@taimoorzaeem taimoorzaeem marked this pull request as draft April 17, 2026 06:54
@taimoorzaeem taimoorzaeem removed the enhancement a feature, ready for implementation label Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Allow schema selection from JWT claims (like role)

2 participants