aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-04-22 16:07:04 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-05-04 16:21:39 +0200
commit7fed637506043e4432cbebe041ada0625171cceb (patch)
tree07f174e17c4b4a0b3d43a0fa6944865c06234338 /server/middlewares
parent8d4197637868d5cde49434e937186b57e40f4b2b (diff)
downloadPeerTube-7fed637506043e4432cbebe041ada0625171cceb.tar.gz
PeerTube-7fed637506043e4432cbebe041ada0625171cceb.tar.zst
PeerTube-7fed637506043e4432cbebe041ada0625171cceb.zip
Begin auth plugin support
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/oauth.ts29
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as OAuthServer from 'express-oauth-server'
3import { OAUTH_LIFETIME } from '../initializers/constants'
4import { logger } from '../helpers/logger' 2import { logger } from '../helpers/logger'
5import { Socket } from 'socket.io' 3import { Socket } from 'socket.io'
6import { getAccessToken } from '../lib/oauth-model' 4import { getAccessToken } from '../lib/oauth-model'
7 5import { handleIdAndPassLogin, oAuthServer } from '@server/lib/auth'
8const 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
16function authenticate (req: express.Request, res: express.Response, next: express.NextFunction, authenticateInQuery = false) { 7function 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
76function 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
93export { 69export {
94 authenticate, 70 authenticate,
95 authenticateSocket, 71 authenticateSocket,
96 authenticatePromiseIfNeeded, 72 authenticatePromiseIfNeeded,
97 optionalAuthenticate, 73 optionalAuthenticate
98 token
99} 74}