Copied to clipboard

Flag this post as spam?

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

  • stephencai 12 posts 102 karma points
    Mar 08, 2019 @ 03:06

    Currently, I am looking for a way to perform a single log on feature with other system through API.

    The feature logic is when user using other system account to login umbraco cms, backoffice will do the authenticate with calling API. If the username and password are correct and login to cms. There will also check if the user is not exist in cms, it will create new user and login.

    I am facing a problem about after create new user, suppose it can be auto login to cms. However, It shows "Login failed for user XXXX" at first time. It can be able to login when I login again.

    I am trying many way, eg. OwinStartup / custom member ship provider ... etc. But it does not fix my problem.

    Any advise?

  • Alexander Croner 67 posts 278 karma points
    Mar 11, 2019 @ 13:42
    Alexander Croner

    We have it solved with an OwinStartup, we are using it in a few Umbraco projects and it works great.

    But your question is a little to wide to answer I think. What are showing in the logs etc? Can you show some code?

  • stephencai 12 posts 102 karma points
    Mar 15, 2019 @ 08:24

    Sorry for late reply.

    Here is my code.

    [assembly: OwinStartup("CustomUmbracoOwinStartup", typeof(CustomUmbracoOwinStartup))]

    namespace bordrin.web { public class CustomUmbracoOwinStartup { public void Configuration(IAppBuilder app) { var applicationContext = ApplicationContext.Current; app.ConfigureUserManagerForUmbracoBackOffice



    public class CustomBackOfficeUserManager : BackOfficeUserManager { public CustomBackOfficeUserManager(IUserStore

        if (authenticate)
            var userService = ApplicationContext.Current.Services.UserService;
            var existingUser = userService.GetByEmail(user.UserName);
            if (existingUser == null)
                CreateUser(user.UserName, password, user.UserName, userService);
        return Task.FromResult(BackOfficeUserPasswordCheckerResult.InvalidCredentials);
    private BackOfficeUserManager<BackOfficeIdentityUser> _userManager;
    protected BackOfficeUserManager<BackOfficeIdentityUser> UserManager
        get { return _userManager ?? (_userManager = HttpContext.Current.GetOwinContext().GetBackOfficeUserManager()); }
    private bool CreateUser(string username, string password, string email, IUserService userService)
        var newUser = userService.CreateWithIdentity(username, email, password, userService.GetDefaultMemberType());
        newUser.RawPasswordValue = (Membership.Providers["UsersMembershipProvider"] as UsersMembershipProvider).HashPasswordForStorage(password);
        return true;


    Here is the capture at login page.

    enter image description here

    1 Login > api authentication

    2 success > check user > exist > login to cms

    2 success > check user > not exist > create user > login to cms

    I dont know why first time show error, and backend have created the user. when i click login again, it works fine.

Please Sign in or register to post replies

Write your reply to: