/// <summary>
        /// Creates a new <see cref="ClaimsIdentity"/> from this instance.
        /// </summary>
        /// <param name="manager">The current <see cref="AdminUserManager"/> instance.</param>
        /// <returns>A new <see cref="ClaimsIdentity"/> instance.</returns>
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(AdminUserManager manager, bool isPersistentState, bool screenLockedState)
        {
            var identity = await manager.CreateIdentityAsync(
                this,
                DefaultAuthenticationTypes.ApplicationCookie
                );

            var claims = AdminPrincipal.GetAdminClaims(
                adminUserEntity: this,
                isPersistent: isPersistentState,
                screenLocked: screenLockedState
                );

            foreach (var claim in claims)
            {
                if (!identity.HasClaim(claim.Type, claim.Value))
                {
                    identity.AddClaim(claim);
                }
            }

            return(identity);
        }
        /// <summary>
        /// Recreates the user cookie with updated claims information.
        /// </summary>
        /// <param name="principal">Current principal instance.</param>
        /// <param name="reloadClaims">Flags if claims should be read from database again.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public async Task RefreshIdentity(AdminPrincipal principal, bool reloadClaims = false)
        {
            ClaimsIdentity identity = null;

            var isPersistent = principal.IsPersistent;

            if (reloadClaims)
            {
                var adminUser = await _adminUserManager.FindByIdAsync(principal.Id);

                if (adminUser != null)
                {
                    identity = await adminUser.GenerateUserIdentityAsync(
                        _adminUserManager,
                        isPersistentState : isPersistent,
                        screenLockedState : false
                        );
                }
            }
            else
            {
                identity = principal.Identity as ClaimsIdentity;
            }

            if (identity == null)
            {
                throw new Exception("The provided principal has an invalid identity.", new Exception(nameof(RefreshIdentity)));
            }

            AuthenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant(
                identity,
                new AuthenticationProperties {
                IsPersistent = isPersistent
            }
                );
        }