diff options
Diffstat (limited to 'server/middlewares')
-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() |