diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-28 14:40:11 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-28 14:40:11 +0100 |
commit | 93e4a311f37d7fc82ec81190553f8beae28fdef5 (patch) | |
tree | bced0a69b51d0bab35b01bfede629eef60ce3675 /server/middlewares/oauth.ts | |
parent | eec63bbc0f4fdb39e56f37127b35c449f90a135f (diff) | |
download | PeerTube-93e4a311f37d7fc82ec81190553f8beae28fdef5.tar.gz PeerTube-93e4a311f37d7fc82ec81190553f8beae28fdef5.tar.zst PeerTube-93e4a311f37d7fc82ec81190553f8beae28fdef5.zip |
Improve check jobs parameters tests
Diffstat (limited to 'server/middlewares/oauth.ts')
-rw-r--r-- | server/middlewares/oauth.ts | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts index 12872c4a5..9976993e0 100644 --- a/server/middlewares/oauth.ts +++ b/server/middlewares/oauth.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import 'express-validator' | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
3 | import * as OAuthServer from 'express-oauth-server' | 2 | import * as OAuthServer from 'express-oauth-server' |
4 | import { logger } from '../helpers/logger' | 3 | import 'express-validator' |
5 | import { OAUTH_LIFETIME } from '../initializers' | 4 | import { OAUTH_LIFETIME } from '../initializers' |
6 | 5 | ||
7 | const oAuthServer = new OAuthServer({ | 6 | const oAuthServer = new OAuthServer({ |
7 | useErrorHandler: true, | ||
8 | accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN, | 8 | accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN, |
9 | refreshTokenLifetime: OAUTH_LIFETIME.REFRESH_TOKEN, | 9 | refreshTokenLifetime: OAUTH_LIFETIME.REFRESH_TOKEN, |
10 | model: require('../lib/oauth-model') | 10 | model: require('../lib/oauth-model') |
@@ -13,14 +13,12 @@ const oAuthServer = new OAuthServer({ | |||
13 | function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) { | 13 | function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) { |
14 | oAuthServer.authenticate()(req, res, err => { | 14 | oAuthServer.authenticate()(req, res, err => { |
15 | if (err) { | 15 | if (err) { |
16 | logger.error('Cannot authenticate.', err) | 16 | return res.status(err.status) |
17 | return res.sendStatus(500) | 17 | .json({ |
18 | } | 18 | error: 'Authentication failed.', |
19 | 19 | code: err.name | |
20 | if (res.statusCode === 401 || res.statusCode === 400 || res.statusCode === 503) { | 20 | }) |
21 | return res.json({ | 21 | .end() |
22 | error: 'Authentication failed.' | ||
23 | }).end() | ||
24 | } | 22 | } |
25 | 23 | ||
26 | return next() | 24 | return next() |