Open titusgahissy opened 7 months ago
Providers config (client_id, client_secret, etc) can be stored in a database and change while the application is running. The current syntax does not allow to handle this usecase.
client_id
client_secret
goth.UseProviders(providers) // static data
This PR introduces a new interface:
type ProviderResolver interface { Get(name string) (Provider, error) GetAll() Providers }
// No breaking changes func UseProviders(viders ...Provider) { providers := Providers{} for _, p := range viders { providers[p.Name()] = p } resolver = DefaultProviderResolver{providers: providers} } func GetProviders() Providers { return resolver.GetAll() } func GetProvider(name string) (Provider, error) { return resolver.Get(name) }
Now it becomes possible to do something like:
type MyCustomResolver struct{ db *gorm.DB } func (r MyCustomResolver) Get(name string) (goth.Provider, error) { // do your magic } func (r MyCustomResolver) GetAll() goth.Providers { // do your magic } goth.SetProviderResolver(&MyCustomResolver{db: db})
Thanks @titusgahissy, could you resolve the conflicts?
Providers config (
client_id
,client_secret
, etc) can be stored in a database and change while the application is running. The current syntax does not allow to handle this usecase.This PR introduces a new interface:
Now it becomes possible to do something like: