On Tue, 2022-03-22 at 14:48 -0700, samay sharma wrote: > Thank you for porting this on top of the pluggable auth methods API. > I've addressed the feedback around other backend changes in my latest > patch, but the client side changes still remain. I had a few > questions to understand them better. > > (a) What specifically do the client side changes in the patch implement?
Hi Samay, The client-side changes are an implementation of the OAuth 2.0 Device Authorization Grant [1] in libpq. The majority of the OAuth logic is handled by the third-party iddawc library. The server tells the client what OIDC provider to contact, and then libpq prompts you to log into that provider on your smartphone/browser/etc. using a one-time code. After you give libpq permission to act on your behalf, the Bearer token gets sent to libpq via a direct connection, and libpq forwards it to the server so that the server can determine whether you're allowed in. > (b) Are the changes you made on the client side specific to OAUTH or > are they about making SASL more generic? The original patchset included changes to make SASL more generic. Many of those changes have since been merged, and the remaining code is mostly OAuth-specific, but there are still improvements to be made. (And there's some JSON crud to sift through in the first couple of patches. I'm still mad that the OAUTHBEARER spec requires clients to parse JSON in the first place.) > As an additional question, > if someone wanted to implement something similar on top of your > patch, would they still have to make client side changes? Any new SASL mechanisms require changes to libpq at this point. You need to implement a new pg_sasl_mech, modify pg_SASL_init() to select the mechanism correctly, and add whatever connection string options you need, along with the associated state in pg_conn. Patch 0004 has all the client-side magic for OAUTHBEARER. --Jacob [1] https://datatracker.ietf.org/doc/html/rfc8628