func GetProtectedAPIToken(openidConnectTokenURL string, clientID string, clientSecret string) (string, error) {
	client := &http.Client{Timeout: 10 * time.Second}
	res, err := client.PostForm(openidConnectTokenURL, url.Values{
		"client_id":     {clientID},
		"client_secret": {clientSecret},
		"grant_type":    {"client_credentials"},
	})
	if err != nil {
		return "", errors.NewInternalError("Error when obtaining token " + err.Error())
	}
	switch res.StatusCode {
	case http.StatusOK:
		// OK
	case http.StatusUnauthorized:
		return "", errors.NewUnauthorizedError(res.Status + " " + rest.ReadBody(res.Body))
	case http.StatusBadRequest:
		return "", errors.NewBadParameterError(rest.ReadBody(res.Body), nil)
	default:
		return "", errors.NewInternalError(res.Status + " " + rest.ReadBody(res.Body))
	}

	token, err := ReadToken(res)
	if err != nil {
		return "", err
	}
	return *token.AccessToken, nil
}
// GetProtectedAPIToken obtains a Protected API Token (PAT) from Keycloak
GetProtectedAPIToken obtains a Protected API Token (PAT) from Keycloak
// GetProtectedAPIToken obtains a Protected API Token ( PAT ) from Keycloak
func GetProtectedAPIToken(openidConnectTokenURL string, clientID string, clientSecret string) (string, error) {
	client := &http.Client{Timeout: 10 * time.Second}
	res, err := client.PostForm(openidConnectTokenURL, url.Values{
		"client_id":     {clientID},
		"client_secret": {clientSecret},
		"grant_type":    {"client_credentials"},
	})
	if err != nil {
		return "", errors.NewInternalError("Error when obtaining token " + err.Error())
	}
	switch res.StatusCode {
	case http.StatusOK:
	case http.StatusUnauthorized:
		return "", errors.NewUnauthorizedError(res.Status + " " + rest.ReadBody(res.Body))
	case http.StatusBadRequest:
		return "", errors.NewBadParameterError(rest.ReadBody(res.Body), nil)
	default:
		return "", errors.NewInternalError(res.Status + " " + rest.ReadBody(res.Body))
	}
	token, err := ReadToken(res)
	if err != nil {
		return "", err
	}
	return *token.AccessToken, nil
}
func GetProtectedAPIToken ( openidConnectTokenURL string , clientID string , clientSecret string ) ( string , error ) { client := & http . Client { Timeout : 10 * time . Second } res , err := client . PostForm ( openidConnectTokenURL , url . Values { " " : { clientID } , " " : { clientSecret } , " " : { " " } , } ) if err != nil { return " " , errors . NewInternalError ( " " + err . Error ( ) ) } switch res . StatusCode { case http . StatusOK : case http . StatusUnauthorized : return " " , errors . NewUnauthorizedError ( res . Status + " " + rest . ReadBody ( res . Body ) ) case http . StatusBadRequest : return " " , errors . NewBadParameterError ( rest . ReadBody ( res . Body ) , nil ) default : return " " , errors . NewInternalError ( res . Status + " " + rest . ReadBody ( res . Body ) ) } token , err := ReadToken ( res ) if err != nil { return " " , err } return * token . AccessToken , nil }
GetProtectedAPIToken obtains a Protected API Token (PAT) from Keycloak
GetProtectedAPIToken obtains a Protected API Token ( PAT ) from Keycloak
// OK