Skip to content

Commit

Permalink
MR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-r-west committed Nov 21, 2024
1 parent 63975a3 commit b4e0c98
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 418 deletions.
167 changes: 0 additions & 167 deletions external/oidc/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,170 +158,3 @@ func GenerateCodeChallenge(verifier string) (string, error) {
// Base64 URL encode the hash
return base64.RawURLEncoding.EncodeToString(hash[:]), nil
}

/*
tmpl, err := template.New("index").Parse(oidc.Index)
if err != nil {
log.Errorf("Could not parse index template")
w.WriteHeader(500)
return
}
err = tmpl.Execute(w, profiles)
if err != nil {
log.Warnf("Error handling request %v\n%v", r, err)
return
}
})
http.HandleFunc("/callback", func(w http.ResponseWriter, r *http.Request) {
// Parse the query parameters
queryParams := r.URL.Query()
// Convert query parameters to a map
data := make(map[string]string)
for key, values := range queryParams {
data[key] = values[0] // Use the first value if multiple are provided
}
data["uri"] = fmt.Sprintf("http://localhost:", port)
if data["code"] != "" {
state, err := r.Cookie("state")
if err != nil {
log.Errorf("Could not get state cookie")
w.WriteHeader(500)
return
}
verifier, err := r.Cookie("code_verifier")
if err != nil {
log.Errorf("Could not get verifier cookie")
w.WriteHeader(500)
return
}
result, err := rest.CreateInternal(context.Background(), &httpclient.HttpParameterOverrides{}, []string{"account-management-authentication-token",
"authentication_mechanism", "oidc",
"oauth_authorization_code", data["code"],
"oauth_redirect_uri", fmt.Sprintf("http://localhost:%d/callback", port),
"oauth_state", state.Value,
"oauth_code_verifier", verifier.Value,
}, false, "", true)
if err != nil {
RenderErrorPage(w, "Could Not Get Account Tokens", err.Error())
return
}
spi := SuccessPageInfo{
LoginType: "AM",
}
err = gojson.Unmarshal([]byte(result), &spi.AccountTokenResponse)
if err != nil {
log.Errorf("Could not unmarshal account: %v", err)
}
for _, v := range spi.AccountTokenResponse.Data {
str, err := gojson.Marshal(v)
if err != nil {
log.Errorf("Could not encode token %v", err)
}
base64.URLEncoding.EncodeToString(str)
spi.AccountTokenStructBase64 = append(spi.AccountTokenStructBase64, base64.URLEncoding.EncodeToString(str))
}
log.Infof("Result: %v, SPI: %v, State: %s, Verifier: %s", result, spi, state.String(), verifier.String())
tmpl, err := template.New("index").Parse(oidc.SuccessPage)
if err != nil {
log.Errorf("Could not parse index template")
w.WriteHeader(500)
return
}
err = tmpl.Execute(w, spi)
if err != nil {
log.Warnf("Error handling request %v\n%v", r, err)
return
}
return
} else if data["error"] == "" {
RenderErrorPage(w, "bad_response", "Invalid response from IdP, no code or error query parameter")
} else {
RenderErrorPage(w, data["error"], data["error_description"])
}
})
http.HandleFunc("/style.css", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/css")
_, err := fmt.Fprintf(w, oidc.Css)
if err != nil {
log.Warnf("Error handling request %v\n%v", r, err)
return
}
})
http.HandleFunc("/set-am-token/", func(w http.ResponseWriter, r *http.Request) {
token := strings.Replace(r.URL.Path, "/set-am-token/", "", 1)
log.Infof("Setting Token to %s", token)
amTokenJson, err := base64.URLEncoding.DecodeString(token)
if err != nil {
log.Errorf("Could not base64 decode token %v", err)
w.WriteHeader(500)
return
}
amToken := authentication.AccountManagementAuthenticationTokenStruct{}
err = gojson.Unmarshal(amTokenJson, &amToken)
if err != nil {
log.Errorf("Could not unmarshal token %v", err)
w.WriteHeader(500)
return
}
authentication.SaveAccountManagementAuthenticationToken(amToken)
tmpl, err := template.New("index").Parse(oidc.DonePage)
if err != nil {
log.Errorf("Could not parse index template")
w.WriteHeader(500)
return
}
err = tmpl.Execute(w, amToken)
if err != nil {
log.Warnf("Error handling request %v\n%v", r, err)
return
}
return
return
})
*/
Loading

0 comments on commit b4e0c98

Please sign in to comment.