modernizations

This commit is contained in:
Denys Konovalov 2023-01-15 22:29:56 +01:00
parent 9a91af1467
commit 79580c1c51
2 changed files with 6 additions and 2 deletions

5
env/sample.config vendored

@ -5,6 +5,9 @@ environment="development"
host="localhost" host="localhost"
port="3000" port="3000"
sessionSecret="super-secret" sessionSecret="super-secret"
publicProto="https"
public="oauth.example.com"
publicPort="443"
# Delete if not in use # Delete if not in use
[gitea] [gitea]
@ -14,7 +17,7 @@ baseURL="https://gitea.yourcompany.com"
authURI= authURI=
accessTokenURI= accessTokenURI=
userURI= userURI=
callbackURI="http://localhost:3000/callback/gitea" callbackURI="https://oauth.example.com/callback/gitea"
# Delete if not in use # Delete if not in use
[gitlab] [gitlab]

@ -169,8 +169,9 @@ func main() {
// redirect to correct auth/{provider} URL if Auth request is submited with a query param '&provider=X' // redirect to correct auth/{provider} URL if Auth request is submited with a query param '&provider=X'
// TODO: Remove hardcoded http:// // TODO: Remove hardcoded http://
r.HandleFunc("/auth", func(w http.ResponseWriter, r *http.Request) { r.HandleFunc("/auth", func(w http.ResponseWriter, r *http.Request) {
proto := config.GetString("server.publicProto")
host := net.JoinHostPort(config.GetString("server.host"), config.GetString("server.port")) host := net.JoinHostPort(config.GetString("server.host"), config.GetString("server.port"))
URL := fmt.Sprintf("http://%s/auth/%s", host, r.FormValue("provider")) URL := fmt.Sprintf("%s://%s/auth/%s", proto, host, r.FormValue("provider"))
log.Infof("redirecting to '%s'\n", URL) log.Infof("redirecting to '%s'\n", URL)
http.Redirect(w, r, URL, http.StatusTemporaryRedirect) http.Redirect(w, r, URL, http.StatusTemporaryRedirect)