Add SASL OAUTHBEARER support with application-supplied tokens#3694
Open
proddata wants to merge 1 commit into
Open
Add SASL OAUTHBEARER support with application-supplied tokens#3694proddata wants to merge 1 commit into
proddata wants to merge 1 commit into
Conversation
Add an oauthBearerToken client option for PostgreSQL OAUTHBEARER authentication, including token callback handling and SASL response serialization. Keep bearer tokens non-enumerable in client, connection parameters, and pool options, and document the new pure-JS client support. Add focused unit coverage for OAuth SASL mechanism selection, callback error paths, credential redaction, and SCRAM compatibility.
605f620 to
b19703e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds support for PostgreSQL's SASL
OAUTHBEARERauthentication mechanism when the application supplies a bearer token directly or through a callback.The implementation intentionally keeps OAuth provider interaction outside of
pg. OAuth bearer token acquisition depends heavily on the IdP, grant type, scopes, refresh behavior, caching policy, and user interaction model. Instead of embedding that logic in the driver, this change gives applications a focused hook for supplying a valid token whilepghandles the PostgreSQL SASL protocol exchange.Changes
oauthBearerTokenclient option that accepts either:OAUTHBEARERwhen the server advertises it andoauthBearerTokenis configured.sendSASLResponseMessageprotocol serializer while keepingsendSCRAMClientFinalMessageas an alias for SCRAM compatibility.oauthBearerTokennon-enumerable on client, connection parameters, and pool options so token values do not appear in common inspection/serialization output.Rationale
PostgreSQL 18 adds native OAuth authentication using the SASL
OAUTHBEARERmechanism. Returning a bearer token from the existingpasswordcallback is not sufficient because the server expects OAUTHBEARER SASL messages, not a SCRAM exchange.This change implements the PostgreSQL protocol support needed for callers that already have, or can fetch, a bearer token. Keeping token acquisition in user code keeps the driver small and avoids baking IdP-specific OAuth behavior into
pg.Scope
This does not implement a full OAuth authorization flow, device authorization grant, token discovery, or token refresh logic inside
pg.Applications can build those flows externally and provide the resulting token through
oauthBearerToken.This support applies to the pure JavaScript client.
pg.nativedelegates authentication to libpq and does not currently useoauthBearerToken; native OAuth support would require libpq OAuth configuration or new node-libpq auth hook bindings.Partially resolves #3687
I am not conviced that fully following libpq (oauth_issuer and oauth_client_id) is proper for a low level driver like node-pg. However open for suggestions.
co-authored with codex