Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Cimplex 113 posts 576 karma points
    Oct 23, 2019 @ 18:46
    Cimplex
    0

    2FA - Umbraco 8 - Redirect to backoffice after successful code

    Howdy!

    We have two factor authentication enabled for our Umbraco site, in Umbraco 7 we used this code snippet to verify the 2fa code:

    authResource.verify2FACode(provider, code)
                    .then(function (data) {
                        userService.setAuthenticationSuccessful(data);
                        $scope.submit(true);
                    }, function(response) {
                        $scope.error = true;
                    });
    

    Now the $scope.submit(true) throws a error:

    TypeError: $scope.submit is not a function
    

    And the user is not redirected to the backoffice. If the page is reloaded manually (F5) the backoffice appear as expected, means that the cookie is set correctly.

    Any ideas how to solve this?

    / Herman

  • Thomas Maassen 3 posts 73 karma points
    Jan 13, 2020 @ 12:38
    Thomas Maassen
    0

    I think this means angularJs does not have a built in function for $scope.submit anymore, but not sure.

    I have been working on a 2fa package for Umbraco 8 that will we released later this week or next week and I solved this by using a different function to refresh the page.

    I hardcoded the backoffice URL and allowed that URL to be changed in a constants file. If you swap $scope.submit for this line it should work:

    $window.location.href = '/umbraco';
    

    For this to work you will have to inject $window in your controller like you did with $scope and authResource. If you have a different backoffice URL you should ofcourse put that in the string instead of /umbraco

  • Cimplex 113 posts 576 karma points
    Jan 14, 2020 @ 08:57
    Cimplex
    0

    Hi Thomas,

    Thanks for the reply, that's how i solved it as well, bad thing about this is if your automatically logged out from Umbraco all your changes will be gone because of the redirect.

    // Herman

  • Thomas Maassen 3 posts 73 karma points
    Jan 14, 2020 @ 09:21
    Thomas Maassen
    0

    It's not my favorite solution either, but it's the only one I could get to work. Normally i use a different method in the angular controllers to refresh the page:$route.reload(). But when i use that method in the login controler it updates the URL but it doesn't refresh the view so for now this seems to be the only way

  • Joep 96 posts 698 karma points
    Mar 10, 2020 @ 15:55
    Joep
    100

    Hi,

    Someone found a way without reloading the page. For more info look at this issue: https://github.com/Dallas-msc/umbraco-2fa-with-google-authenticator/issues/1

    -Joep

  • Cimplex 113 posts 576 karma points
    Mar 11, 2020 @ 08:17
    Cimplex
    0

    Works like a charm, thanks for sharing!

  • David Armitage 505 posts 2073 karma points
    Dec 03, 2020 @ 02:47
    David Armitage
    0

    Hi,

    I just did the same as Thomas and it worked a treat. Just just used regular JS. window.location.href = '/umbraco';

     $scope.validate = function (provider, code) {
                provider = "GoogleAuthenticator"; //temp netser
                $scope.error2FA = "";
                $scope.code = code;
                authResource.verify2FACode(provider, code)
                    .then(function (data) {
                        userService.setAuthenticationSuccessful(data);
                        window.location.href = '/umbraco';
                        //$scope.submit(true);
                    }, function () { $scope.error2FA = "Invalid code entered." });
            };
    

    Remember to keep refreshing this page. I usually open the js file in the browser and force refresh. I then also force refresh the login screen.

    This stuff is always cached and might not run your code changes.

    Regards

    David

  • Bishwajit 28 posts 98 karma points
    Jul 24, 2023 @ 11:21
    Bishwajit
    0

    I am getting ReferenceError: authResource is not defined. Is there any other way to submit dialogue editor content ?

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft