github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/uaa/ssh.go (about)

     1  package uaa
     2  
     3  import (
     4  	"net/url"
     5  
     6  	"code.cloudfoundry.org/cli/api/uaa/internal"
     7  )
     8  
     9  func (client *Client) GetSSHPasscode(accessToken string, sshOAuthClient string) (string, error) {
    10  	queryValues := url.Values{}
    11  	queryValues.Add("response_type", "code")
    12  	queryValues.Add("client_id", sshOAuthClient)
    13  
    14  	request, err := client.newRequest(requestOptions{
    15  		RequestName: internal.GetSSHPasscodeRequest,
    16  		Query:       queryValues,
    17  	})
    18  	if err != nil {
    19  		return "", err
    20  	}
    21  
    22  	response := Response{}
    23  	err = client.connection.Make(request, &response)
    24  	if err != nil {
    25  		return "", err
    26  	}
    27  
    28  	locationURL, err := response.HTTPResponse.Location()
    29  	if err != nil {
    30  		return "", err
    31  	}
    32  
    33  	return locationURL.Query().Get("code"), nil
    34  }