Пример #1
0
func OAuthToken(username, password string) (t *Token, err error) {
	client.SetBasicAuth(username, password)
	res, err := client.Get(conf.Auth.TokenUrl, client.Header{}, nil)
	if err == nil {
		if res.StatusCode == http.StatusCreated {
			if body, err := ioutil.ReadAll(res.Body); err == nil {
				if err = json.Unmarshal(body, &t); err != nil {
					return nil, err
				}
			}
		} else {
			return nil, errors.New("Authentication failed: Unexpected response status: " + res.Status)
		}
	} else {
		return nil, err
	}
	return
}
Пример #2
0
func SetBasicAuth(username, password string) {
	client.SetBasicAuth(username, password)
}