grpc.github.io icon indicating copy to clipboard operation
grpc.github.io copied to clipboard

Mutual auth example in Node

Open zinuga opened this issue 9 years ago • 2 comments

Would very much like examples on how to do mutual auth on node. Its pretty easily done in Go, but in node, its not at all clear from the docs.

For example, this is what they'd like to do in node. Do we have any examples in node to publish (infact, I'd say we publish in all languages)

cer, err := tls.LoadX509KeyPair("./certs/client.crt", "./certs/client.key") if err != nil { fmt.Printf("Error, could not load key and/or cert files %v\n", err) return }

rootCAs := x509.NewCertPool()
pemData, err := ioutil.ReadFile("./certs/ca.crt")
if err != nil {
    fmt.Printf("Error, could not load cert file: %v\n", err)
    return
}
rootCAs.AppendCertsFromPEM(pemData)

config := &tls.Config{
    Certificates: []tls.Certificate{cer},
    RootCAs: rootCAs,
}   

creds := credentials.NewTLS(config)
conn, err := grpc.Dial("localhost:9012", grpc.WithTransportCredentials(creds))

zinuga avatar Jun 24 '16 17:06 zinuga

@murgatroid99 @LisaFC we should add this after GA

zinuga avatar Jul 21 '16 17:07 zinuga

@murgatroid99 , can fix/close this?

jtattermusch avatar Dec 12 '17 20:12 jtattermusch