Skip to content

OAuth2 authentication - #1325

Closed
JoHaHu wants to merge 2 commits into
rust-postgres:masterfrom
JoHaHu:feature/oauth2_authentication
Closed

JoHaHu wants to merge 2 commits into
rust-postgres:masterfrom
JoHaHu:feature/oauth2_authentication

Conversation

@JoHaHu

@JoHaHu JoHaHu commented Feb 9, 2026

Copy link
Copy Markdown

This adds support to authenticate connections using OAuth2 tokens.
This is available in since Postgres 18.
This is useful to e.g. authenticate using Kubernetes service account tokens.
The acquiring and caching of tokens is out of scope for this implementation and should be implemented via the token provider.

@geoHeil

geoHeil commented Aug 29, 2026

Copy link
Copy Markdown

@JoHaHu I hope this is welcome rather than intrusive — this PR had been quiet for a while and no longer merged, so I picked it up rather than opening a competing implementation: #1378, with #1377 as the issue describing the scope.

Your approach is the one in it, unchanged in substance: token-first only, and a token-provider closure called per connection attempt. What I added is a rebase onto current master, the RFC 7628 Sec. 3.2.3 failure round (so a rejected token surfaces the server's own error instead of "unexpected message"), tests, and docs. One thing worth flagging in case you want to fix it here instead: authenticate_oauthbearer consumed the AuthenticationOk message, but authenticate() reads that itself after the SASL helper returns, so a successful exchange would have failed with unexpected message from server. Easy to miss without a validator-equipped server to test against.

If you would rather carry this forward yourself, say so and I will close #1378 — I have no attachment to it beyond wanting the feature to land. Either way the credit is yours, and it is in the commit message.

@JoHaHu JoHaHu closed this Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants