Пример #1
0
        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);
        }
Пример #2
0
        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
                    }
                }
            };
        }
Пример #3
0
        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);
        }
Пример #4
0
        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;

        }
Пример #5
0
        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
                    }
                }
            });
        }