2019-02-23 10:54:08 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/oauth2"
|
|
|
|
"golang.org/x/oauth2/gitlab"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
var gitlabConfig *oauth2.Config
|
|
|
|
|
|
|
|
func gitlabOauthConfigure() error {
|
|
|
|
gitlabConfig = nil
|
|
|
|
if os.Getenv("GITLAB_KEY") == "" && os.Getenv("GITLAB_SECRET") == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if os.Getenv("GITLAB_KEY") == "" {
|
|
|
|
logger.Errorf("COMMENTO_GITLAB_KEY not configured, but COMMENTO_GITLAB_SECRET is set")
|
|
|
|
return errorOauthMisconfigured
|
|
|
|
}
|
|
|
|
|
|
|
|
if os.Getenv("GITLAB_SECRET") == "" {
|
|
|
|
logger.Errorf("COMMENTO_GITLAB_SECRET not configured, but COMMENTO_GITLAB_KEY is set")
|
|
|
|
return errorOauthMisconfigured
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.Infof("loading gitlab OAuth config")
|
|
|
|
|
|
|
|
gitlabConfig = &oauth2.Config{
|
|
|
|
RedirectURL: os.Getenv("ORIGIN") + "/api/oauth/gitlab/callback",
|
|
|
|
ClientID: os.Getenv("GITLAB_KEY"),
|
|
|
|
ClientSecret: os.Getenv("GITLAB_SECRET"),
|
|
|
|
Scopes: []string{
|
|
|
|
"read_user",
|
|
|
|
},
|
|
|
|
Endpoint: gitlab.Endpoint,
|
|
|
|
}
|
2019-07-26 18:28:19 +08:00
|
|
|
gitlabConfig.Endpoint.AuthURL = os.Getenv("GITLAB_URL") + "/oauth/authorize"
|
|
|
|
gitlabConfig.Endpoint.TokenURL = os.Getenv("GITLAB_URL") + "/oauth/token"
|
2019-02-23 10:54:08 +08:00
|
|
|
|
2019-04-20 07:03:34 +08:00
|
|
|
gitlabConfigured = true
|
2019-02-23 10:54:08 +08:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|