aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/auth.ts
diff options
context:
space:
mode:
authorWicklow <123956049+wickloww@users.noreply.github.com>2023-06-29 07:48:55 +0000
committerGitHub <noreply@github.com>2023-06-29 09:48:55 +0200
commit40346ead2b0b7afa475aef057d3673b6c7574b7a (patch)
tree24ffdc23c3a9d987334842e0d400b5bd44500cf7 /server/middlewares/auth.ts
parentae22c59f14d0d553f60b281948b6c232c2aca178 (diff)
downloadPeerTube-40346ead2b0b7afa475aef057d3673b6c7574b7a.tar.gz
PeerTube-40346ead2b0b7afa475aef057d3673b6c7574b7a.tar.zst
PeerTube-40346ead2b0b7afa475aef057d3673b6c7574b7a.zip
Feature/password protected videos (#5836)
* Add server endpoints * Refactoring test suites * Update server and add openapi documentation * fix compliation and tests * upload/import password protected video on client * add server error code * Add video password to update resolver * add custom message when sharing pw protected video * improve confirm component * Add new alert in component * Add ability to watch protected video on client * Cannot have password protected replay privacy * Add migration * Add tests * update after review * Update check params tests * Add live videos test * Add more filter test * Update static file privacy test * Update object storage tests * Add test on feeds * Add missing word * Fix tests * Fix tests on live videos * add embed support on password protected videos * fix style * Correcting data leaks * Unable to add password protected privacy on replay * Updated code based on review comments * fix validator and command * Updated code based on review comments
Diffstat (limited to 'server/middlewares/auth.ts')
-rw-r--r--server/middlewares/auth.ts15
1 files changed, 12 insertions, 3 deletions
diff --git a/server/middlewares/auth.ts b/server/middlewares/auth.ts
index 0eefa2a8e..39a7b2998 100644
--- a/server/middlewares/auth.ts
+++ b/server/middlewares/auth.ts
@@ -5,6 +5,7 @@ import { RunnerModel } from '@server/models/runner/runner'
5import { HttpStatusCode } from '../../shared/models/http/http-error-codes' 5import { HttpStatusCode } from '../../shared/models/http/http-error-codes'
6import { logger } from '../helpers/logger' 6import { logger } from '../helpers/logger'
7import { handleOAuthAuthenticate } from '../lib/auth/oauth' 7import { handleOAuthAuthenticate } from '../lib/auth/oauth'
8import { ServerErrorCode } from '@shared/models'
8 9
9function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) { 10function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) {
10 handleOAuthAuthenticate(req, res) 11 handleOAuthAuthenticate(req, res)
@@ -48,15 +49,23 @@ function authenticateSocket (socket: Socket, next: (err?: any) => void) {
48 .catch(err => logger.error('Cannot get access token.', { err })) 49 .catch(err => logger.error('Cannot get access token.', { err }))
49} 50}
50 51
51function authenticatePromise (req: express.Request, res: express.Response) { 52function authenticatePromise (options: {
53 req: express.Request
54 res: express.Response
55 errorMessage?: string
56 errorStatus?: HttpStatusCode
57 errorType?: ServerErrorCode
58}) {
59 const { req, res, errorMessage = 'Not authenticated', errorStatus = HttpStatusCode.UNAUTHORIZED_401, errorType } = options
52 return new Promise<void>(resolve => { 60 return new Promise<void>(resolve => {
53 // Already authenticated? (or tried to) 61 // Already authenticated? (or tried to)
54 if (res.locals.oauth?.token.User) return resolve() 62 if (res.locals.oauth?.token.User) return resolve()
55 63
56 if (res.locals.authenticated === false) { 64 if (res.locals.authenticated === false) {
57 return res.fail({ 65 return res.fail({
58 status: HttpStatusCode.UNAUTHORIZED_401, 66 status: errorStatus,
59 message: 'Not authenticated' 67 type: errorType,
68 message: errorMessage
60 }) 69 })
61 } 70 }
62 71