Beispiel #1
0
 public Authenticator()
 {
     try
     {
         _userService = AppAutoFac.Resolve <IUserService>();
     }
     catch (Exception ex)
     {
         ex.ToString();
         throw;
     }
     _client = AppAutoFac.Resolve <IMobileServiceClient>();
 }
Beispiel #2
0
        public static void NavigateToHomePage()
        {
            try {
                var detailPage = AppAutoFac.ResolvedIViewFactory.Resolve <MainPageViewModel>();

                var masterDetails = new MasterDetailPage
                {
                    Master = AppAutoFac.ResolvedIViewFactory.Resolve <MenuPageViewModel>(),
                    Detail = new NavigationPage(detailPage)
                    {
                        BarTextColor = Color.Black
                    }
                };

                masterDetails.SetBinding(MasterDetailPage.IsPresentedProperty, "IsPresented", BindingMode.TwoWay);
                masterDetails.BindingContext = AppAutoFac.Resolve <MasterDetailPageViewModel>();
                Application.Current.MainPage = masterDetails;
            }
            catch (Exception e)
            {
            }
        }
Beispiel #3
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (this._client == null)
            {
                _client = AppAutoFac.Resolve <IMobileServiceClient>();
                //throw new InvalidOperationException("Make sure to set the 'Client' property in this handler before using it.");
            }

            // Cloning the request, in case we need to send it again
            var clonedRequest = await CloneRequestAsync(request);

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

            if (response.StatusCode == HttpStatusCode.Unauthorized)
            {
                try
                {
                    var authenticator = AppAutoFac.Resolve <IAuthenticator>();
                    await authenticator.AuthenticateAsync(new LoginObject());

                    clonedRequest = await CloneRequestAsync(request);

                    clonedRequest.Headers.Remove("X-ZUMO-AUTH");
                    clonedRequest.Headers.Add("X-ZUMO-AUTH", _client.CurrentUser.MobileServiceAuthenticationToken);

                    // Resend the request
                    response = await base.SendAsync(clonedRequest, cancellationToken);
                }
                catch (InvalidOperationException)
                {
                    // user cancelled auth, so return the original response
                    return(response);
                }
            }

            return(response);
        }
Beispiel #4
0
 public Authenticator()
 {
     _userService = AppAutoFac.Resolve <IUserService>();
     _client      = AppAutoFac.Resolve <IMobileServiceClient>();
 }
Beispiel #5
0
        public async Task Unauthenticate()
        {
            await _client.LogoutAsync();

            await AppAutoFac.Resolve <ISyncService>().PurgeDataAsync();
        }