Authenticating with a Credentials File
Given a creds file, a client can authenticate as a specific user belonging to a specific account:
{% tabs %} {% tab title=”Go” %}
nc, err := nats.Connect("127.0.0.1", nats.UserCredentials("path_to_creds_file"))
if err != nil {
log.Fatal(err)
}
defer nc.Close()
// Do something with the connection
{% endtab %}
{% endtab %}
{% tab title=”JavaScript” %}
// credentials file contains the JWT and the secret signing key
const authenticator = credsAuthenticator(creds);
port: ns.port,
authenticator: authenticator,
});
{% endtab %}
{% endtab %}
{% tab title=”C” %}
natsConnection *conn = NULL;
natsOptions *opts = NULL;
natsStatus s = NATS_OK;
s = natsOptions_Create(&opts);
if (s == NATS_OK)
// Otherwise, if the content is split, the first file is the user JWT, the second
// contains the seed.
s = natsOptions_SetUserCredentialsFromFiles(opts, "path_to_creds_file", NULL);
if (s == NATS_OK)
s = natsConnection_Connect(&conn, opts);
(...)
// Destroy objects that were created
natsOptions_Destroy(opts);
{% endtab %} {% endtabs %}