Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add providers resolver #539

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

titusgahissy
Copy link

@titusgahissy titusgahissy commented Feb 10, 2024

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.

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})

@techknowlogick
Copy link
Collaborator

Thanks @titusgahissy, could you resolve the conflicts?

go.mod Outdated
@@ -1,41 +1,20 @@
module github.com/markbates/goth
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for updating this PR. It looks like somethings have been reverted from master in go.mod. Could you bump the version to 1.18, and run go mod tidy?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be ok now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants