X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fauth.ts;h=dbd421a7b3d6e0b33c1ecbf5dc2286475cc36452;hb=095e2258043fcff8a79ab082d11edfbd8f13a8e2;hp=8579bdbb44401e0f6fe0b1d4d5e82b54284a0ff8;hpb=610d0be13b3d01f653ef269271dd667a57c85ef2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/auth.ts b/server/lib/auth.ts index 8579bdbb4..dbd421a7b 100644 --- a/server/lib/auth.ts +++ b/server/lib/auth.ts @@ -10,14 +10,16 @@ import { RegisterServerAuthenticatedResult, RegisterServerAuthPassOptions, RegisterServerExternalAuthenticatedResult -} from '@shared/models/plugins/register-server-auth.model' +} from '@server/types/plugins/register-server-auth.model' import * as express from 'express' import * as OAuthServer from 'express-oauth-server' +import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' const oAuthServer = new OAuthServer({ useErrorHandler: true, accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN, refreshTokenLifetime: OAUTH_LIFETIME.REFRESH_TOKEN, + allowExtendedTokenAttributes: true, continueMiddleware: true, model: require('./oauth-model') }) @@ -52,7 +54,7 @@ async function handleTokenRevocation (req: express.Request, res: express.Respons const token = res.locals.oauth.token res.locals.explicitLogout = true - await revokeToken(token) + const result = await revokeToken(token) // FIXME: uncomment when https://github.com/oauthjs/node-oauth2-server/pull/289 is released // oAuthServer.revoke(req, res, err => { @@ -68,7 +70,7 @@ async function handleTokenRevocation (req: express.Request, res: express.Respons // } // }) - return res.json() + return res.json(result) } async function onExternalUserAuthenticated (options: { @@ -215,7 +217,7 @@ function proxifyExternalAuthBypass (req: express.Request, res: express.Response) const obj = authBypassTokens.get(req.body.externalAuthToken) if (!obj) { logger.error('Cannot authenticate user with unknown bypass token') - return res.sendStatus(400) + return res.sendStatus(HttpStatusCode.BAD_REQUEST_400) } const { expires, user, authName, npmName } = obj @@ -223,12 +225,12 @@ function proxifyExternalAuthBypass (req: express.Request, res: express.Response) const now = new Date() if (now.getTime() > expires.getTime()) { logger.error('Cannot authenticate user with an expired external auth token') - return res.sendStatus(400) + return res.sendStatus(HttpStatusCode.BAD_REQUEST_400) } if (user.username !== req.body.username) { logger.error('Cannot authenticate user %s with invalid username %s.', req.body.username) - return res.sendStatus(400) + return res.sendStatus(HttpStatusCode.BAD_REQUEST_400) } // Bypass oauth library validation