diff --git a/SUMMARY.md b/SUMMARY.md index c627812..2dce020 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -75,6 +75,8 @@ * [Securing Connections](developer/security/intro.md) * [Authenticating with a User and Password](developer/security/userpass.md) * [Authenticating with a Token](developer/security/token.md) + * [Authenticating with an NKey](developer/security/nkey.md) + * [Authenticating with a Credentials File](developer/security/creds.md) * [Encrypting Connections with TLS](developer/security/tls.md) * [Receiving Messages](developer/receiving/intro.md) diff --git a/_examples/connect_creds.html b/_examples/connect_creds.html new file mode 100644 index 0000000..8f8725d --- /dev/null +++ b/_examples/connect_creds.html @@ -0,0 +1,24 @@ + +
NKey theNKey = NKey.createUser(null); // really should load from somewhere
+Options options = new Options.Builder().
+ server("nats://localhost:4222").
+ authHandler(new AuthHandler(){
+ public char[] getID() {
+ try {
+ return theNKey.getPublicKey();
+ } catch (GeneralSecurityException|IOException|NullPointerException ex) {
+ return null;
+ }
+ }
+
+ public byte[] sign(byte[] nonce) {
+ try {
+ return theNKey.sign(nonce);
+ } catch (GeneralSecurityException|IOException|NullPointerException ex) {
+ return null;
+ }
+ }
+
+ public char[] getJWT() {
+ return null;
+ }
+ }).
+ build();
+Connection nc = Nats.connect(options);
+
+// Do something with the connection
+
+nc.close();
+
+