add google login

This commit is contained in:
Ruidy 2024-05-19 21:04:44 +02:00
parent 8f4f1638a4
commit 0924417a81
No known key found for this signature in database
GPG key ID: E00F51288CB857CC

48
internal/auth/service.go Normal file
View file

@ -0,0 +1,48 @@
package auth
import (
"sort"
"github.com/gorilla/sessions"
"github.com/markbates/goth"
"github.com/markbates/goth/gothic"
"github.com/markbates/goth/providers/google"
)
type Service struct {
secret string
googleClientId string
googleSecret string
googleRedirectUrl string
}
type ProviderIndex struct {
ProvidersMap map[string]string
Providers []string
}
func NewService(secret, googleClientId, googleSecret, googleRedirectUrl string) *Service {
return &Service{
secret,
googleClientId,
googleSecret,
googleRedirectUrl,
}
}
func (as Service) GetProviderIndex() *ProviderIndex {
goth.UseProviders(google.New(as.googleClientId, as.googleSecret, as.googleRedirectUrl))
m := map[string]string{
"google": "Google",
}
var keys []string
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
gothic.Store = sessions.NewCookieStore([]byte(as.secret))
return &ProviderIndex{Providers: keys, ProvidersMap: m}
}