diff options
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/oauth.ts | 29 |
1 files changed, 2 insertions, 27 deletions
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts index 9eef03bb4..4ae7f18c2 100644 --- a/server/middlewares/oauth.ts +++ b/server/middlewares/oauth.ts | |||
@@ -1,17 +1,8 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as OAuthServer from 'express-oauth-server' | ||
3 | import { OAUTH_LIFETIME } from '../initializers/constants' | ||
4 | import { logger } from '../helpers/logger' | 2 | import { logger } from '../helpers/logger' |
5 | import { Socket } from 'socket.io' | 3 | import { Socket } from 'socket.io' |
6 | import { getAccessToken } from '../lib/oauth-model' | 4 | import { getAccessToken } from '../lib/oauth-model' |
7 | 5 | import { handleIdAndPassLogin, oAuthServer } from '@server/lib/auth' | |
8 | const oAuthServer = new OAuthServer({ | ||
9 | useErrorHandler: true, | ||
10 | accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN, | ||
11 | refreshTokenLifetime: OAUTH_LIFETIME.REFRESH_TOKEN, | ||
12 | continueMiddleware: true, | ||
13 | model: require('../lib/oauth-model') | ||
14 | }) | ||
15 | 6 | ||
16 | function authenticate (req: express.Request, res: express.Response, next: express.NextFunction, authenticateInQuery = false) { | 7 | function authenticate (req: express.Request, res: express.Response, next: express.NextFunction, authenticateInQuery = false) { |
17 | const options = authenticateInQuery ? { allowBearerTokensInQueryString: true } : {} | 8 | const options = authenticateInQuery ? { allowBearerTokensInQueryString: true } : {} |
@@ -73,27 +64,11 @@ function optionalAuthenticate (req: express.Request, res: express.Response, next | |||
73 | return next() | 64 | return next() |
74 | } | 65 | } |
75 | 66 | ||
76 | function token (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
77 | return oAuthServer.token()(req, res, err => { | ||
78 | if (err) { | ||
79 | return res.status(err.status) | ||
80 | .json({ | ||
81 | error: err.message, | ||
82 | code: err.name | ||
83 | }) | ||
84 | .end() | ||
85 | } | ||
86 | |||
87 | return next() | ||
88 | }) | ||
89 | } | ||
90 | |||
91 | // --------------------------------------------------------------------------- | 67 | // --------------------------------------------------------------------------- |
92 | 68 | ||
93 | export { | 69 | export { |
94 | authenticate, | 70 | authenticate, |
95 | authenticateSocket, | 71 | authenticateSocket, |
96 | authenticatePromiseIfNeeded, | 72 | authenticatePromiseIfNeeded, |
97 | optionalAuthenticate, | 73 | optionalAuthenticate |
98 | token | ||
99 | } | 74 | } |