1
0
Fork 0
mirror of https://github.com/Luzifer/nginx-sso.git synced 2024-12-30 01:31:18 +00:00
nginx-sso/vendor/github.com/jda/go-crowd/cookie.go
Knut Ahlers 9b3c895c04
Update dependencies
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2019-04-22 06:44:07 +02:00

50 lines
1.1 KiB
Go

package crowd
import (
"encoding/xml"
"fmt"
"io/ioutil"
"net/http"
)
// CookieConfig holds configuration values needed to set a Crowd SSO cookie.
type CookieConfig struct {
XMLName struct{} `xml:"cookie-config"`
Domain string `xml:"domain"`
Secure bool `xml:"secure"`
Name string `xml:"name"`
}
// GetCookieConfig returns settings needed to set a Crowd SSO cookie.
func (c *Crowd) GetCookieConfig() (CookieConfig, error) {
cc := CookieConfig{}
c.Client.Jar = c.cookies
req, err := http.NewRequest("GET", c.url+"rest/usermanagement/1/config/cookie", nil)
if err != nil {
return cc, err
}
req.SetBasicAuth(c.user, c.passwd)
req.Header.Set("Accept", "application/xml")
req.Header.Set("Content-Type", "application/xml")
resp, err := c.Client.Do(req)
if err != nil {
return cc, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return cc, fmt.Errorf("request failed: %s", resp.Status)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return cc, err
}
err = xml.Unmarshal(body, &cc)
if err != nil {
return cc, err
}
return cc, nil
}