func (m *AppIDManager) ROP(username string, password string) error {
	form := url.Values{
		"client_id":  {m.ClientID},
		"grant_type": {"password"},
		"username":   {username},
		"password":   {password},
	}
	req, err := http.NewRequest("POST", m.TokenURL(), strings.NewReader(form.Encode()))
	if err != nil {
		zap.L().Error("Could not serialize HTTP request", zap.Error(err))
		return err
	}
	req.SetBasicAuth(m.ClientID, m.ClientSecret)
	req.Header.Set(contentType, applicationFormEncoded)
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		return err
	}
	if res.StatusCode != http.StatusOK {
		return fmt.Errorf(res.Status)
	}
	var tokenResponse authserver.TokenResponse
	if err := json.NewDecoder(res.Body).Decode(&tokenResponse); err != nil {
		str, _ := ioutil.ReadAll(res.Body)
		return fmt.Errorf("body %s | %s", string(str), err)
	}
	m.Tokens = &tokenResponse
	return nil
}
ROP issues an ROP token flow again the authorization server instance
package framework
import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"os"
	"strings"
	"testing"
	"github.com/PuerkitoBio/goquery"
	"github.com/stretchr/testify/require"
	"go.uber.org/zap"
	"github.com/ibm-cloud-security/app-identity-and-access-adapter/adapter/authserver"
)
const (
	DefaultUsername = "username@ibm.com"
	DefaultPassword = "password"
	clientID        = "APPID_CLIENT_ID"
	clientSecret    = "APPID_CLIENT_SECRET"
	oauthServerUrl  = "APPID_OAUTH_SERVER_URL"
)
const (
	tokenEndpoint          = "/token"
	publicKeysEndpoint     = "/publickeys"
	discoveryEndpoint      = "/.well-known/openid-configuration"
	appIDCDAuthEndpoint    = "/cloud_directory/auth"
	callbackEndpoint       = "/oidc/callback"
	applicationFormEncoded = "application/x-www-form-urlencoded"
	contentType            = "Content-Type"
	setCookie              = "set-cookie"
	widgetURLID            = "#widgetUrl"
	stateID                = "#cd_form input[name='state']"
)
type AppIDManager struct {
	ClientID       string
	ClientSecret   string
	OAuthServerURL string
	Tokens         *authserver.TokenResponse
	client         *http.Client
}
func NewAppIDManager() *AppIDManager {
	return &AppIDManager{
		os.Getenv(clientID),
		os.Getenv(clientSecret),
		os.Getenv(oauthServerUrl),
		nil,
		&http.Client{
			CheckRedirect: func(req *http.Request, via []*http.Request) error {
				return http.ErrUseLastResponse
			},
		},
	}
}
func (m *AppIDManager) OK() bool {
	return m.ClientID != "" && m.ClientSecret != "" && m.OAuthServerURL != "" && m.client != nil
}
func (m *AppIDManager) TokenURL() string {
	return m.OAuthServerURL + tokenEndpoint
}
func (m *AppIDManager) PublicKeysURL() string {
	return m.OAuthServerURL + publicKeysEndpoint
}
func (m *AppIDManager) DiscoveryURL() string {
	return m.OAuthServerURL + discoveryEndpoint
}
func (m *AppIDManager) LoginToCloudDirectory(t *testing.T, root string, path string, output interface{}) error {
	stateCookie, state, widgetURL := m.initialRequestToFrontend(t, root+path)
	require.NotNil(t, stateCookie)
	require.NotEmpty(t, state)
	require.NotEmpty(t, widgetURL)
	adapterCallbackURL, err := m.postCredentialsFromWidget(root+path+callbackEndpoint, state, widgetURL)
	require.NoError(t, err)
	oidcCookie, adapterOriginalURL, err := m.forwardRedirectToAdapter(adapterCallbackURL, stateCookie)
	require.NoError(t, err)
	return m.sendAuthenticatedRequest(adapterOriginalURL, oidcCookie, output)
}