]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/oauth.ts
Update FAQ
[github/Chocobozzz/PeerTube.git] / server / middlewares / oauth.ts
index bd60a36399d3d2e7d8efc89c78996801b2742b5c..ffc1b7ca9532a780d255ac5ad856fdfa5a25f17f 100644 (file)
@@ -3,6 +3,7 @@ import { Socket } from 'socket.io'
 import { oAuthServer } from '@server/lib/auth'
 import { logger } from '../helpers/logger'
 import { getAccessToken } from '../lib/oauth-model'
+import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
 
 function authenticate (req: express.Request, res: express.Response, next: express.NextFunction, authenticateInQuery = false) {
   const options = authenticateInQuery ? { allowBearerTokensInQueryString: true } : {}
@@ -19,6 +20,8 @@ function authenticate (req: express.Request, res: express.Response, next: expres
         .end()
     }
 
+    res.locals.authenticated = true
+
     return next()
   })
 }
@@ -50,7 +53,7 @@ function authenticatePromiseIfNeeded (req: express.Request, res: express.Respons
     // Already authenticated? (or tried to)
     if (res.locals.oauth?.token.User) return resolve()
 
-    if (res.locals.authenticated === false) return res.sendStatus(401)
+    if (res.locals.authenticated === false) return res.sendStatus(HttpStatusCode.UNAUTHORIZED_401)
 
     authenticate(req, res, () => resolve(), authenticateInQuery)
   })