Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Option to disable 2FA for OAuth users #32945

Merged
merged 29 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
214015c
implement new setting
yash-rajpal Jul 30, 2024
969caf2
Hide option in UI for oAuth users
yash-rajpal Jul 30, 2024
fdb0fac
add cs
yash-rajpal Jul 31, 2024
6a1a5a5
OAuth user definition
yash-rajpal Aug 2, 2024
5bf39c7
oops
yash-rajpal Aug 2, 2024
ae866f7
remove console.log
yash-rajpal Aug 2, 2024
53ff5ad
fix return condition
yash-rajpal Aug 2, 2024
1480e82
fix review
yash-rajpal Aug 2, 2024
87e974a
Merge branch 'develop' into feat/disable-email-2FA-oauth
yash-rajpal Aug 2, 2024
7c79251
revert oAuth types to any
yash-rajpal Aug 5, 2024
4d97527
fix review
yash-rajpal Aug 5, 2024
063ff50
replace setting behavior
yash-rajpal Aug 5, 2024
4149692
add unit tests
yash-rajpal Aug 5, 2024
c542bd0
Merge branch 'develop' into feat/disable-email-2FA-oauth
yash-rajpal Aug 12, 2024
351f0a0
fix review
yash-rajpal Aug 12, 2024
c9ad659
revert password fallack password check
yash-rajpal Aug 12, 2024
56bdbf9
translations
yash-rajpal Aug 12, 2024
94c57df
Merge branch 'develop' into feat/disable-email-2FA-oauth
yash-rajpal Aug 16, 2024
d7fc847
jest new test config
yash-rajpal Aug 16, 2024
c9bb363
don't mock isOAuthUser function
yash-rajpal Aug 20, 2024
0b3d6f3
Update apps/meteor/app/2fa/server/code/EmailCheck.spec.ts
yash-rajpal Aug 20, 2024
c9edf9e
control disabling and showing from higher component
yash-rajpal Aug 20, 2024
3c5ebca
unit testing the component no longer makes sense
yash-rajpal Aug 20, 2024
560df75
get entire services object
yash-rajpal Aug 20, 2024
2abce3c
setting name semantics
yash-rajpal Aug 22, 2024
d4cdd53
Merge branch 'develop' into feat/disable-email-2FA-oauth
kodiakhq[bot] Sep 9, 2024
974fe47
Merge branch 'develop' into feat/disable-email-2FA-oauth
scuciatto Sep 9, 2024
bb717b6
Merge branch 'develop' into feat/disable-email-2FA-oauth
kodiakhq[bot] Sep 9, 2024
b878dc7
Merge branch 'develop' into feat/disable-email-2FA-oauth
kodiakhq[bot] Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tiny-geckos-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/i18n': minor
'@rocket.chat/meteor': minor
---

Added a new setting which allows workspace admins to disable email two factor authentication for SSO (OAuth) users. If enabled, SSO users won't be asked for email two factor authentication.
4 changes: 4 additions & 0 deletions apps/meteor/app/2fa/server/code/EmailCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export class EmailCheck implements ICodeCheck {
return false;
}

if (settings.get('Accounts_TwoFactorAuthentication_Disable_Email_For_OAuth_Users')) {
yash-rajpal marked this conversation as resolved.
Show resolved Hide resolved
return user?.services?.password?.bcrypt !== undefined;
}

return this.getUserVerifiedEmails(user).length > 0;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/2fa/server/code/PasswordCheckFallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class PasswordCheckFallback implements ICodeCheck {
// TODO: Remove this setting for version 4.0 forcing the
// password fallback for who has password set.
if (settings.get('Accounts_TwoFactorAuthentication_Enforce_Password_Fallback')) {
return user.services?.password?.bcrypt != null;
return user.services?.password?.bcrypt !== undefined;
yash-rajpal marked this conversation as resolved.
Show resolved Hide resolved
}
return false;
}
Expand Down
13 changes: 10 additions & 3 deletions apps/meteor/client/views/account/security/TwoFactorEmail.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { Box, Button, Margins } from '@rocket.chat/fuselage';
import { useUser, useTranslation } from '@rocket.chat/ui-contexts';
import type { ComponentProps, ReactElement } from 'react';
import { useUser, useTranslation, useSetting } from '@rocket.chat/ui-contexts';
import type { ComponentProps } from 'react';
import React, { useCallback } from 'react';

import { useEndpointAction } from '../../../hooks/useEndpointAction';

const TwoFactorEmail = (props: ComponentProps<typeof Box>): ReactElement => {
const TwoFactorEmail = (props: ComponentProps<typeof Box>): JSX.Element | null => {
yash-rajpal marked this conversation as resolved.
Show resolved Hide resolved
const t = useTranslation();
const user = useUser();

const disableEmail2FAForOAuth = useSetting('Accounts_TwoFactorAuthentication_Disable_Email_For_OAuth_Users');
const isOAuthUser = !user?.services?.password?.exists;
const isEnabled = user?.services?.email2fa?.enabled;
const isAllowed = !isOAuthUser || !disableEmail2FAForOAuth;

const enable2faAction = useEndpointAction('POST', '/v1/users.2fa.enableEmail', {
successMessage: t('Two-factor_authentication_enabled'),
Expand All @@ -25,6 +28,10 @@ const TwoFactorEmail = (props: ComponentProps<typeof Box>): ReactElement => {
await disable2faAction();
}, [disable2faAction]);

if (!isAllowed) {
return null;
}

return (
<Box display='flex' flexDirection='column' alignItems='flex-start' mbs={16} {...props}>
<Margins blockEnd={8}>
Expand Down
12 changes: 12 additions & 0 deletions apps/meteor/server/settings/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ export const createAccountSettings = () =>
public: true,
});

await this.add('Accounts_TwoFactorAuthentication_Disable_Email_For_OAuth_Users', false, {
type: 'boolean',
enableQuery: [
enable2FA,
{
_id: 'Accounts_TwoFactorAuthentication_By_Email_Enabled',
value: true,
},
],
public: true,
});

await this.add('Accounts_TwoFactorAuthentication_By_Email_Auto_Opt_In', true, {
type: 'boolean',
enableQuery: [
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
"Accounts_TwoFactorAuthentication_By_Email_Code_Expiration": "Time to expire the code sent via email in seconds",
"Accounts_TwoFactorAuthentication_By_Email_Enabled": "Enable Two Factor Authentication via Email",
"Accounts_TwoFactorAuthentication_By_Email_Enabled_Description": "Users with email verified and the option enabled in their profile page will receive an email with a temporary code to authorize certain actions like login, save the profile, etc.",
"Accounts_TwoFactorAuthentication_Disable_Email_For_OAuth_Users": "Disable two factor authentication via email for OAuth users",
"Accounts_TwoFactorAuthentication_Enabled": "Enable Two Factor Authentication",
"Accounts_TwoFactorAuthentication_Enabled_Description": "If deactivated, this setting will deactivate all Two Factor Authentication. \nTo force users to use Two Factor Authentication, the admin has to configure the 'user' role to enforce it.",
"Accounts_TwoFactorAuthentication_Enforce_Password_Fallback": "Enforce password fallback",
Expand Down
Loading