I'm attempting to implement Sign-in with SSB on Patchfox.
This thread will serve as a little dev diary as I made a gazillion bad decisions pragmatic choices and hit a wall which I can't overcome. I need help from people who know more about this than I do.
So the kernel of the problem is that the whole workflow of Sign-in with SSB and the modules associated with it are assuming a client like Patchwork or Manyverse which are in control of both the backend and client parts of SSB.
Patchfox has only the client-side, it piggybacks on whatever SSB server you're running. That is somewhat troublesome when it comes to features that require specialised plugins. In the case of joining a rooms 2.0 room, I managed — with help from Staltz — to load it on the client-side by manually calling the init()
method of the plugin and grafting it into the local sbot
. It kinda looks like this:
sbot.httpInviteClient = ssbHttpInviteClient.init(sbot)
All is working fine there.
When it comes to the Sign-in with SSB flow, things are a bit more complex.
That makes use of ssb-http-auth-client. I attempted to load it like I did with the other plugin.
sbot.httpAuthClientTokens = ssbHttpAuthClient[0].init(sbot) // hack: assuming order in `ssb-http-auth-client`.
sbot.httpAuthClient = ssbHttpAuthClient[1].init(sbot, {keys}) // hack: assuming order in `ssb-http-auth-client`.
sbot.httpAuth = ssbHttpAuthClient[2].init(sbot, {keys}) // hack: assuming order in `ssb-http-auth-client`.
One of those plugins, attempt to use sbot.close.hooks()
which is not available. So, I polyfilled it with a no-op:
// hack: apparently `ssb-client` has no `hook()` in `sbot.close()`, so we no-op'd a polyfill.
sbot.close.hook = (data) => {
console.warn("sbot.close is a no-op polyfill, doesn't actually work.")
}
The other problem is that the callback from ssb.conn.connect()
does not include the plugins above, so I went destructive and wrapped that so that I could force it into having the plugins I needed.
// SSB Conn callback passes an RPC back, which looks like sbot.
// This sbot does not contain the plugins above ¬¬
// I need to force it back.
let conn_aux = sbot.conn.connect
sbot.conn.connect = (serverMSAddr, cb) => {
conn_aux(serverMSAddr, (err, rpc) => {
rpc.httpAuthClientTokens = sbot.httpAuthClientTokens
rpc.httpAuthClient = sbot.httpAuthClient
rpc.httpAuth = sbot.httpAuth
console.log("ssb.conn.connect wrapped!", rpc)
cb(err, rpc)
})
}
And after all that, it loads and attempts to sign in! Buuuuut then it hits a wall which is from httpAuth
plugin which perceives it is running on the client-side and kills the whole process down because I should not be doing it anyway.
sendSolution(_sc: string, _cc: string, _sol: string, cb: CB<never>) {
cb(new Error('httpAuth.sendSolution not supported on the client side'));
},
and that is where I am, no idea where to go, or what the path to implement the Sign-in with SSB on the client-side could be.