func ValidateKeycloakUser(ctx context.Context, adminEndpoint string, userID, protectionAPIToken string) (bool, error) {
	req, err := http.NewRequest("GET", adminEndpoint+"/users/"+userID, nil)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"err": err.Error(),
		}, "Unable to crete http request")
		return false, 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{}{
			"user_id": userID,
			"err":     err.Error(),
		}, "Unable to get user from Keycloak")
		return false, errors.NewInternalError("Unable to get user from Keycloak " + err.Error())
	}
	switch res.StatusCode {
	case http.StatusOK:
		return true, nil
	case http.StatusNotFound:
		return false, nil
	default:
		log.Error(ctx, map[string]interface{}{
			"user_id": userID,
		}, "Unable to get user from Keycloak")
		return false, errors.NewInternalError("Unable to get user from Keycloak. Response status: " + res.Status + ". Responce body: " + rest.ReadBody(res.Body))
	}
}
// ValidateKeycloakUser returns true if the user exists in Keyclaok. Returns false if the user is not found
ValidateKeycloakUser returns true if the user exists in Keyclaok. Returns false if the user is not found
// ValidateKeycloakUser returns true if the user exists in Keyclaok . Returns false if the user is not found
func ValidateKeycloakUser(ctx context.Context, adminEndpoint string, userID, protectionAPIToken string) (bool, error) {
	req, err := http.NewRequest("GET", adminEndpoint+"/users/"+userID, nil)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"err": err.Error(),
		}, "Unable to crete http request")
		return false, 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{}{
			"user_id": userID,
			"err":     err.Error(),
		}, "Unable to get user from Keycloak")
		return false, errors.NewInternalError("Unable to get user from Keycloak " + err.Error())
	}
	switch res.StatusCode {
	case http.StatusOK:
		return true, nil
	case http.StatusNotFound:
		return false, nil
	default:
		log.Error(ctx, map[string]interface{}{
			"user_id": userID,
		}, "Unable to get user from Keycloak")
		return false, errors.NewInternalError("Unable to get user from Keycloak. Response status: " + res.Status + ". Responce body: " + rest.ReadBody(res.Body))
	}
}
func ValidateKeycloakUser ( ctx context . Context , adminEndpoint string , userID , protectionAPIToken string ) ( bool , error ) { req , err := http . NewRequest ( " " , adminEndpoint + " " + userID , nil ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : err . Error ( ) , } , " " ) return false , errors . NewInternalError ( " " + err . Error ( ) ) } req . Header . Add ( " " , " " + protectionAPIToken ) res , err := http . DefaultClient . Do ( req ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : userID , " " : err . Error ( ) , } , " " ) return false , errors . NewInternalError ( " " + err . Error ( ) ) } switch res . StatusCode { case http . StatusOK : return true , nil case http . StatusNotFound : return false , nil default : log . Error ( ctx , map [ string ] interface { } { " " : userID , } , " " ) return false , errors . NewInternalError ( " " + res . Status + " " + rest . ReadBody ( res . Body ) ) } }
ValidateKeycloakUser returns true if the user exists in Keyclaok.
ValidateKeycloakUser returns true if the user exists in Keyclaok .