aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/oauth.ts18
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 @@
1import 'express-validator'
2import * as express from 'express' 1import * as express from 'express'
3import * as OAuthServer from 'express-oauth-server' 2import * as OAuthServer from 'express-oauth-server'
4import { logger } from '../helpers/logger' 3import 'express-validator'
5import { OAUTH_LIFETIME } from '../initializers' 4import { OAUTH_LIFETIME } from '../initializers'
6 5
7const oAuthServer = new OAuthServer({ 6const 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({
13function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) { 13function 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()