aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/oauth.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-11-16 15:02:48 +0100
committerChocobozzz <me@florianbigard.com>2018-11-16 15:49:16 +0100
commit8d4273463fb19d503b1aa0a32dc289f292ed614e (patch)
treef422773ecba3405bb5808bed8e25b62ac6b7ea08 /server/middlewares/oauth.ts
parent5776f78e3b3f3a371ec30c7fcb11e7ca17f2f65e (diff)
downloadPeerTube-8d4273463fb19d503b1aa0a32dc289f292ed614e.tar.gz
PeerTube-8d4273463fb19d503b1aa0a32dc289f292ed614e.tar.zst
PeerTube-8d4273463fb19d503b1aa0a32dc289f292ed614e.zip
Check follow constraints when getting a video
Diffstat (limited to 'server/middlewares/oauth.ts')
-rw-r--r--server/middlewares/oauth.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts
index 5233b66bd..8c1df2c3e 100644
--- a/server/middlewares/oauth.ts
+++ b/server/middlewares/oauth.ts
@@ -28,9 +28,24 @@ function authenticate (req: express.Request, res: express.Response, next: expres
28 }) 28 })
29} 29}
30 30
31function authenticatePromiseIfNeeded (req: express.Request, res: express.Response) {
32 return new Promise(resolve => {
33 // Already authenticated? (or tried to)
34 if (res.locals.oauth && res.locals.oauth.token.User) return resolve()
35
36 if (res.locals.authenticated === false) return res.sendStatus(401)
37
38 authenticate(req, res, () => {
39 return resolve()
40 })
41 })
42}
43
31function optionalAuthenticate (req: express.Request, res: express.Response, next: express.NextFunction) { 44function optionalAuthenticate (req: express.Request, res: express.Response, next: express.NextFunction) {
32 if (req.header('authorization')) return authenticate(req, res, next) 45 if (req.header('authorization')) return authenticate(req, res, next)
33 46
47 res.locals.authenticated = false
48
34 return next() 49 return next()
35} 50}
36 51
@@ -53,6 +68,7 @@ function token (req: express.Request, res: express.Response, next: express.NextF
53 68
54export { 69export {
55 authenticate, 70 authenticate,
71 authenticatePromiseIfNeeded,
56 optionalAuthenticate, 72 optionalAuthenticate,
57 token 73 token
58} 74}