Last active
October 16, 2025 08:29
-
-
Save markadrake/f6c00123ad177e7d4395849c079ab0e9 to your computer and use it in GitHub Desktop.
Force Users to Enable Two-Factor Authentication in Umbraco 13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (() => { | |
| angular.module("umbraco").run(["authResource", "twoFactorLoginResource", "editorService", "notificationsService", "eventsService", async (authResource, twoFactorLoginResource, editorService, notificationsService, eventsService) => { | |
| const state = {}; | |
| const init = async (firstInit) => { | |
| "app.ready" | |
| state.currentUser = await authResource.getCurrentUser(); | |
| state.twoFactorAuthProviders = await twoFactorLoginResource.get2FAProvidersForUser(state.currentUser.id); | |
| if(firstInit && !twoFactorIsEnabled()) { | |
| configureTwoFactor(); | |
| } | |
| }; | |
| const twoFactorIsEnabled = () => { | |
| return !!state.twoFactorAuthProviders.find(provider => provider.isEnabledOnUser); | |
| }; | |
| const configureTwoFactor = () => { | |
| editorService.open({ | |
| create: true, | |
| user: state.currentUser, | |
| isCurrentUser: true, | |
| size: "small", | |
| view: "views/common/infiniteeditors/twofactor/configuretwofactor.html", | |
| close: async () => { | |
| await init(); | |
| if(twoFactorIsEnabled()) { | |
| notificationsService.success("Two-Factor Auth", "You have successfully configured two-factor authentication."); | |
| editorService.close(); | |
| } else { | |
| notificationsService.error("Two-Factor Auth", "You must configure two-factor authentication before continuing."); | |
| } | |
| } | |
| }); | |
| }; | |
| eventsService.on("app.ready", (name, args) => { | |
| init(true); | |
| }); | |
| }]); | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "javascript": [ | |
| "~/App_Plugins/path/to/EnforceTwoFactorAuthentication.js" | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where abouts in Umbraco 13 would you place this code, and is there any other config to do other than the usual Umbraco 2FA stuff?