Button CreateApiButton(AuthenticatedApi api) { var button = new Button { Text = $"Login: {api.GetType().Name}", }; button.Clicked += async(sender, args) => { try { _sourceApi = api; var account = await api.Authenticate() as OAuthAccount; Console.WriteLine(account.Identifier + " : " + account.Token); await MainPage.DisplayAlert("Success!", "User is logged in", "Ok"); } catch (TaskCanceledException) { Console.WriteLine("Canceled"); await MainPage.DisplayAlert("Error", "User Canceled", "Ok"); } catch (Exception ex) { Console.WriteLine(ex); await MainPage.DisplayAlert("Error", ex.Message, "Ok"); } }; return(button); }
public App() { var scopes = new[] { "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile" }; //api = new GoogleApi("google", // "clientid", // "clientsecret",new ModernHttpClient.NativeMessageHandler()) //{ // Scopes = scopes, //}; api = new FacebookApi("facebook", "", ""); var button = new Button { Text = "Login", }; button.Clicked += async(sender, args) => { try { var account = await api.Authenticate(); var me = await api.Get("me"); Console.WriteLine(account.Identifier); } catch (TaskCanceledException) { Console.WriteLine("Canceled"); } }; // The root page of your application MainPage = new ContentPage { Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { button } } }; }
Button CreateApiButton(AuthenticatedApi api) { var button = new Button { Text = $"Login: {api.GetType().Name}", }; button.Clicked += async(sender, args) => { try { var account = await api.Authenticate(); Console.WriteLine(account.Identifier); } catch (TaskCanceledException) { Console.WriteLine("Canceled"); } }; return(button); }
Button CreateApiButton(AuthenticatedApi api) { var button = new Button { Text = $"Login: {api.GetType().Name}", }; button.Clicked += async (sender, args) => { try { var account = await api.Authenticate(); var me = await api.Get("me"); Console.WriteLine(account.Identifier); } catch (TaskCanceledException) { Console.WriteLine("Canceled"); } }; return button; }
public App() { //Hook up our Forms login page for Basic Auth BasicAuthApi.ShowAuthenticator = (BasicAuthAuthenticator obj) => { MainPage.Navigation.PushModalAsync(new LoginPage(obj)); }; var scopes = new[] { "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile" }; //api = new GoogleApi("google", // "clientid", // "clientsecret",new ModernHttpClient.NativeMessageHandler()) //{ // Scopes = scopes, //}; //api = new FacebookApi("facebook","",""); api = new OAuthPasswordApi("myapi", "clientid", "clientsecret", "https://serverurl.com", "https://tokenurl.com", "https://refreshurl.com") { //Hook up our Forms login page for Oauth with Password CurrentShowAuthenticator = (obj) => { MainPage.Navigation.PushModalAsync(new LoginPage(obj)); }, }; var button = new Button { Text = "Login", }; button.Clicked += async(sender, args) => { try { var account = await api.Authenticate(); var me = await api.Get("me"); Console.WriteLine(account.Identifier); } catch (TaskCanceledException) { Console.WriteLine("Canceled"); } }; // The root page of your application MainPage = new NavigationPage(new ContentPage { Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { button } } }); }