Software /
code /
verse
File
util/sasl/oauthbearer.lua @ 485:c9a144591649
component: Avoid adding to the global stream metatable
This allows component and client connections to be made side-by-side.
Previous to this change, loading this connection module would break the
ability to make client connections, due to overriding stream methods such as
:reopen() and :reset().
A next step would be to share the methods that the two connection modules have
in common.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 23 Mar 2023 18:56:32 +0000 |
parent | 477:b0a8d4e9934e |
child | 496:c4ae7aa2958a |
line wrap: on
line source
return function (stream, name) if name == "OAUTHBEARER" and stream.username then return function (stream) local auth = stream.bearer_token and ("Bearer "..stream.bearer_token) or ""; local message, data = coroutine.yield("n,a="..stream.username.."@"..stream.host..",\001auth="..auth.."\001"); if message == "success" then return true; elseif message == "challenge" then stream:event("oauth-failure", { json = data; }); -- Note: No code after the yield should generally execute, as "failure" -- doesn't get passed through to us (it contains no data anyway) if coroutine.yield("\001") ~= "failure" then error("Unexpected SASL state: expected failure after challenge"); end return false; end end, stream.bearer_token and 6 or 4; -- Prefer OAUTHBEARER if we have a token, otherwise prefer password if we have one end end