/**
* @module flitter-auth/middleware/Oauth2TokenOnly
*/
const Middleware = require('libflitter/middleware/Middleware')
/**
* Allows a request to proceed if a valid OAuth2 bearer token was provided.
* If not, return a JSON-encoded error message.
* @extends module:libflitter/middleware/Middleware~Middleware
*/
class Oauth2TokenOnly extends Middleware {
/**
* Runs the middleware's test. Allows the request to proceed only
* if a valid OAuth2 bearer token was provided.
* @param {express/request} req - the request
* @param {express/response} res - the response
* @param {function} next - the next function in the stack
* @param {object} [args = {}] - optional args
* @returns {*}
*/
test(req, res, next, args = {}){
return req.app.oauth2.authorise()(req, res, next)
}
}
module.exports = Oauth2TokenOnly