Add additional scopes option

This commit is contained in:
Achim Rohn
2026-04-06 16:45:10 +02:00
parent 2aabad6f07
commit 9d0733bd96
+23 -2
View File
@@ -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(&params)
}
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,