]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/oauth.ts
Begin auth plugin support
[github/Chocobozzz/PeerTube.git] / server / middlewares / oauth.ts
index 9eef03bb43fc8bba3384dd350ebe977dcc25214a..4ae7f18c2002e1182964c0c04fde29cfd5635cee 100644 (file)
@@ -1,17 +1,8 @@
 import * as express from 'express'
-import * as OAuthServer from 'express-oauth-server'
-import { OAUTH_LIFETIME } from '../initializers/constants'
 import { logger } from '../helpers/logger'
 import { Socket } from 'socket.io'
 import { getAccessToken } from '../lib/oauth-model'
-
-const oAuthServer = new OAuthServer({
-  useErrorHandler: true,
-  accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN,
-  refreshTokenLifetime: OAUTH_LIFETIME.REFRESH_TOKEN,
-  continueMiddleware: true,
-  model: require('../lib/oauth-model')
-})
+import { handleIdAndPassLogin, oAuthServer } from '@server/lib/auth'
 
 function authenticate (req: express.Request, res: express.Response, next: express.NextFunction, authenticateInQuery = false) {
   const options = authenticateInQuery ? { allowBearerTokensInQueryString: true } : {}
@@ -73,27 +64,11 @@ function optionalAuthenticate (req: express.Request, res: express.Response, next
   return next()
 }
 
-function token (req: express.Request, res: express.Response, next: express.NextFunction) {
-  return oAuthServer.token()(req, res, err => {
-    if (err) {
-      return res.status(err.status)
-        .json({
-          error: err.message,
-          code: err.name
-        })
-        .end()
-    }
-
-    return next()
-  })
-}
-
 // ---------------------------------------------------------------------------
 
 export {
   authenticate,
   authenticateSocket,
   authenticatePromiseIfNeeded,
-  optionalAuthenticate,
-  token
+  optionalAuthenticate
 }