My Feathers application needs to be able to have two JWT authentication strategies. For the users
service, I need to have, for example, all: [authenticate('carrier')]
instead of all: [authenticate('jwt')]
in my hooks. For the rest of the services, authenticate['jwt']
is needed.
For this, I have registered a custom strategy in authentication.js called CarrierStrategy
as following:
module.exports = function auth(app) {
const authentication = new AuthenticationService(app)
// register all of the strategies with authentication service
authentication.register('carrier', new CarrierStrategy())
authentication.register('jwt', new JWTStrategy())
// register the authentication service with your app
app.use('/api/authentication', authentication)
}
In config/default.json, I have also registered this strategy as following:
authStrategies: ["carrier", "jwt"]
The CarrierStrategy needs to handle the incoming Authorization header a little differently with some custom logic.
When I use Postman to send requests for this service, i.e., localhost:3030/users
with a JWT token in the header, I get the following error.
Invalid authentication information (strategy not allowed in authStrategies)'
Please guide me if this is the right way to add a custom strategy to the application.