Esempio n. 1
0
        public async Task <IAuthStatus> AuthorizeUserAsync(string password)
        {
            IAuthStatus          status = null;
            WebTransferException webEx  = null;

            try
            {
                IsBusy = true;
                status = await HockeyClient.Current.AsInternal().AuthorizeUserAsync(this.Email, password ?? "");

                if (status.IsAuthorized)
                {
                    await AuthManager.Current.UpdateAuthStatusAsync(status);
                }
            }
            catch (WebTransferException wte)
            {
                webEx = wte;
            }

            finally
            {
                IsBusy = false;
            }
            if (webEx != null)
            {
                await HandleNetworkError(webEx);
            }
            return(status);
        }
Esempio n. 2
0
        public async Task <IAuthStatus> IdentifyUserAsync()
        {
            IAuthStatus          status = null;
            WebTransferException webEx  = null;

            try
            {
                IsBusy = true;
                status = await HockeyClient.Current.AsInternal().IdentifyUserAsync(this.Email, this.AppSecret);

                if (status.IsIdentified)
                {
                    await AuthManager.Current.UpdateAuthStatusAsync(status);
                }
            }
            catch (WebTransferException wte)
            {
                webEx = wte;
            }
            finally
            {
                IsBusy = false;
            }
            if (webEx != null)
            {
                await HandleNetworkError(webEx);
            }
            return(status);
        }
Esempio n. 3
0
        internal async Task UpdateAuthStatusAsync(IAuthStatus newStatus)
        {
            if (newStatus as AuthStatus != null && newStatus.IsIdentified)
            {
                await StoreStringProtectedAsync(ConstantsUniversal.AuthStatusKey, (newStatus as AuthStatus).SerializeToString());

                HockeyClient.Current.AsInternal().PlatformHelper.SetSettingValue(ConstantsUniversal.AuthLastAuthorizedVersionKey, HockeyClient.Current.AsInternal().VersionInfo);
            }
            _authStatus = newStatus;
        }
        internal async Task AuthenticateOnlineAsync()
        {
            this.VM.IsBusy = true;
            Exception thrownException = null;

            try
            {
                IAuthStatus status = await(this.VM.IsAuthorize ? this.VM.AuthorizeUserAsync(this.Password.Password) : this.VM.IdentifyUserAsync());
                if (status.IsIdentified)
                {
                    AuthManager.Current.ExecuteSuccessRedirectOrAction();
                    return;
                }
                else
                {
                    if (status.IsCredentialError)
                    {
                        this.Password.Password = String.Empty;
                        await new MessageDialog(LocalizedStrings.LocalizedResources.AuthCredentialsError).ShowAsync();
                    }
                    else if (status.IsPermissionError)
                    {
                        this.Password.Password = String.Empty;
                        await new MessageDialog(LocalizedStrings.LocalizedResources.AuthNoMemberError).ShowAsync();
                    }
                    else
                    {
                        this.Password.Password = String.Empty;
                        await new MessageDialog(LocalizedStrings.LocalizedResources.AuthUnknownError).ShowAsync();
                    }
                }
            }
            catch (Exception e)
            {
                thrownException = e;
            }
            finally
            {
                this.VM.IsBusy = false;
            }
            if (thrownException != null)
            {
                if (thrownException is HockeyApp.Exceptions.WebTransferException)
                {
                    await new MessageDialog(LocalizedStrings.LocalizedResources.AuthNetworkError).ShowAsync();
                }
                else
                {
                    await new MessageDialog(LocalizedStrings.LocalizedResources.AuthUnknownError).ShowAsync();
                }
            }
        }
Esempio n. 5
0
        internal async Task <bool> AuthorizeOnline(string password = null)
        {
            IsBusy = true;
            Exception thrownException = null;

            try
            {
                IAuthStatus status = await(this.IsAuthorize ? this.AuthorizeUserAsync(password) : this.IdentifyUserAsync());
                if (status.IsIdentified)
                {
                    AuthManager.Current.ExecuteSuccessRedirectOrAction();
                    return(true);
                }
                else
                {
                    if (status.IsCredentialError)
                    {
                        await new MessageDialog(LocalizedStrings.LocalizedResources.AuthCredentialsError).ShowAsync();
                    }
                    else if (status.IsPermissionError)
                    {
                        await new MessageDialog(LocalizedStrings.LocalizedResources.AuthNoMemberError).ShowAsync();
                    }
                    else
                    {
                        await new MessageDialog(LocalizedStrings.LocalizedResources.AuthUnknownError).ShowAsync();
                    }
                }
            }
            catch (Exception e)
            {
                HockeyClient.Current.AsInternal().HandleInternalUnhandledException(e);
                thrownException = e;
            }
            finally
            {
                IsBusy = false;
            }
            if (thrownException != null)
            {
                if (thrownException is HockeyApp.Exceptions.WebTransferException)
                {
                    await new MessageDialog(LocalizedStrings.LocalizedResources.AuthNetworkError).ShowAsync();
                }
                else
                {
                    await new MessageDialog(LocalizedStrings.LocalizedResources.AuthUnknownError).ShowAsync();
                }
            }
            return(false);
        }
 protected async Task AuthenticateOnlineAsync()
 {
     SystemTray.ProgressIndicator.IsVisible = true;
     try
     {
         IAuthStatus status = await(this.VM.IsAuthorize ? this.VM.AuthorizeUserAsync(this.Password.Password) : this.VM.IdentifyUserAsync());
         if (status.IsIdentified)
         {
             NavigationService.Navigate(AuthManager.Instance.SuccessRedirect);
             return;
         }
         else
         {
             if (status.IsCredentialError)
             {
                 this.Password.Password = String.Empty;
                 MessageBox.Show(LocalizedStrings.LocalizedResources.AuthCredentialsError);
             }
             else if (status.IsPermissionError)
             {
                 this.Password.Password = String.Empty;
                 MessageBox.Show(LocalizedStrings.LocalizedResources.AuthNoMemberError);
             }
             else
             {
                 this.Password.Password = String.Empty;
                 MessageBox.Show(LocalizedStrings.LocalizedResources.AuthUnknownError);
             }
         }
     }
     catch (Exception e)
     {
         if (e is HockeyApp.Exceptions.WebTransferException)
         {
             MessageBox.Show(LocalizedStrings.LocalizedResources.AuthNetworkError);
         }
         else
         {
             MessageBox.Show(LocalizedStrings.LocalizedResources.AuthUnknownError);
         }
     }
     finally
     {
         SystemTray.ProgressIndicator.IsVisible = false;
     }
 }
        internal static async Task <IAuthStatus> DoAuthRequestHandleResponseAsync(HttpWebRequest request)
        {
            WebResponse response = null;

            try
            {
                response = await request.GetResponseAsync();
            }
            catch (WebException webEx)
            {
                if ((webEx.Status == WebExceptionStatus.ConnectFailure) ||
                    (webEx.Status == WebExceptionStatus.SendFailure) ||
                    (webEx.Response == null || String.IsNullOrWhiteSpace(webEx.Response.ContentType)))
                {
                    HockeyClient.Current.AsInternal().HandleInternalUnhandledException(webEx);
                    throw new WebTransferException("Could not connect to server.", webEx);
                }
                else
                {
                    if ((webEx.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotFound)
                    {
                        return(AuthStatus.NotFoundAuthStatus);
                    }
                    else if ((webEx.Response as HttpWebResponse).StatusCode == HttpStatusCode.Unauthorized)
                    {
                        return(AuthStatus.NotAuthorizedAuthStatus);
                    }
                    //sent if token is invalid
                    else if ((int)(webEx.Response as HttpWebResponse).StatusCode == 422)
                    {
                        return(AuthStatus.NotAuthorizedAuthStatus);
                    }
                    else
                    {
                        HockeyClient.Current.AsInternal().HandleInternalUnhandledException(webEx);
                        return(AuthStatus.InvalidAuthStatus);
                    }
                }
            }
            IAuthStatus checkedAuthStatus = await TaskEx.Run(() => AuthStatus.FromJson(response.GetResponseStream()));

            return(checkedAuthStatus);
        }
Esempio n. 8
0
        internal async Task <IAuthStatus> AuthorizeUserAsync(string password)
        {
            IAuthStatus status = null;

            try
            {
                IsShowOverlay = true;
                status        = await HockeyClient.Current.AsInternal().AuthorizeUserAsync(this.Email, password ?? "");

                if (status.IsAuthorized)
                {
                    AuthManager.Instance.CurrentAuthStatus = status;
                }
            }
            catch (WebTransferException wte)
            {
                HandleNetworkError(wte);
            }
            finally
            {
                IsShowOverlay = false;
            }
            return(status);
        }
Esempio n. 9
0
        internal async Task <IAuthStatus> IdentifyUserAsync()
        {
            IAuthStatus status = null;

            try
            {
                IsShowOverlay = true;
                status        = await HockeyClient.Current.AsInternal().IdentifyUserAsync(this.Email, this.AppSecret);

                if (status.IsIdentified)
                {
                    AuthManager.Instance.CurrentAuthStatus = status;
                }
            }
            catch (WebTransferException wte)
            {
                HandleNetworkError(wte);
            }
            finally
            {
                IsShowOverlay = false;
            }
            return(status);
        }
Esempio n. 10
0
        //;

        internal async Task <bool> CheckAndHandleExistingTokenAsync(AuthenticationMode authMode, AuthValidationMode validationMode)
        {
            string serializedAuthStatus = await RetrieveProtectedStringAsync(ConstantsUniversal.AuthStatusKey);

            if (!String.IsNullOrEmpty(serializedAuthStatus))
            {
                var aS = AuthStatus.DeserializeFromString(serializedAuthStatus);
                //consider that a change in Authmode is possible between versions of an app, so check if the saved token may be trusted
                if (AuthenticationMode.Authorize.Equals(authMode) && !aS.IsAuthorized || AuthenticationMode.Identify.Equals(authMode) && aS.IsAuthorized)
                {
                    return(false);
                }
                else if (NetworkInterface.GetIsNetworkAvailable())
                {
                    Exception error = null;
                    try
                    {
                        if (await aS.CheckIfStillValidAsync())
                        {
                            _authStatus = aS;
                            ExecuteSuccessRedirectOrAction();
                            return(true);
                        }
                    }
                    catch (WebTransferException e)
                    {
                        HockeyClient.Current.AsInternal().HandleInternalUnhandledException(e);
                        error = e;
                    }
                    if (error != null)
                    {
                        if (AuthValidationMode.Graceful.Equals(validationMode))
                        {
                            _authStatus = aS;
                            ExecuteSuccessRedirectOrAction();
                            return(true);
                        }
                        else
                        {
                            await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                            {
                                await new MessageDialog(LocalizedStrings.LocalizedResources.AuthNetworkError).ShowAsync();
                            });
                        }
                    }
                }
                else
                {
                    if (AuthValidationMode.Graceful.Equals(validationMode))
                    {
                        ExecuteSuccessRedirectOrAction();
                        return(true);
                    }
                    else
                    {
                        await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                        {
                            await new MessageDialog(LocalizedStrings.LocalizedResources.AuthNetworkError).ShowAsync();
                        });
                    }
                }
            }
            return(false);
        }
Esempio n. 11
0
        //;

        internal async Task<bool> CheckAndHandleExistingTokenAsync(AuthenticationMode authMode, AuthValidationMode validationMode)
        {

            string serializedAuthStatus = await RetrieveProtectedStringAsync(ConstantsUniversal.AuthStatusKey);
            if (!String.IsNullOrEmpty(serializedAuthStatus))
            {
                var aS = AuthStatus.DeserializeFromString(serializedAuthStatus);
                //consider that a change in Authmode is possible between versions of an app, so check if the saved token may be trusted
                if (AuthenticationMode.Authorize.Equals(authMode) && !aS.IsAuthorized || AuthenticationMode.Identify.Equals(authMode) && aS.IsAuthorized)
                {
                    return false;
                }
                else if (NetworkInterface.GetIsNetworkAvailable())
                {
                    Exception error = null;
                    try
                    {
                        if (await aS.CheckIfStillValidAsync())
                        {
                            _authStatus = aS;
                            ExecuteSuccessRedirectOrAction();
                            return true;
                        }
                    }
                    catch (WebTransferException e)
                    {
                        HockeyClient.Current.AsInternal().HandleInternalUnhandledException(e);
                        error = e;
                    }
                    if (error != null)
                    {
                        if (AuthValidationMode.Graceful.Equals(validationMode))
                        {
                            _authStatus = aS;
                            ExecuteSuccessRedirectOrAction();
                            return true;
                        }
                        else
                        {
                            await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                            {
                                await new MessageDialog(LocalizedStrings.LocalizedResources.AuthNetworkError).ShowAsync();
                            });
                        }
                    }
                }
                else
                {
                    if (AuthValidationMode.Graceful.Equals(validationMode))
                    {
                        ExecuteSuccessRedirectOrAction();
                        return true;
                    }
                    else
                    {
                        await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                        {
                            await new MessageDialog(LocalizedStrings.LocalizedResources.AuthNetworkError).ShowAsync();
                        });
                    }
                }
            }
            return false;
        }
Esempio n. 12
0
 internal async Task UpdateAuthStatusAsync(IAuthStatus newStatus)
 {
     if (newStatus as AuthStatus != null && newStatus.IsIdentified)
     {
         await StoreStringProtectedAsync(ConstantsUniversal.AuthStatusKey, (newStatus as AuthStatus).SerializeToString());
         HockeyClient.Current.AsInternal().PlatformHelper.SetSettingValue(ConstantsUniversal.AuthLastAuthorizedVersionKey, HockeyClient.Current.AsInternal().VersionInfo);
     }
     _authStatus = newStatus;
 }