func GetClientID(ctx context.Context, clientsEndpoint string, publicClientID string, protectionAPIToken string) (string, error) {
	req, err := http.NewRequest("GET", clientsEndpoint, nil)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"err": err.Error(),
		}, "Unable to crete http request")
		return "", errors.NewInternalError("unable to crete http request " + err.Error())
	}
	req.Header.Add("Authorization", "Bearer "+protectionAPIToken)
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"public_client_id": publicClientID,
			"err":              err.Error(),
		}, "Unable to obtain keycloak client ID")
		return "", errors.NewInternalError("Unable to obtain keycloak client ID " + err.Error())
	}
	if res.StatusCode != http.StatusOK {
		log.Error(ctx, map[string]interface{}{
			"public_client_id": publicClientID,
			"response_status":  res.Status,
			"response_body":    rest.ReadBody(res.Body),
		}, "Unable to obtain keycloak client ID")
		return "", errors.NewInternalError("Unable to obtain keycloak client ID. Response status: " + res.Status + ". Responce body: " + rest.ReadBody(res.Body))
	}
	jsonString := rest.ReadBody(res.Body)

	var r []clientData
	err = json.Unmarshal([]byte(jsonString), &r)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"public_client_id": publicClientID,
			"err":              err.Error(),
		}, "Unable to unmarshal json with client ID")
		return "", errors.NewInternalError(fmt.Sprintf("error when unmarshal json with client ID result %s ", jsonString) + err.Error())
	}
	for _, client := range r {
		if publicClientID == client.ClientID {
			return client.ID, nil
		}
	}
	log.Error(ctx, map[string]interface{}{
		"public_client_id": publicClientID,
		"json":             jsonString,
	}, "Unable to find client ID '"+publicClientID+"' among available IDs: "+jsonString)
	return "", errors.NewInternalError("Unable to find keycloak client ID")
}
// GetClientID obtains the internal client ID associated with keycloak client
GetClientID obtains the internal client ID associated with keycloak client
// GetClientID obtains the internal client ID associated with keycloak client
func GetClientID(ctx context.Context, clientsEndpoint string, publicClientID string, protectionAPIToken string) (string, error) {
	req, err := http.NewRequest("GET", clientsEndpoint, nil)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"err": err.Error(),
		}, "Unable to crete http request")
		return "", errors.NewInternalError("unable to crete http request " + err.Error())
	}
	req.Header.Add("Authorization", "Bearer "+protectionAPIToken)
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"public_client_id": publicClientID,
			"err":              err.Error(),
		}, "Unable to obtain keycloak client ID")
		return "", errors.NewInternalError("Unable to obtain keycloak client ID " + err.Error())
	}
	if res.StatusCode != http.StatusOK {
		log.Error(ctx, map[string]interface{}{
			"public_client_id": publicClientID,
			"response_status":  res.Status,
			"response_body":    rest.ReadBody(res.Body),
		}, "Unable to obtain keycloak client ID")
		return "", errors.NewInternalError("Unable to obtain keycloak client ID. Response status: " + res.Status + ". Responce body: " + rest.ReadBody(res.Body))
	}
	jsonString := rest.ReadBody(res.Body)
	var r []clientData
	err = json.Unmarshal([]byte(jsonString), &r)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"public_client_id": publicClientID,
			"err":              err.Error(),
		}, "Unable to unmarshal json with client ID")
		return "", errors.NewInternalError(fmt.Sprintf("error when unmarshal json with client ID result %s ", jsonString) + err.Error())
	}
	for _, client := range r {
		if publicClientID == client.ClientID {
			return client.ID, nil
		}
	}
	log.Error(ctx, map[string]interface{}{
		"public_client_id": publicClientID,
		"json":             jsonString,
	}, "Unable to find client ID '"+publicClientID+"' among available IDs: "+jsonString)
	return "", errors.NewInternalError("Unable to find keycloak client ID")
}
func GetClientID ( ctx context . Context , clientsEndpoint string , publicClientID string , protectionAPIToken string ) ( string , error ) { req , err := http . NewRequest ( " " , clientsEndpoint , nil ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : err . Error ( ) , } , " " ) return " " , errors . NewInternalError ( " " + err . Error ( ) ) } req . Header . Add ( " " , " " + protectionAPIToken ) res , err := http . DefaultClient . Do ( req ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : publicClientID , " " : err . Error ( ) , } , " " ) return " " , errors . NewInternalError ( " " + err . Error ( ) ) } if res . StatusCode != http . StatusOK { log . Error ( ctx , map [ string ] interface { } { " " : publicClientID , " " : res . Status , " " : rest . ReadBody ( res . Body ) , } , " " ) return " " , errors . NewInternalError ( " " + res . Status + " " + rest . ReadBody ( res . Body ) ) } jsonString := rest . ReadBody ( res . Body ) var r [ ] clientData err = json . Unmarshal ( [ ] byte ( jsonString ) , & r ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : publicClientID , " " : err . Error ( ) , } , " " ) return " " , errors . NewInternalError ( fmt . Sprintf ( " " , jsonString ) + err . Error ( ) ) } for _ , client := range r { if publicClientID == client . ClientID { return client . ID , nil } } log . Error ( ctx , map [ string ] interface { } { " " : publicClientID , " " : jsonString , } , " " + publicClientID + " " + jsonString ) return " " , errors . NewInternalError ( " " ) }
GetClientID obtains the internal client ID associated with keycloak client
GetClientID obtains the internal client ID associated with keycloak client