/// <summary>
        /// Enters credentials on the device control panel and initiates the authentication process.
        /// Applies the specified parameters before submitting the authentication request.
        /// </summary>
        public void Authenticate(Dictionary <string, object> parameters)
        {
            AuthenticationInitMethod authMode = GetAuthenticationInitMethod();

            RecordEvent(DeviceWorkflowMarker.AuthenticationBegin);
            AuthenticationProvider deviceDefaultProvider = GetDefaultProvider(ControlPanel.GetScreenInfo());

            // Eager Auth allows for the setting of a provider.  Lazy Auth just prompts for credentials,
            // so we only want to allow the provider to be set if auth mode is Eager.
            if (authMode == AuthenticationInitMethod.SignInButton)
            {
                if (Provider == AuthenticationProvider.Auto)
                {
                    // Use the device default
                    Provider = deviceDefaultProvider;
                }

                if (Provider != deviceDefaultProvider)
                {
                    // Set the device provider to the requested provider
                    SetDeviceProvider(Provider);
                }

                ControlPanel.PressByValue("Continue");
            }

            //At this point this.Provider should be correctly set, so we should use it from now on.
            IAppAuthenticator appAuthenticator = GetAppAuthenticator(Provider);

            if (Provider != AuthenticationProvider.Card && parameters?.Count > 0)
            {
                appAuthenticator.ApplyParameters(parameters);
            }

            RecordInfo(DeviceWorkflowMarker.AuthType, Provider.GetDescription());
            RecordEvent(DeviceWorkflowMarker.EnterCredentialsBegin);
            appAuthenticator.EnterCredentials();
            RecordEvent(DeviceWorkflowMarker.EnterCredentialsEnd);

            if (Provider != AuthenticationProvider.Card)
            {
                appAuthenticator.SubmitAuthentication();
            }
            RecordEvent(DeviceWorkflowMarker.AuthenticationEnd);
        }
예제 #2
0
        /// <summary>
        /// Enters credentials on the device control panel and initiates the authentication process.
        /// Applies the specified parameters before submitting the authentication request.
        /// </summary>
        /// <param name="parameters">Additional configuration parameters presented on the Auth screen.</param>
        public void Authenticate(Dictionary <string, object> parameters)
        {
            StringBuilder     providerDescription = new StringBuilder(Provider.GetDescription());
            IAppAuthenticator appAuthenticator    = null;

            RecordEvent(DeviceWorkflowMarker.AuthenticationBegin);

            if (InitializationMethod != AuthenticationInitMethod.Badge)
            {
                AuthenticationProvider deviceDefaultProvider = GetDefaultProvider();

                if (Provider == AuthenticationProvider.Auto)
                {
                    // Use the device default
                    Provider = deviceDefaultProvider;
                    providerDescription.Append(" - ");
                    providerDescription.Append(Provider.GetDescription());
                }

                RecordInfo(DeviceWorkflowMarker.AuthType, providerDescription.ToString());

                if (Provider != deviceDefaultProvider)
                {
                    // Set the device provider to the requested provider
                    SetDeviceProvider(Provider);
                }

                //At this point this.Provider should be correctly set, so we should use it from now on.
                appAuthenticator = GetAppAuthenticator(Provider);
            }
            else
            {
                providerDescription.Insert(0, " - ");
                providerDescription.Insert(0, InitializationMethod.GetDescription());
                RecordInfo(DeviceWorkflowMarker.AuthType, providerDescription.ToString());
                appAuthenticator = GetAppAuthenticator(AuthenticationProvider.Card);
            }

            if (Provider == AuthenticationProvider.Card || InitializationMethod.Equals(AuthenticationInitMethod.Badge))
            {
                RecordEvent(DeviceWorkflowMarker.DeviceButtonPress, InitializationMethod.GetDescription());
                appAuthenticator.ApplyParameters(null);
            }
            else if (parameters?.Count > 0)
            {
                appAuthenticator.ApplyParameters(parameters);
            }

            RecordEvent(DeviceWorkflowMarker.EnterCredentialsBegin);
            appAuthenticator.EnterCredentials();
            RecordEvent(DeviceWorkflowMarker.EnterCredentialsEnd);

            if (Provider != AuthenticationProvider.Card)
            {
                appAuthenticator.SubmitAuthentication();
                if (!appAuthenticator.ValidateAuthentication())
                {
                    throw new DeviceWorkflowException($"{Credential.UserName} login failed. {appAuthenticator.ErrorMessage}");
                }
            }

            RecordEvent(DeviceWorkflowMarker.AuthenticationEnd);
        }