From 56f47830758ff8e92abcfcc5f35d474ab12fe215 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 5 Oct 2022 15:37:15 +0200 Subject: Support two factor authentication in backend --- server/controllers/api/users/token.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'server/controllers/api/users/token.ts') diff --git a/server/controllers/api/users/token.ts b/server/controllers/api/users/token.ts index 012a49791..c6afea67c 100644 --- a/server/controllers/api/users/token.ts +++ b/server/controllers/api/users/token.ts @@ -1,8 +1,9 @@ import express from 'express' import { logger } from '@server/helpers/logger' import { CONFIG } from '@server/initializers/config' +import { OTP } from '@server/initializers/constants' import { getAuthNameFromRefreshGrant, getBypassFromExternalAuth, getBypassFromPasswordGrant } from '@server/lib/auth/external-auth' -import { handleOAuthToken } from '@server/lib/auth/oauth' +import { handleOAuthToken, MissingTwoFactorError } from '@server/lib/auth/oauth' import { BypassLogin, revokeToken } from '@server/lib/auth/oauth-model' import { Hooks } from '@server/lib/plugins/hooks' import { asyncMiddleware, authenticate, buildRateLimiter, openapiOperationDoc } from '@server/middlewares' @@ -79,6 +80,10 @@ async function handleToken (req: express.Request, res: express.Response, next: e } catch (err) { logger.warn('Login error', { err }) + if (err instanceof MissingTwoFactorError) { + res.set(OTP.HEADER_NAME, OTP.HEADER_REQUIRED_VALUE) + } + return res.fail({ status: err.code, message: err.message, -- cgit v1.2.3