public static void ShowOAuthView(OAuth2PinBasedFlow oAuth) { currentPage = Application.Current.MainPage; var contentDialog = new ContentPage(); var stackPanel = new StackLayout() { Orientation = StackOrientation.Vertical }; var urlTextBlock = new Label() { Text = "Open URL in Browser: " + oAuth.GetUserTokenUrl(), VerticalTextAlignment = TextAlignment.Center }; var pinTextBox = new Entry { WidthRequest = 150.0f }; var okButton = new Button { Text = "OK" }; okButton.Clicked += async(sender, args) => { if (string.IsNullOrWhiteSpace(pinTextBox.Text)) { await Application.Current.MainPage.DisplayAlert("Error", "Please Enter Pin Code", "OK"); } if (await oAuth.ProcessUserAuthorizationAsync(pinTextBox.Text)) { RestoreView(); } else { await Application.Current.MainPage.DisplayAlert("Error", "Invalid Pin", "OK"); } }; stackPanel.Children.Add(urlTextBlock); stackPanel.Children.Add(pinTextBox); stackPanel.Children.Add(okButton); contentDialog.Content = stackPanel; OnAuthenticated?.Invoke(oAuth, new AuthenticatedEventArgs(oAuth.AccessToken.Code, oAuth.AccessToken.RefreshToken, oAuth.AccessToken.Expires)); Application.Current.MainPage = contentDialog; }
public static async void ShowOAuthView(OAuth2PinBasedFlow oAuth) { StoreElements(); var contentDialog = new ContentDialog(); var stackPanel = new StackPanel { Orientation = Orientation.Vertical }; var urlTextBlock = new TextBlock { Text = "Open URL in Browser: " + oAuth.GetUserTokenUrl(), VerticalAlignment = VerticalAlignment.Center }; var pinTextBox = new TextBox { Width = 150.0f }; var okButton = new Button { Content = "OK" }; okButton.Click += async(sender, args) => { if (string.IsNullOrWhiteSpace(pinTextBox.Text)) { await new MessageDialog("Please Enter Pin").ShowAsync(); } if (await oAuth.ProcessUserAuthorizationAsync(pinTextBox.Text)) { contentDialog.Hide(); } else { await new MessageDialog("Invalid Pin").ShowAsync(); } }; stackPanel.Children.Add(urlTextBlock); stackPanel.Children.Add(pinTextBox); stackPanel.Children.Add(okButton); contentDialog.Content = stackPanel; await contentDialog.ShowAsync(); }