in pkg/provider/custom/custom.go [49:99]
func (oc *Client) Authenticate(loginDetails *creds.LoginDetails) (string, error) {
_, err := url.Parse(loginDetails.URL)
if err != nil {
return "", errors.Wrap(err, "error building login request URL")
}
//authenticate using x-www-form-urlencoded
authReq := url.Values{}
authReq.Set("username", loginDetails.Username)
authReq.Set("password", loginDetails.Password)
authBody := strings.NewReader(authReq.Encode())
req, err := http.NewRequest("POST", loginDetails.URL, authBody)
if err != nil {
return "", errors.Wrap(err, "error building authentication request")
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Content-Length", strconv.Itoa(len(authReq.Encode())))
res, err := oc.client.Do(req)
if err != nil {
return "", errors.Wrap(err, "error retrieving auth response")
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return "", errors.Wrap(err, "error retrieving body from response")
}
resp := string(body)
successResponse := gjson.Get(resp, "success").String()
samlResponse := gjson.Get(resp, "data").String()
// error response
if successResponse != "true" {
return "", errors.Wrap(err, "error retrieving SAML response")
}
decodedSamlResponse, err := base64.StdEncoding.DecodeString(samlResponse)
if err != nil {
return "", errors.Wrap(err, "failed to decode SAML response")
}
logger.WithField("type", "saml-response").WithField("saml-response", string(decodedSamlResponse)).Debug("custom auth response")
return samlResponse, nil
}