UnsupportedGrantTypeError
} from '@node-oauth/oauth2-server'
import { randomBytesPromise } from '@server/helpers/core-utils'
+import { isOTPValid } from '@server/helpers/otp'
import { MOAuthClient } from '@server/types/models'
import { sha1 } from '@shared/extra-utils'
import { HttpStatusCode } from '@shared/models'
import { OAUTH_LIFETIME, OTP } from '../../initializers/constants'
import { BypassLogin, getClient, getRefreshToken, getUser, revokeToken, saveToken } from './oauth-model'
-import { isOTPValid } from '@server/helpers/otp'
class MissingTwoFactorError extends Error {
code = HttpStatusCode.UNAUTHORIZED_401
function handleOAuthAuthenticate (
req: express.Request,
- res: express.Response,
- authenticateInQuery = false
+ res: express.Response
) {
- const options = authenticateInQuery
- ? { allowBearerTokensInQueryString: true }
- : {}
-
- return oAuthServer.authenticate(new Request(req), new Response(res), options)
+ return oAuthServer.authenticate(new Request(req), new Response(res))
}
export {
throw new MissingTwoFactorError('Missing two factor header')
}
- if (isOTPValid({ secret: user.otpSecret, token: request.headers[OTP.HEADER_NAME] }) !== true) {
+ if (await isOTPValid({ encryptedSecret: user.otpSecret, token: request.headers[OTP.HEADER_NAME] }) !== true) {
throw new InvalidTwoFactorError('Invalid two factor header')
}
}