From 9d0733bd960a68fb80efbd9879e8cc803fc8eb0e Mon Sep 17 00:00:00 2001 From: Achim Rohn Date: Mon, 6 Apr 2026 16:45:10 +0200 Subject: [PATCH] Add additional scopes option --- authentication/google/http/google_auth.go | 25 +++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) 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,