Authenticating with a Token
nats-server --auth mytokenConnecting with a Token
// Set a token
nc, err := nats.Connect("127.0.0.1", nats.Name("API Token Example"), nats.Token("mytoken"))
if err != nil {
log.Fatal(err)
}
defer nc.Close()
// Do something with the connectionOptions options = new Options.Builder()
.server("nats://demo.nats.io:4222")
.token("mytoken") // Set a token
.build();
Connection nc = Nats.connect(options);
// Do something with the connection
nc.close();const nc = await connect({
port: ns.port,
token: "aToK3n",
});Connecting with a Token in the URL
Last updated
Was this helpful?