-
Notifications
You must be signed in to change notification settings - Fork 45
Allow storing state in the database. #8
Comments
Hi, Regarding |
When nnYou're doing |
Right, you have only the state (by query params), the user and the token (returned by Handle) but not the "instance". Since I suppose you need the state + gocial right after import (
...
)
var gocial = gocialite.NewDispatcher()
gocial.setHooks(gocialite.Hooks{
AfterStateCreated: func(state, instance) { // state string, instance Gocial
// Here you can encode instance with gob, or maybe we can add a third parameter where you get the instance already encoded in []byte
},
}) In this case, Then, before the gocial.LoadState(state, instance) // state string, instance Gocial
// Handle callback and check for errors
user, token, err := gocial.Handle(state, code)
if err != nil {
c.Writer.Write([]byte("Error: " + err.Error()))
return
} Or gocial.LoadStateEncoded(state, bytes) // state string, bytes []byte
// Handle callback and check for errors
user, token, err := gocial.Handle(state, code)
if err != nil {
c.Writer.Write([]byte("Error: " + err.Error()))
return
} These functions will basically do (more or less) what func (d *Dispatcher) LoadState(state string, instance *Gocial) {
d.mu.Lock()
defer d.mu.Unlock()
d.g[state] = instance
} Tell me if I wrote some bullshit or if I didn't understand something |
I am also interested in this since the current implementation is not scalable. If we are running few instances infront of a load balancer, there will be no way to get back the correct state. We need to find a way to store in a cache server like Redis for ex. Here is a lib I created that works with different cache backend https://github.com/gadelkareem/cachita and I think it could help. |
If I understand the codebase correctly, the
Dispatcher
keeps a map from state toGocial
instance. This means that:What I'd propose, is that we implement a way to serialise
Gocial
s to a []byte, either using json or gob encoding, and then add an interface like this:which we can pass to
NewDispatcher
. We could provide a basic implementation that uses the current mechanism that stores them in a map.The text was updated successfully, but these errors were encountered: