aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/oauth.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/oauth.ts')
-rw-r--r--server/middlewares/oauth.ts12
1 files changed, 6 insertions, 6 deletions
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts
index 77fb305dd..bb90dac47 100644
--- a/server/middlewares/oauth.ts
+++ b/server/middlewares/oauth.ts
@@ -12,8 +12,10 @@ const oAuthServer = new OAuthServer({
12 model: require('../lib/oauth-model') 12 model: require('../lib/oauth-model')
13}) 13})
14 14
15function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) { 15function authenticate (req: express.Request, res: express.Response, next: express.NextFunction, authenticateInQuery = false) {
16 oAuthServer.authenticate()(req, res, err => { 16 const options = authenticateInQuery ? { allowBearerTokensInQueryString: true } : {}
17
18 oAuthServer.authenticate(options)(req, res, err => {
17 if (err) { 19 if (err) {
18 logger.warn('Cannot authenticate.', { err }) 20 logger.warn('Cannot authenticate.', { err })
19 21
@@ -50,16 +52,14 @@ function authenticateSocket (socket: Socket, next: (err?: any) => void) {
50 }) 52 })
51} 53}
52 54
53function authenticatePromiseIfNeeded (req: express.Request, res: express.Response) { 55function authenticatePromiseIfNeeded (req: express.Request, res: express.Response, authenticateInQuery = false) {
54 return new Promise(resolve => { 56 return new Promise(resolve => {
55 // Already authenticated? (or tried to) 57 // Already authenticated? (or tried to)
56 if (res.locals.oauth && res.locals.oauth.token.User) return resolve() 58 if (res.locals.oauth && res.locals.oauth.token.User) return resolve()
57 59
58 if (res.locals.authenticated === false) return res.sendStatus(401) 60 if (res.locals.authenticated === false) return res.sendStatus(401)
59 61
60 authenticate(req, res, () => { 62 authenticate(req, res, () => resolve(), authenticateInQuery)
61 return resolve()
62 })
63 }) 63 })
64} 64}
65 65