|
@@ -25,6 +25,7 @@ type OauthHandler struct {
|
|
|
|
|
|
type Config struct {
|
|
type Config struct {
|
|
Enabled bool `json:"enabled"`
|
|
Enabled bool `json:"enabled"`
|
|
|
|
+ AutoRedirect bool `json:"auto_redirect"`
|
|
IDP string `json:"idp"`
|
|
IDP string `json:"idp"`
|
|
RedirectURL string `json:"redirect_url"`
|
|
RedirectURL string `json:"redirect_url"`
|
|
ServerURL string `json:"server_url"`
|
|
ServerURL string `json:"server_url"`
|
|
@@ -152,11 +153,27 @@ func (oh *OauthHandler) HandleAuthorize(w http.ResponseWriter, r *http.Request)
|
|
|
|
|
|
//CheckOAuth check if oauth is enabled
|
|
//CheckOAuth check if oauth is enabled
|
|
func (oh *OauthHandler) CheckOAuth(w http.ResponseWriter, r *http.Request) {
|
|
func (oh *OauthHandler) CheckOAuth(w http.ResponseWriter, r *http.Request) {
|
|
|
|
+ enabledB := false
|
|
enabled := oh.readSingleConfig("enabled")
|
|
enabled := oh.readSingleConfig("enabled")
|
|
- if enabled == "" {
|
|
|
|
- enabled = "false"
|
|
|
|
|
|
+ if enabled == "true" {
|
|
|
|
+ enabledB = true
|
|
}
|
|
}
|
|
- sendJSONResponse(w, enabled)
|
|
|
|
|
|
+
|
|
|
|
+ autoredirectB := false
|
|
|
|
+ autoredirect := oh.readSingleConfig("autoredirect")
|
|
|
|
+ if autoredirect == "true" {
|
|
|
|
+ autoredirectB = true
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ type returnFormat struct {
|
|
|
|
+ Enabled bool `json:"enabled"`
|
|
|
|
+ AutoRedirect bool `json:"auto_redirect"`
|
|
|
|
+ }
|
|
|
|
+ json, err := json.Marshal(returnFormat{Enabled: enabledB, AutoRedirect: autoredirectB})
|
|
|
|
+ if err != nil {
|
|
|
|
+ sendErrorResponse(w, "Error occurred while marshalling JSON response")
|
|
|
|
+ }
|
|
|
|
+ sendJSONResponse(w, string(json))
|
|
}
|
|
}
|
|
|
|
|
|
//https://golangcode.com/add-a-http-cookie/
|
|
//https://golangcode.com/add-a-http-cookie/
|
|
@@ -176,7 +193,11 @@ func (oh *OauthHandler) ReadConfig(w http.ResponseWriter, r *http.Request) {
|
|
sendTextResponse(w, "Invalid config value [key=enabled].")
|
|
sendTextResponse(w, "Invalid config value [key=enabled].")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ autoredirect, err := strconv.ParseBool(oh.readSingleConfig("autoredirect"))
|
|
|
|
+ if err != nil {
|
|
|
|
+ sendTextResponse(w, "Invalid config value [key=autoredirect].")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
idp := oh.readSingleConfig("idp")
|
|
idp := oh.readSingleConfig("idp")
|
|
redirecturl := oh.readSingleConfig("redirecturl")
|
|
redirecturl := oh.readSingleConfig("redirecturl")
|
|
serverurl := oh.readSingleConfig("serverurl")
|
|
serverurl := oh.readSingleConfig("serverurl")
|
|
@@ -185,6 +206,7 @@ func (oh *OauthHandler) ReadConfig(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
config, err := json.Marshal(Config{
|
|
config, err := json.Marshal(Config{
|
|
Enabled: enabled,
|
|
Enabled: enabled,
|
|
|
|
+ AutoRedirect: autoredirect,
|
|
IDP: idp,
|
|
IDP: idp,
|
|
ServerURL: serverurl,
|
|
ServerURL: serverurl,
|
|
RedirectURL: redirecturl,
|
|
RedirectURL: redirecturl,
|
|
@@ -207,8 +229,11 @@ func (oh *OauthHandler) WriteConfig(w http.ResponseWriter, r *http.Request) {
|
|
sendErrorResponse(w, "enabled field can't be empty")
|
|
sendErrorResponse(w, "enabled field can't be empty")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-
|
|
|
|
- oh.coredb.Write("oauth", "enabled", enabled)
|
|
|
|
|
|
+ autoredirect, err := mv(r, "autoredirect", true)
|
|
|
|
+ if err != nil {
|
|
|
|
+ sendErrorResponse(w, "enabled field can't be empty")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
showError := true
|
|
showError := true
|
|
if enabled != "true" {
|
|
if enabled != "true" {
|
|
@@ -259,6 +284,8 @@ func (oh *OauthHandler) WriteConfig(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ oh.coredb.Write("oauth", "enabled", enabled)
|
|
|
|
+ oh.coredb.Write("oauth", "autoredirect", autoredirect)
|
|
oh.coredb.Write("oauth", "idp", idp)
|
|
oh.coredb.Write("oauth", "idp", idp)
|
|
oh.coredb.Write("oauth", "redirecturl", redirecturl)
|
|
oh.coredb.Write("oauth", "redirecturl", redirecturl)
|
|
oh.coredb.Write("oauth", "serverurl", serverurl)
|
|
oh.coredb.Write("oauth", "serverurl", serverurl)
|