mirror of
https://gitlab.com/commento/commento.git
synced 2025-06-29 22:56:37 -04:00
api: Add go files
I know this is a huge commit, but I can't be bothered to check this in part by part.
This commit is contained in:
41
api/oauth_google.go
Normal file
41
api/oauth_google.go
Normal file
@ -0,0 +1,41 @@
|
||||
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("BACKEND_WEB") + "/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,
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user