/// <summary>
        /// Refresh credentials after expiry. If the role profile is configured to not
        /// use the default user identity, an exception is thrown if the UserAuthenticationCallback
        /// property has not been set.
        /// </summary>
        /// <returns></returns>
        protected override CredentialsRefreshState GenerateNewCredentials()
        {
            Validate();

            CredentialsRefreshState newState = null;
            var attempts = 0;

            do
            {
                try
                {
                    NetworkCredential userCredential = null;
                    if (!ProfileData.UseDefaultUserIdentity)
                    {
                        var callbackArgs = new CredentialCallbackArgs
                        {
                            UserIdentity = ProfileData.UserIdentity,
                            CustomState  = CustomCallbackState,
                            PreviousAuthenticationFailed = attempts > 0
                        };

                        userCredential = RequestUserCredentialCallback(callbackArgs);

                        if (userCredential == null) // user declined to authenticate
                        {
                            throw new AuthenticationFailedException("No credentials supplied, credential refresh abandoned");
                        }
                    }

                    newState = Authenticate(userCredential, _credentialDuration);
                }
                catch (AuthenticationFailedException)
                {
                    if (attempts < MaxAuthenticationRetries)
                    {
                        attempts++;
                    }
                    else
                    {
                        throw;
                    }
                }
            } while (newState == null && attempts < MaxAuthenticationRetries);

            return(newState);
        }
        /// <summary>
        /// Refresh credentials after expiry. If the role profile is configured to not
        /// use the default user identity, an exception is thrown if the UserAuthenticationCallback
        /// property has not been set.
        /// </summary>
        /// <returns></returns>
        protected override CredentialsRefreshState GenerateNewCredentials()
        {
            Validate();

            CredentialsRefreshState newState = null;
            var attempts = 0;
            do
            {
                try
                {
                    NetworkCredential userCredential = null;
                    if (!ProfileData.UseDefaultUserIdentity)
                    {
                        var callbackArgs = new CredentialCallbackArgs
                        {
                            UserIdentity = ProfileData.UserIdentity,
                            CustomState = CustomCallbackState,
                            PreviousAuthenticationFailed = attempts > 0
                        };

                        userCredential = RequestUserCredentialCallback(callbackArgs);

                        if (userCredential == null) // user declined to authenticate
                            throw new AuthenticationFailedException("No credentials supplied, credential refresh abandoned");
                    }

                    newState = Authenticate(userCredential, _credentialDuration);
                }
                catch (AuthenticationFailedException)
                {
                    if (attempts < MaxAuthenticationRetries)
                        attempts++;
                    else
                        throw;
                }
            } while (newState == null && attempts < MaxAuthenticationRetries);

            return newState;
        }