Hi All,
Actually my neo4j db is in client vm. So i am using certs mentioned in neo4j.conf to get connection while doing that getting below error. Since i am trying to connect with neo4j which is at client vm i dont know the password. when i log in system and give neo4j it will redirect to neo4j command line i tried to get password but getting grant related errors from neo4j.
Error :
Unable to retrieve routing table from ocua.prodapt.com:7687: Server error: [Neo.ClientError.Security.Unauthorized] The client is unauthorized due to authentication failure.
Can anyone tell me whether there is anything wrong in the code i have used:
code i have used:
package main
import (
"crypto/tls"
"log"
"net/http"
"github.com/neo4j/neo4j-go-driver/neo4j"
)
func main() {
// Load your custom certificates
cert, err := tls.LoadX509KeyPair("/certs/Host.crt", "/certs/Host.key")
if err != nil {
log.Fatal(err)
}
// Create a custom TLS configuration
tlsConfig := &tls.Config{
InsecureSkipVerify: false, // Set this to true for testing (not recommended for production)
Certificates: []tls.Certificate{cert},
}
// Set up a custom HTTP client with the custom transport
customTransport := &http.Transport{
TLSClientConfig: tlsConfig,
}
http.DefaultTransport = customTransport
// Create a Neo4j driver with custom TLS configuration
driver, err := neo4j.NewDriver(
"bolt+routing://ocua.prodapt.com:7687",
neo4j.BasicAuth("assure1", "", ""),
)
if err != nil {
log.Fatalf("Driver configuration Error: %v", err)
}
defer driver.Close()
log.Printf("Driver configuration: %v", driver)
session, err := driver.NewSession(neo4j.SessionConfig{})
if err != nil {
log.Fatalf("Session Error: %v", err)
}
defer session.Close()
log.Printf("Session opened: %v", session)
result, err := session.ReadTransaction(func(tx neo4j.Transaction) (interface{}, error) {
result, err := tx.Run("MATCH (n) RETURN n LIMIT 10", nil)
if err != nil {
return nil, err
}
var records []interface{}
for result.Next() {
record := result.Record()
records = append(records, record)
}
return records, err
})
if err != nil {
log.Fatalf("Query Error: %v", err)
}
log.Printf("Result: %v", result)
if result != nil {
records := result.([]interface{})
for _, record := range records {
log.Printf("%#v", record)
}
}
}