aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/oauth.ts
diff options
context:
space:
mode:
authorbuoyantair <buoyantair@protonmail.com>2018-11-18 21:55:52 +0530
committerbuoyantair <buoyantair@protonmail.com>2018-11-18 21:55:52 +0530
commitb9f234371bfaf0d9cfa81e02fcea92cac1f9ae13 (patch)
treedcdf451ac431ec7953bee58e814f642d1c370d1b /server/middlewares/oauth.ts
parent92e07c3b5d9dbf2febedb1b5b87ec676eb6d1ac8 (diff)
parent9d0b856e930ee1c676d16a56408a3e4a18f8f978 (diff)
downloadPeerTube-b9f234371bfaf0d9cfa81e02fcea92cac1f9ae13.tar.gz
PeerTube-b9f234371bfaf0d9cfa81e02fcea92cac1f9ae13.tar.zst
PeerTube-b9f234371bfaf0d9cfa81e02fcea92cac1f9ae13.zip
Merge branch 'develop' of https://github.com/Chocobozzz/PeerTube into move-utils-to-shared
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}