mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
48 lines
973 B
Go
48 lines
973 B
Go
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}
|
|
}
|