You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
Georg Traar
committed
Add OAUTHBEARER SASL support
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.
Copy file name to clipboardExpand all lines: docs/pages/features/connecting.mdx
+20Lines changed: 20 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -114,6 +114,26 @@ const pool = new Pool({
114
114
})
115
115
```
116
116
117
+
PostgreSQL servers configured for OAuth can authenticate with a bearer token using the SASL `OAUTHBEARER` mechanism.
118
+
Pass the token directly, or provide a synchronous or asynchronous callback that resolves to a token string.
119
+
When `oauthBearerToken` is set, `OAUTHBEARER` takes precedence over `SCRAM-SHA-256-PLUS` even when TLS channel binding is available.
120
+
`pg` does not perform the OAuth authorization flow; your application is responsible for fetching and caching tokens from your OAuth provider.
121
+
Using a callback is recommended for short-lived tokens, as it is invoked for each new connection with the connection parameters and must return a non-empty token string.
122
+
123
+
```js
124
+
importpgfrom'pg'
125
+
const { Pool } = pg
126
+
127
+
constpool=newPool({
128
+
user:'api-user',
129
+
host:'database.server.com',
130
+
database:'my-db',
131
+
oauthBearerToken:async () => {
132
+
returngetAccessToken()
133
+
},
134
+
})
135
+
```
136
+
117
137
### Unix Domain Sockets
118
138
119
139
Connections to unix sockets can also be made. This can be useful on distros like Ubuntu, where authentication is managed via the socket connection instead of a password.
0 commit comments