/// <summary>
        ///     This method will launch the pincode screen if the policy requires it.
        ///     If determined that no pincode screen is required, the flag requiring the pincode will be cleared.
        /// </summary>
        public static async void LaunchPincodeScreen()
        {
            var frame = Window.Current.Content as Frame;

            if (frame != null && typeof(PincodeDialog) != frame.SourcePageType)
            {
                await frame.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    SDKServiceLocator.Get <ILoggingService>().Log(" Launching Pincode Screen", LoggingLevel.Information);
                    Account account = AccountManager.GetAccount();
                    if (account != null)
                    {
                        PincodeOptions options = null;
                        bool required          = AuthStorageHelper.IsPincodeRequired();
                        if (account.Policy != null && !IsPincodeSet())
                        {
                            options = new PincodeOptions(PincodeOptions.PincodeScreen.Create, account, "");
                        }
                        else if (required)
                        {
                            MobilePolicy policy = AuthStorageHelper.GetMobilePolicy();
                            if (account.Policy != null)
                            {
                                if (policy.ScreenLockTimeout < account.Policy.ScreenLockTimeout)
                                {
                                    policy.ScreenLockTimeout = account.Policy.ScreenLockTimeout;
                                    AuthStorageHelper.GetAuthStorageHelper().PersistPincode(policy);
                                }
                                if (policy.PinLength < account.Policy.PinLength)
                                {
                                    options = new PincodeOptions(PincodeOptions.PincodeScreen.Create, account, "");
                                }
                                else
                                {
                                    options = new PincodeOptions(PincodeOptions.PincodeScreen.Locked, account, "");
                                }
                            }
                            else
                            {
                                options = new PincodeOptions(PincodeOptions.PincodeScreen.Locked, account, "");
                            }
                        }
                        if (options != null)
                        {
                            // As per MSDN documentation (https://msdn.microsoft.com/en-us/library/windows/apps/hh702394.aspx)
                            // the second param of Frame.Navigate must be a basic type otherwise Suspension manager will crash
                            // when serializing frame's state. So we serialize custom object using Json and pass that as the
                            // second param to avoid this crash.
                            frame.Navigate(typeof(PincodeDialog), PincodeOptions.ToJson(options));
                        }
                    }
                });
            }
        }
 protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
 {
     if (e != null &&
         Options != null &&
         PincodeOptions.PincodeScreen.Locked.Equals(Options.Screen) &&
         AuthStorageHelper.IsPincodeRequired())
     {
         e.Cancel = true;
     }
     base.OnNavigatingFrom(e);
 }
Exemple #3
0
        /// <summary>
        /// This should be called when login is complete. A new account is created
        /// in the AccountManager and the pincode screen is shown if needeed
        /// </summary>
        /// <param name="loginOptions"></param>
        /// <param name="authResponse"></param>
        public async Task OnLoginCompleteAsync(LoginOptions loginOptions, AuthResponse authResponse)
        {
            var frame   = Window.Current.Content as Frame;
            var account = await AccountManager.CreateNewAccount(loginOptions, authResponse);

            if (account.Policy != null && (!PincodeManager.IsPincodeSet() || AuthStorageHelper.IsPincodeRequired()))
            {
                PincodeManager.LaunchPincodeScreen();
            }
            else
            {
                SDKServiceLocator.Get <ILoggingService>().Log($"Navigating to {SDKManager.RootApplicationPage}", LoggingLevel.Information);
                frame?.Navigate(SDKManager.RootApplicationPage);
            }
        }
Exemple #4
0
        /// <summary>
        ///     Persist oauth credentials via the AccountManager
        /// </summary>
        /// <param name="loginOptions"></param>
        /// <param name="authResponse"></param>
        public async void EndLoginFlow(LoginOptions loginOptions, AuthResponse authResponse)
        {
            var     frame   = Window.Current.Content as Frame;
            Account account = await AccountManager.CreateNewAccount(loginOptions, authResponse);

            if (account.Policy != null && (!PincodeManager.IsPincodeSet() || AuthStorageHelper.IsPincodeRequired()))
            {
                PincodeManager.LaunchPincodeScreen();
            }
            else
            {
                PlatformAdapter.SendToCustomLogger(string.Format("AuthHelper.EndLoginFlow - Navigating to {0}",
                                                                 SDKManager.RootApplicationPage), LoggingLevel.Information);
                frame.Navigate(SDKManager.RootApplicationPage);
            }
        }
        public static void TriggerBackgroundedPinTimer()
        {
            Account      account  = AccountManager.GetAccount();
            MobilePolicy policy   = AuthStorageHelper.GetMobilePolicy();
            bool         required = AuthStorageHelper.IsPincodeRequired();

            if (account != null)
            {
                if (required || (policy == null && account.Policy != null))
                {
                    LaunchPincodeScreen();
                }
            }
            else if (!required)
            {
                AuthStorageHelper.ClearPinTimer();
            }
        }