Esempio n. 1
0
        private async Task <bool> PasswordMatches(string pass)
        {
            var response = await _dataService.UserService.GetCurrentActiveUserAsync();

            string currentPassword = _userCredentialService.GetUserCredential(
                ResourceType.SETTINGS_PASSWORD_RESOURCE,
                response.Result.Email);

            return(currentPassword == pass);
            //            IsErrorVisible = true;
        }
        public async Task <bool> PasswordMatches()
        {
            var response = await _dataService.UserService.GetCurrentActiveUserAsync();

            string currentPassowrd = _credentialService.GetUserCredential(
                ResourceType.SETTINGS_PASSWORD_RESOURCE,
                response.Result.Email);

            if (currentPassowrd == Password)
            {
                IsErrorVisible = false;
                return(true);
            }
            IsErrorVisible = true;
            return(false);
        }
Esempio n. 3
0
        protected override async Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            // Cloning the request, in case we need to send it again
            var clonedRequest = await CloneRequest(request);

            var response = await base.SendAsync(clonedRequest, cancellationToken);

            if (response.StatusCode == HttpStatusCode.Unauthorized)
            {
                try
                {
                    var currentLoggedUsername = _userCredentialService.GetCurrentLoggedUsername();
                    if (string.IsNullOrEmpty(currentLoggedUsername))
                    {
                        await _dialogService.ShowMessageDialogAsync(
                            "Error",
                            "Could't retrieve the current logged username");

                        return(response);
                    }

                    var refreshToken = _userCredentialService.GetUserCredential(
                        ResourceType.REFRESH_TOKEN_RESOURCE,
                        currentLoggedUsername);
                    if (string.IsNullOrEmpty(refreshToken))
                    {
                        await _dialogService.ShowMessageDialogAsync(
                            "Error",
                            "Could't retrieve the refresh token");

                        return(response);
                    }

                    var tokenResponse = await _googleAuthService.GetNewTokenAsync(refreshToken);

                    if (!tokenResponse.Succeed)
                    {
                        await _dialogService.ShowMessageDialogAsync(
                            "Error",
                            "Could't get a new token. Did you remove access to our app :C?");

                        return(response);
                    }

                    var token = tokenResponse.Result;

                    // we're now logged in again.

                    // Clone the request
                    clonedRequest = await CloneRequest(request);

                    // Save the user to the app settings
                    _userCredentialService.UpdateUserCredential(
                        ResourceType.REFRESH_TOKEN_RESOURCE,
                        currentLoggedUsername,
                        false,
                        token.RefreshToken);
                    _userCredentialService.UpdateUserCredential(
                        ResourceType.TOKEN_RESOURCE,
                        currentLoggedUsername,
                        false,
                        token.AccessToken);
                    // Set the authentication header
                    //clonedRequest.Headers.Remove("Bearer");
                    //clonedRequest.Headers.Add("Bearer", newToken.AccessToken);
                    clonedRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
                    // Resend the request
                    response = await base.SendAsync(clonedRequest, cancellationToken);
                }
                catch (InvalidOperationException)
                {
                    // user cancelled auth, so lets return the original response
                    return(response);
                }
            }

            return(response);
        }