oauth config: Use GITLAB_URL env variable

In order to use oauth from gitlab CE instance one has to be
able to provide the URL of the instance.

closes #209 (https://gitlab.com/commento/commento/issues/209)
This commit is contained in:
matclab 2019-07-26 12:28:19 +02:00 committed by Adhityaa Chandrasekar
parent 07cfcc9c17
commit b57b6bcc12
3 changed files with 5 additions and 1 deletions

View File

@ -56,6 +56,7 @@ func configParse() error {
"GITLAB_KEY": "", "GITLAB_KEY": "",
"GITLAB_SECRET": "", "GITLAB_SECRET": "",
"GITLAB_URL": "https://gitlab.com",
} }
if os.Getenv("COMMENTO_CONFIG_FILE") != "" { if os.Getenv("COMMENTO_CONFIG_FILE") != "" {

View File

@ -35,6 +35,8 @@ func gitlabOauthConfigure() error {
}, },
Endpoint: gitlab.Endpoint, Endpoint: gitlab.Endpoint,
} }
gitlabConfig.Endpoint.AuthURL = os.Getenv("GITLAB_URL") + "/oauth/authorize"
gitlabConfig.Endpoint.TokenURL = os.Getenv("GITLAB_URL") + "/oauth/token"
gitlabConfigured = true gitlabConfigured = true

View File

@ -6,6 +6,7 @@ import (
"golang.org/x/oauth2" "golang.org/x/oauth2"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os"
) )
func gitlabCallbackHandler(w http.ResponseWriter, r *http.Request) { func gitlabCallbackHandler(w http.ResponseWriter, r *http.Request) {
@ -24,7 +25,7 @@ func gitlabCallbackHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
resp, err := http.Get("https://gitlab.com/api/v4/user?access_token=" + token.AccessToken) resp, err := http.Get(os.Getenv("GITLAB_URL") + "/api/v4/user?access_token=" + token.AccessToken)
if err != nil { if err != nil {
fmt.Fprintf(w, "Error: %s", err.Error()) fmt.Fprintf(w, "Error: %s", err.Error())
return return