diff --git a/authentication/google/http/google_auth.go b/authentication/google/http/google_auth.go index 6608a80..6869d45 100644 --- a/authentication/google/http/google_auth.go +++ b/authentication/google/http/google_auth.go @@ -50,13 +50,34 @@ type Environment struct { IsLocal bool } -func NewGoogleAuth(db Database, server *http.ServeMux, environment Environment, sessionStore *sessions.CookieStore) *GoogleAuth { +type GoogleAuthParams struct { + AdditionalScopes []string +} + +type GoogleAuthOption func(p *GoogleAuthParams) + +func WithAdditionalScopes(scopes []string) GoogleAuthOption { + return func(p *GoogleAuthParams) { + p.AdditionalScopes = scopes + } +} + +func NewGoogleAuth(db Database, server *http.ServeMux, environment Environment, sessionStore *sessions.CookieStore, + options ...GoogleAuthOption) *GoogleAuth { + + params := GoogleAuthParams{} + for _, option := range options { + option(¶ms) + } + scopes := []string{"https://www.googleapis.com/auth/userinfo.email"} + scopes = append(scopes, params.AdditionalScopes...) + config := oauth2.Config{ ClientID: environment.ClientId, ClientSecret: environment.ClientSecret, Endpoint: google.Endpoint, RedirectURL: environment.BaseUrl + GoogleLoginCallback, - Scopes: []string{"https://www.googleapis.com/auth/userinfo.email"}, + Scopes: scopes, } return &GoogleAuth{ db: db,