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” %}

    1. nc, err := nats.Connect("127.0.0.1", nats.UserCredentials("path_to_creds_file"))
    2. if err != nil {
    3. log.Fatal(err)
    4. }
    5. defer nc.Close()
    6. // Do something with the connection

    {% endtab %}

    {% endtab %}

    {% tab title=”JavaScript” %}

    1. // credentials file contains the JWT and the secret signing key
    2. const authenticator = credsAuthenticator(creds);
    3. port: ns.port,
    4. authenticator: authenticator,
    5. });

    {% endtab %}

    {% endtab %}

    {% tab title=”C” %}

    1. natsConnection *conn = NULL;
    2. natsOptions *opts = NULL;
    3. natsStatus s = NATS_OK;
    4. s = natsOptions_Create(&opts);
    5. if (s == NATS_OK)
    6. // Otherwise, if the content is split, the first file is the user JWT, the second
    7. // contains the seed.
    8. s = natsOptions_SetUserCredentialsFromFiles(opts, "path_to_creds_file", NULL);
    9. if (s == NATS_OK)
    10. s = natsConnection_Connect(&conn, opts);
    11. (...)
    12. // Destroy objects that were created
    13. natsOptions_Destroy(opts);

    {% endtab %} {% endtabs %}