PeerTube/server/middlewares/oauth2.js

36 lines
754 B
JavaScript
Raw Normal View History

2016-03-21 05:56:33 -05:00
'use strict'
const OAuthServer = require('express-oauth-server')
const logger = require('../helpers/logger')
const oAuthServer = new OAuthServer({
2016-03-21 05:56:33 -05:00
model: require('../models/users')
})
const oAuth2 = {
authenticate: authenticate,
token: token
}
function authenticate (req, res, next) {
oAuthServer.authenticate()(req, res, function (err) {
if (err) {
logger.error('Cannot authenticate.', { error: err })
return res.sendStatus(500)
}
if (res.statusCode === 401 || res.statusCode === 400) return res.end()
return next()
})
}
function token (req, res, next) {
return oAuthServer.token()(req, res, next)
}
2016-03-21 05:56:33 -05:00
// ---------------------------------------------------------------------------
module.exports = oAuth2