Пример #1
0
 public async void OnAuthComplete(object sender, AuthenticatorCompletedEventArgs e)
 {
     if (e.IsAuthenticated && e.Account != null && User != null)
     {
         MainPage = new MainPage();
         await SecureStorageAccountStore.SaveAsync(e.Account, Constants.AppName);
     }
 }
Пример #2
0
        public static async Task LoadAuth()
        {
            List <Account> accounts = await SecureStorageAccountStore.FindAccountsForServiceAsync(App.AppName);

            var account = accounts.FirstOrDefault();

            if (account != null)
            {
                await DoLogin(account.Username, account.Properties["Password"], false);
            }
        }
Пример #3
0
        private async void SocialLoggedInGoogle(object obj)
        {
            string clientId = null;

            string redirectUri = null;

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                clientId    = Constants.GoogleiOSClientId;
                redirectUri = Constants.GoogleiOSRedirectUrl;
                break;

            case Device.Android:
                clientId    = Constants.GoogleAndroidClientId;
                redirectUri = Constants.GoogleAndroidRedirectUrl;
                break;
            }

            //   account = store.FindAccountsForService(Constants.AppName).FirstOrDefault();
            var accounts = await SecureStorageAccountStore.FindAccountsForServiceAsync(Constants.AppName);

            OAuth2Authenticator authenticator = new OAuth2Authenticator(
                clientId,
                null,
                Constants.GoogleScope,
                new Uri(Constants.GoogleAuthorizeUrl),
                new Uri(redirectUri),
                new Uri(Constants.GoogleAccessTokenUrl),
                null,
                true);

            authenticator.Completed += OnAuthCompleted;
            authenticator.Error     += OnAuthError;

            AuthenticationState.Authenticator = authenticator;
            var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();

            try
            {
                presenter.Login(authenticator);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("OAuthLoginPresenter exception error: " + ex.Message);
                if (ex.InnerException != null)
                {
                    Debug.WriteLine("OAuthLoginPresenter inner exception error: " + ex.InnerException.Message);
                }
            }
        }
Пример #4
0
        public async void OnAuthenticationCompleted(Account i_Account)
        {
            try
            {
                await LoginHelper.SaveAccountAndLoginToBackend(i_Account);

                StartMainApp();
            }
            catch
            {
                Helpers.Alert.Show("Error", "There was a problem, please try again later.", this);
                SecureStorageAccountStore.RemoveAllAccounts();
            }
        }
Пример #5
0
        public async void OnAuthenticationCompleted(Account i_Account)
        {
            DismissViewController(true, null);
            try
            {
                await LoginHelper.SaveAccountAndLoginToBackend(i_Account);

                m_HasLoggedIn = true;
                PerformSegue("launchAppSegue", this);
            }
            catch
            {
                Helpers.Alert.Display("Error", "There was a problem, please try again later.", this);
                SecureStorageAccountStore.RemoveAllAccounts();
            }
        }
Пример #6
0
        // TODO: Clean up async/void - Sweeky! ;-)
        async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            var authenticator = sender as OAuth2Authenticator;

            if (authenticator != null)
            {
                authenticator.Completed -= OnAuthCompleted;
                authenticator.Error     -= OnAuthError;
            }

            if (e.IsAuthenticated)
            {
                var request = e.Account;
                //var access_token = request.Properties["access_token"];
                await SecureStorageAccountStore.SaveAsync(e.Account, Constants.AppName);

                await Shell.Current.GoToAsync("//main");
            }
        }
Пример #7
0
        private async void Setup()
        {
            Account account = null;

            try
            {
                account = (await SecureStorageAccountStore.FindAccountsForServiceAsync(Constants.AppName)).SingleOrDefault();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }

            if (account != null)
            {
                MainPage = new MainPage();
                GetUserObject(account);
            }
            else
            {
                MainPage = new NavigationPage(new LoginFlowPage());
            }
        }
Пример #8
0
        private async void SubmitButtonClicked(object obj)
        {
            AppController.AddBusy("SignInViewModel");
            IsPasswordEmpty = string.IsNullOrEmpty(Password);

            if (string.IsNullOrEmpty(Mail) || !mail.Contains("@") || !mail.Contains("."))
            {
                HasError = true;
            }
            else if (!isPasswordEmpty)
            {
                if (await DoLogin(Mail, Password, true))
                {
                    // Save this.
                    Account account = new Account
                    {
                        Username = Mail
                    };
                    account.Properties.Add("Password", Password);
                    await SecureStorageAccountStore.SaveAsync(account, App.AppName);
                }
            }
            AppController.RemoveBusy("SignInViewModel");
        }
        private async void Login_Clicked(object sender, EventArgs e)
        {
            var oAuth = new OAuth2AuthenticatorEx("xamarin-client", "offline_access values-api",
                                                  new Uri(EndPoints.IS4domain + "/connect/authorize"), new Uri(EndPoints.IS4domain + "/grants"))
            {
                AccessTokenUrl = new Uri(EndPoints.IS4domain + "/connect/token"),
                ShouldEncounterOnPageLoading = false
            };

            var account = await SecureStorageAccountStore.FindAccountsForServiceAsync("AuthServer");

            if (account != null && account.Any())
            {
                AuthAccount = account.First();
                Client.DefaultRequestHeaders.Add("Authorization", $"Bearer {AuthAccount.Properties["access_token"]}");
                await Navigation.PushAsync(new ValuesPage());
            }
            else
            {
                var presenter = new OAuthLoginPresenter();
                presenter.Completed += Presenter_Completed;
                presenter.Login(oAuth);
            }
        }
Пример #10
0
        async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            var authenticator = sender as OAuth2Authenticator;

            if (authenticator != null)
            {
                authenticator.Completed -= OnAuthCompleted;
                authenticator.Error     -= OnAuthError;
            }

            if (e.IsAuthenticated)
            {
                if (authenticator.AuthorizeUrl.Host == "www.facebook.com")
                {
                    FacebookEmail facebookEmail = null;

                    var httpClient = new HttpClient();
                    var json       = await httpClient.GetStringAsync($"https://graph.facebook.com/me?fields=id,name,first_name,last_name,email,picture.type(large)&access_token=" + e.Account.Properties["access_token"]);

                    facebookEmail = JsonConvert.DeserializeObject <FacebookEmail>(json);
                    //await store.SaveAsync(account = e.Account, Constants.AppName);

                    try
                    {
                        await SecureStorageAccountStore.SaveAsync(e.Account, Constants.AppName);
                    }
                    catch { }


                    Application.Current.Properties.Remove("Id");
                    Application.Current.Properties.Remove("FirstName");
                    Application.Current.Properties.Remove("LastName");
                    Application.Current.Properties.Remove("DisplayName");
                    Application.Current.Properties.Remove("EmailAddress");
                    Application.Current.Properties.Remove("ProfilePicture");
                    Application.Current.Properties.Add("Id", facebookEmail.Id);
                    Application.Current.Properties.Add("FirstName", facebookEmail.First_Name);
                    Application.Current.Properties.Add("LastName", facebookEmail.Last_Name);
                    Application.Current.Properties.Add("DisplayName", facebookEmail.Name);
                    Application.Current.Properties.Add("EmailAddress", facebookEmail.Email);
                    Application.Current.Properties.Add("ProfilePicture", facebookEmail.Picture.Data.Url);
                    //await Navigation.PushAsync(new ProfilePage());
                    //                    await NavigationService.NavigateTo(typeof(BikeDetailViewModel), string.Empty, string.Empty, true);
                    await NavigationService.NavigateToAsync <BikeDetailViewModel>();
                }
                else
                {
                    SocialMediaUser user = null;

                    // If the user is authenticated, request their basic user data from Google
                    // UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo
                    var request  = new OAuth2Request("GET", new Uri(Constants.GoogleUserInfoUrl), null, e.Account);
                    var response = await request.GetResponseAsync();

                    if (response != null)
                    {
                        // Deserialize the data and store it in the account store

                        // The users email address will be used to identify data in SimpleDB

                        string userJson = await response.GetResponseTextAsync();

                        user = JsonConvert.DeserializeObject <SocialMediaUser>(userJson);
                    }

                    /*if (account != null)
                     * {
                     *  store.Delete(account, Constants.AppName);
                     * }
                     * await store.SaveAsync(account = e.Account, Constants.AppName); */

                    try
                    {
                        await SecureStorageAccountStore.SaveAsync(e.Account, Constants.AppName);
                    }
                    catch { }

                    Application.Current.Properties.Remove("Id");
                    Application.Current.Properties.Remove("FirstName");
                    Application.Current.Properties.Remove("LastName");
                    Application.Current.Properties.Remove("DisplayName");
                    Application.Current.Properties.Remove("EmailAddress");
                    Application.Current.Properties.Remove("ProfilePicture");
                    Application.Current.Properties.Add("Id", user.Id);
                    Application.Current.Properties.Add("FirstName", user.GivenName);
                    Application.Current.Properties.Add("LastName", user.FamilyName);
                    Application.Current.Properties.Add("DisplayName", user.Name);
                    Application.Current.Properties.Add("EmailAddress", user.Email);
                    Application.Current.Properties.Add("ProfilePicture", user.Picture);

                    //await Navigation.PushAsync(new ProfilePage());
                    await NavigationService.NavigateToAsync <BikeDetailViewModel>();

                    //                    await NavigationService.NavigateTo(typeof(BikeDetailViewModel), string.Empty, string.Empty, true);
                }
            }
        }
Пример #11
0
 public void OnAuthenticationFailed(string i_Message, Exception i_Exception)
 {
     // if permission was not granted, we do not want to store any account - to be safe
     Helpers.Alert.Show("Error", "There was a problem, please try again later.", this);
     SecureStorageAccountStore.RemoveAllAccounts();
 }
Пример #12
0
 public void OnAuthenticationFailed(string i_Message, Exception i_Exception)
 {
     DismissViewController(true, null);
     SecureStorageAccountStore.RemoveAllAccounts();
     Helpers.Alert.Display("Error", "There was a problem, please try again later.", this);
 }