in entryMaker/oneCRL/oneCRL.go [410:451]
func checkKintoAuth(collectionUrl string) error {
conf := config.GetConfig()
kintoBase := strings.SplitAfter(collectionUrl, "/v1/")[0]
req, err := http.NewRequest("GET", kintoBase, nil)
if len(conf.KintoToken) > 0 {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", conf.KintoToken))
} else if len(conf.KintoUser) > 0 {
req.SetBasicAuth(conf.KintoUser, conf.KintoPassword)
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if nil != err {
return err
}
err = checkResponseStatus(resp, "There was a problem checking auth status")
if nil != err {
return err
}
res := new(KintoMetadata)
err = json.NewDecoder(resp.Body).Decode(res)
if nil != err {
return err
}
if "" == res.User.Id {
return errors.New("Cannot perform Kinto operations; user is not authenticated")
}
fmt.Printf("authenticated as user %s\n", res.User.Id)
defer resp.Body.Close()
return nil
}