public async Task <bool> LoginUserAsync(string providerName) { var context = Android.App.Application.Context; if (!Enum.TryParse(providerName, out MobileServiceAuthenticationProvider provider)) { provider = MobileServiceAuthenticationProvider.Facebook; } var client = AzureClientUtility.GetClient(); // new MobileServiceClient(Constants.AzureServerUrl); try { var user = await client.LoginAsync(context, provider, LoginConfig.Constants.AzureClientSchema); Settings.LastValidToken = user?.MobileServiceAuthenticationToken ?? string.Empty; Settings.UID = user?.UserId ?? string.Empty; LoginConfig.Settings.LoginWithProvider = providerName; return(!string.IsNullOrWhiteSpace(Settings.LastValidToken)); } catch (Exception ex) { Debug.WriteLine(ex); throw; } }
public async Task <bool> LoginUserAsync(string providerName) { if (!Enum.TryParse(providerName, out MobileServiceAuthenticationProvider provider)) { provider = MobileServiceAuthenticationProvider.Facebook; } var client = AzureClientUtility.GetClient(); // new MobileServiceClient( Constants.AzureServerUrl ); AppDelegate.ResumeWithUrl = url => string.Equals(url.Scheme, LoginConfig.Constants.AzureClientSchema) && client.ResumeWithURL(url); try { var user = await client.LoginAsync(UIApplication.SharedApplication.KeyWindow.RootViewController, provider, LoginConfig.Constants.AzureClientSchema); Settings.LastValidToken = user?.MobileServiceAuthenticationToken ?? string.Empty; Settings.UID = user?.UserId ?? string.Empty; LoginConfig.Settings.LoginWithProvider = providerName; return(!string.IsNullOrWhiteSpace(Settings.LastValidToken)); } catch (Exception ex) { //Insights.Report(ex); Debug.WriteLine(ex); throw; } }
private async Task Init(NavigationParameters navigationParameters) { try { var source = navigationParameters.ContainsKey(LoginConfig.Constants.NavigationSourceKey) ? navigationParameters[LoginConfig.Constants.NavigationSourceKey].ToString() : string.Empty; SharedClient.Setup(XpenceConfig.Settings.UID, XpenceConfig.Settings.LastValidToken, LoginConfig.Constants.AzureServerUrl); await Store.InitStore(SharedClient.CurrentClient).ConfigureAwait(false); //user can disable cloud synchronization //If connected to internet we will refresh data with azure and refresh tokens if (Connectivity.IsConnected()) { if (!string.IsNullOrWhiteSpace(XpenceConfig.Settings.LastValidToken)) { //we have saved token and have to check it and refresh //we need the Token var tokenExpired = await AzureClientUtility.IsTokenExpired(XpenceConfig.Settings.LastValidToken); Debug.WriteLine($"Token expired {tokenExpired}"); if (tokenExpired) { await NavigateToLogin(); } else { //check that we have time interval passed after the previous pin if (PinRequired()) { //Pin was entered with error more then N times. redirect to login page //later user could change the pin //in application settings if (string.Equals(source, PinViewResults.PinError.ToString())) { await NavigateToLogin(); } else { await NavigateToPin(); } } else { //check that we need to call initial application wizard if (XpenceConfig.Settings.InitialRegistrationRequired) { await NavigateRegistration(); } else { if (XpenceConfig.Settings.SyncOnStart) { await _itemManagerWrapper.SyncAllAsync(); } //navigate to app await Navigate(NavigationMap.EntryPoint); } } } } else { await NavigateToLogin(); } } else { await Navigate(NavigationMap.OnStartNotificationPage, null, navigationParameters); } } catch (AggregateException ex) { Debug.WriteLine(ex); } catch (Exception ex) { Debug.WriteLine(ex); } }