Authentication and Authorization for Mosca using Seneca and Seneca User.
This is a specialization of Seneca User
for this specific use case. Go there and have a look for the full
docs. The default role is changed from 'user'
to 'mosca-auth'
.
npm i mosca seneca-mosca-auth --save
'use strict'
const Mosca = require('mosca')
const Seneca = require('seneca')
const MoscaAuth = require('seneca-mosca-auth')
var seneca = Seneca()
seneca.use(MoscaAuth)
var server = new Mosca.Server()
// configures Mosca to authenticate via seneca
MoscaAuth.setup(seneca, server)
// register a user
seneca.act({
role: 'mosca-auth',
cmd: 'register',
nick: 'mydevice',
email: 'matteo.collina@nearform.com',
password: 'mypassword',
publishPatterns: ['hello', 'a/#', 'b/+'],
subscribePatterns: ['hello', 'a/#', 'b/+']
})
This project was kindly sponsored by nearForm.
MIT