Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add NKEYs and JWT auth #27

Merged
merged 2 commits into from
Oct 27, 2023
Merged

feat: add NKEYs and JWT auth #27

merged 2 commits into from
Oct 27, 2023

Conversation

mja00
Copy link
Contributor

@mja00 mja00 commented Oct 23, 2023

This adds support for authenticating using NKEYs and JWT following this part of the nats.js readme.

This was tested using the following as the app.js

'use strict';
const _ = require('lodash');
const spawnpoint = require('spawnpoint');
const app = new spawnpoint();

app.setup();


app.on('app.ready', function() {
	console.log('App is ready');
	// Run the following every 5 seconds
	setInterval(function() {
		// Publish a message to the NATS server
		app.nats.publish("test.1", "I'm test 2!", function() {
			console.log("Message sent!");
		});
	}, 5000);

	// Subscribe to test.1
	app.nats.subscribe("test.2", function(msg) {
		console.log("Received a message on test.2: " + msg);
	});
});

And the following as the nats.json

{
	"connection": {
		"tls": true,
		"maxReconnectAttempts": -1,
		"timeout": 10000,
		"auth": {
			"creds_file": "default.creds"
		}
	},
	"request_defaults": {
		"timeout": 5000,
		"maxMessages": -1,
		"maxWait": -1
	},
	"subscribe_prefix": ""
}

Spawnpoint was able to successfully connect and communicate over NATS.

if(config.connection.auth) {
// We want to read in the creds file given to us
const authCredsFile = path.join(app.cwd, config.connection.auth.creds_file);
delete config.connection.auth.creds_file;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is redundant as I delete the entire object on line 65 but included just in-case.

@mja00 mja00 requested a review from Cherry October 25, 2023 19:05
Copy link
Member

@Cherry Cherry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks Matt!

@Cherry Cherry merged commit 4ec318f into master Oct 27, 2023
12 checks passed
@Cherry Cherry deleted the feat/nkeys-auth branch October 27, 2023 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants