commento/api/oauth_google.go
Adhityaa 2020405e8b frontend, api: allow custom emails as commenters
I'm really sorry this came out as one huge commit, but I'm afraid
I can't split this up.

Closes https://gitlab.com/commento/commento-ce/issues/9
2018-06-10 22:58:54 +05:30

44 lines
1022 B
Go

package main
import (
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"os"
)
var googleConfig *oauth2.Config
func googleOauthConfigure() error {
googleConfig = nil
if os.Getenv("GOOGLE_KEY") == "" && os.Getenv("GOOGLE_SECRET") == "" {
return nil
}
if os.Getenv("GOOGLE_KEY") == "" {
logger.Errorf("GOOGLE_KEY not configured, but GOOGLE_SECRET is set")
return errorOauthMisconfigured
}
if os.Getenv("GOOGLE_SECRET") == "" {
logger.Errorf("GOOGLE_SECRET not configured, but GOOGLE_KEY is set")
return errorOauthMisconfigured
}
logger.Infof("loading Google OAuth config")
googleConfig = &oauth2.Config{
RedirectURL: os.Getenv("ORIGIN") + "/api/oauth/google/callback",
ClientID: os.Getenv("GOOGLE_KEY"),
ClientSecret: os.Getenv("GOOGLE_SECRET"),
Scopes: []string{
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email",
},
Endpoint: google.Endpoint,
}
configuredOauths = append(configuredOauths, "google");
return nil
}