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); } }
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); } } }
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()); } }
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); } }