diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-12-07 14:32:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 14:32:36 +0100 |
commit | 2d53be0267acc49cda46707b885096193a1f4e9c (patch) | |
tree | 887061a34bc67f40acbb96a6278f9544bf83caeb /server/middlewares/oauth.ts | |
parent | adc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff) | |
download | PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip |
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'server/middlewares/oauth.ts')
-rw-r--r-- | server/middlewares/oauth.ts | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts index bd60a3639..ab5301415 100644 --- a/server/middlewares/oauth.ts +++ b/server/middlewares/oauth.ts | |||
@@ -3,6 +3,7 @@ import { Socket } from 'socket.io' | |||
3 | import { oAuthServer } from '@server/lib/auth' | 3 | import { oAuthServer } from '@server/lib/auth' |
4 | import { logger } from '../helpers/logger' | 4 | import { logger } from '../helpers/logger' |
5 | import { getAccessToken } from '../lib/oauth-model' | 5 | import { getAccessToken } from '../lib/oauth-model' |
6 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | ||
6 | 7 | ||
7 | function authenticate (req: express.Request, res: express.Response, next: express.NextFunction, authenticateInQuery = false) { | 8 | function authenticate (req: express.Request, res: express.Response, next: express.NextFunction, authenticateInQuery = false) { |
8 | const options = authenticateInQuery ? { allowBearerTokensInQueryString: true } : {} | 9 | const options = authenticateInQuery ? { allowBearerTokensInQueryString: true } : {} |
@@ -50,7 +51,7 @@ function authenticatePromiseIfNeeded (req: express.Request, res: express.Respons | |||
50 | // Already authenticated? (or tried to) | 51 | // Already authenticated? (or tried to) |
51 | if (res.locals.oauth?.token.User) return resolve() | 52 | if (res.locals.oauth?.token.User) return resolve() |
52 | 53 | ||
53 | if (res.locals.authenticated === false) return res.sendStatus(401) | 54 | if (res.locals.authenticated === false) return res.sendStatus(HttpStatusCode.UNAUTHORIZED_401) |
54 | 55 | ||
55 | authenticate(req, res, () => resolve(), authenticateInQuery) | 56 | authenticate(req, res, () => resolve(), authenticateInQuery) |
56 | }) | 57 | }) |