// Refresh is used to obtain an OAuth2 access_token
Refresh is used to obtain an OAuth2 access_token
// Refresh is used to obtain an OAuth2 access_token
func (conn *RestConnection) Refresh() error {
	urlValues := url.Values{}
	urlValues.Set("grant_type", "password")
	urlValues.Set("username", conn.Username)
	urlValues.Set("password", conn.Password)
	req, err := http.NewRequest("POST", conn.Host+"/auth/oauth/token", strings.NewReader(urlValues.Encode()))
	if err != nil {
		return err
	}
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Add("User-Agent", "Skuid-CLI/"+VERSION)
	resp, err := getClientForProxyURL(conn.MetadataServiceProxy).Do(req)
	if err != nil {
		switch err.(type) {
		case *url.Error:
			return text.AugmentError("Could not connect to authorization endpoint", err)
		default:
			return err
		}
	}
	defer resp.Body.Close()
	if resp.StatusCode != 200 {
		return httperror.New(resp.Status, resp.Body)
	}
	result := OAuthResponse{}
	if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
		return httperror.New(resp.Status, resp.Body)
	}
	conn.AccessToken = result.AccessToken
	return nil
}
func ( conn * RestConnection ) Refresh ( ) error { urlValues := url . Values { } urlValues . Set ( " " , " " ) urlValues . Set ( " " , conn . Username ) urlValues . Set ( " " , conn . Password ) req , err := http . NewRequest ( " " , conn . Host + " " , strings . NewReader ( urlValues . Encode ( ) ) ) if err != nil { return err } req . Header . Set ( " " , " " ) req . Header . Add ( " " , " " + VERSION ) resp , err := getClientForProxyURL ( conn . MetadataServiceProxy ) . Do ( req ) if err != nil { switch err . ( type ) { case * url . Error : return text . AugmentError ( " " , err ) default : return err } } defer resp . Body . Close ( ) if resp . StatusCode != 200 { return httperror . New ( resp . Status , resp . Body ) } result := OAuthResponse { } if err := json . NewDecoder ( resp . Body ) . Decode ( & result ) ; err != nil { return httperror . New ( resp . Status , resp . Body ) } conn . AccessToken = result . AccessToken return nil }
Refresh is used to obtain an OAuth2 access_token
Refresh is used to obtain an OAuth2 access_token