Add additional scopes option
This commit is contained in:
@@ -50,13 +50,34 @@ type Environment struct {
|
|||||||
IsLocal bool
|
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{
|
config := oauth2.Config{
|
||||||
ClientID: environment.ClientId,
|
ClientID: environment.ClientId,
|
||||||
ClientSecret: environment.ClientSecret,
|
ClientSecret: environment.ClientSecret,
|
||||||
Endpoint: google.Endpoint,
|
Endpoint: google.Endpoint,
|
||||||
RedirectURL: environment.BaseUrl + GoogleLoginCallback,
|
RedirectURL: environment.BaseUrl + GoogleLoginCallback,
|
||||||
Scopes: []string{"https://www.googleapis.com/auth/userinfo.email"},
|
Scopes: scopes,
|
||||||
}
|
}
|
||||||
return &GoogleAuth{
|
return &GoogleAuth{
|
||||||
db: db,
|
db: db,
|
||||||
|
|||||||
Reference in New Issue
Block a user