aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/oauth.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-19 11:01:34 +0200
committerChocobozzz <me@florianbigard.com>2018-04-19 11:01:34 +0200
commit0883b3245bf0deb9106c4041e9afbd3521b79280 (patch)
treefcb73005e0b31a3b763ee5d22d5fc39c2da89907 /server/middlewares/oauth.ts
parent04ed10b21e8e1339514faae0bb690e4d97c23b0a (diff)
downloadPeerTube-0883b3245bf0deb9106c4041e9afbd3521b79280.tar.gz
PeerTube-0883b3245bf0deb9106c4041e9afbd3521b79280.tar.zst
PeerTube-0883b3245bf0deb9106c4041e9afbd3521b79280.zip
Add ability to choose what policy we have for NSFW videos
There is a global instance setting and a per user setting
Diffstat (limited to 'server/middlewares/oauth.ts')
-rw-r--r--server/middlewares/oauth.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts
index 41a3fb718..a6f28dd5b 100644
--- a/server/middlewares/oauth.ts
+++ b/server/middlewares/oauth.ts
@@ -2,6 +2,7 @@ import * as express from 'express'
2import * as OAuthServer from 'express-oauth-server' 2import * as OAuthServer from 'express-oauth-server'
3import 'express-validator' 3import 'express-validator'
4import { OAUTH_LIFETIME } from '../initializers' 4import { OAUTH_LIFETIME } from '../initializers'
5import { logger } from '../helpers/logger'
5 6
6const oAuthServer = new OAuthServer({ 7const oAuthServer = new OAuthServer({
7 useErrorHandler: true, 8 useErrorHandler: true,
@@ -13,6 +14,8 @@ const oAuthServer = new OAuthServer({
13function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) { 14function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) {
14 oAuthServer.authenticate()(req, res, err => { 15 oAuthServer.authenticate()(req, res, err => {
15 if (err) { 16 if (err) {
17 logger.warn('Cannot authenticate.', { err })
18
16 return res.status(err.status) 19 return res.status(err.status)
17 .json({ 20 .json({
18 error: 'Token is invalid.', 21 error: 'Token is invalid.',
@@ -25,6 +28,12 @@ function authenticate (req: express.Request, res: express.Response, next: expres
25 }) 28 })
26} 29}
27 30
31function optionalAuthenticate (req: express.Request, res: express.Response, next: express.NextFunction) {
32 if (req.header('authorization')) return authenticate(req, res, next)
33
34 return next()
35}
36
28function token (req: express.Request, res: express.Response, next: express.NextFunction) { 37function token (req: express.Request, res: express.Response, next: express.NextFunction) {
29 return oAuthServer.token()(req, res, err => { 38 return oAuthServer.token()(req, res, err => {
30 if (err) { 39 if (err) {
@@ -44,5 +53,6 @@ function token (req: express.Request, res: express.Response, next: express.NextF
44 53
45export { 54export {
46 authenticate, 55 authenticate,
56 optionalAuthenticate,
47 token 57 token
48} 58}