0.0.6 • Published 6 years ago
get-auth-token-middleware v0.0.6
Get auth token middleware
This is middleware handler for Express.js applications. It can authenticate application against third party service. Authentication result will be saved in context.result
field for later usage.
// Initialize middleware
const http = require('http');
const GetAuthTokenMiddleware = require('get-auth-token-middleware');
const context = {
endpoint: {
hostname: 'localhost',
port: 80,
path: '/api/users/login',
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
},
body: {
login: 'root',
password: 'P@ssw0rd'
},
result: {}
};
const middleware = new GetAuthTokenMiddleware(context, http);
const handler = middleware.handle.bind(middleware);
// Bind to Express.js app
app.use(handler);
Returned response content will be attached to context.result
.