protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            OAuthProviderSetting oauth = new OAuthProviderSetting();
            var auth = oauth.LoginWithProvider("Facebook");

            PresentViewController(auth.GetUI(), true, null);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);

            OAuthProviderSetting oauth = new OAuthProviderSetting();
            var auth = oauth.LoginWithProvider("Facebook");

            Windows.UI.Xaml.Controls.Frame rootFrame = Windows.UI.Xaml.Window.Current.Content as Windows.UI.Xaml.Controls.Frame;
            rootFrame.Navigate(auth.GetUI(), auth);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);

            OAuthProviderSetting oauth = new OAuthProviderSetting();
            var auth = oauth.LoginWithProvider("Google");

            var activity = Context as Activity;

            activity.StartActivity(auth.GetUI(activity));
        }
Пример #4
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);

            //Get and Assign ProviderName from ProviderLoginPage
            var    loginPage    = Element as ProviderLoginPage;
            string providername = loginPage.ProviderName;

            var activity = this.Context as Activity;

            if (showLogin && OAuthConfig.User == null)
            {
                showLogin = false;


                OAuthProviderSetting oauth = new OAuthProviderSetting();

                var auth = oauth.LoginWithProvider(providername);

                // After facebook,google and all identity provider login completed
                auth.Completed += async(sender, eventArgs) =>
                {
                    if (eventArgs.IsAuthenticated)
                    {
                        OAuthConfig.User = new Models.Usuario();
                        // Get and Save User Details
                        OAuthConfig.User.Token       = eventArgs.Account.Properties["access_token"];
                        OAuthConfig.User.TokenSecret = eventArgs.Account.Properties["expires_in"];

                        var request  = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me"), null, eventArgs.Account);
                        var response = await request.GetResponseAsync();

                        var obj = JObject.Parse(response.GetResponseText());


                        OAuthConfig.User.TwitterId  = obj["id"].ToString().Replace("\"", "");
                        OAuthConfig.User.ScreenName = obj["name"].ToString().Replace("\"", "");

                        OAuthConfig.SuccessfulLoginAction.Invoke();
                    }
                    else
                    {
                        // The user cancelled
                    }
                };


                activity.StartActivity(auth.GetUI(activity));
            }
        }
Пример #5
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);

            var activity = this.Context as Activity;

            if (showLogin)
            {
                showLogin = false;

                //Classe OauthProviderSetting contém implementação do Oauth
                OAuthProviderSetting oauth = new OAuthProviderSetting();

                var auth = oauth.LoginWithProvider();

                //permite que usuário cancele a autenticação
                auth.AllowCancel = true;

                //Após login com facebook tiver sido completado
                auth.Completed += async(sender, eventArgs) =>
                {
                    if (eventArgs.IsAuthenticated == false)
                    {
                        return;
                    }

                    //Obtém dados de autenticação do usuário
                    await oauth.RequestLoginData(eventArgs.Account);

                    var telaInicial = new Views.MasterDetailPrincipal();
                    App.MyApp.MainPage = telaInicial;
                };

                //inicia tela de login via Facebook
                activity.StartActivity((Android.Content.Intent)auth.GetUI(activity));
            }
        }
Пример #6
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);

            //Get and Assign ProviderName from ProviderLoginPage
            var    loginPage    = Element as ProviderLoginPage;
            string providername = loginPage.ProviderName;

            var activity = this.Context as Activity;

            if (showLogin && OAuthConfig.User == null)
            {
                showLogin = false;

                //Create OauthProviderSetting class with Oauth Implementation .Refer Step 6
                OAuthProviderSetting oauth = new OAuthProviderSetting();

                if (providername == "Twitter")
                {
                    var auth = oauth.LoginWithTwitter();
                    // After Twitter  login completed
                    auth.Completed += (sender, eventArgs) =>
                    {
                        if (eventArgs.IsAuthenticated)
                        {
                            OAuthConfig.User = new UserDetails();
                            // Get and Save User Details
                            OAuthConfig.User.Token       = eventArgs.Account.Properties["oauth_token"];
                            OAuthConfig.User.TokenSecret = eventArgs.Account.Properties["oauth_token_secret"];
                            OAuthConfig.User.TwitterId   = eventArgs.Account.Properties["user_id"];
                            OAuthConfig.User.ScreenName  = eventArgs.Account.Properties["screen_name"];

                            OAuthConfig.SuccessfulLoginAction.Invoke();
                        }
                        else
                        {
                            // The user cancelled
                        }
                    };


                    activity.StartActivity(auth.GetUI(activity));
                }
                else
                {
                    var auth = oauth.LoginWithProvider(providername);

                    // After facebook,google and all identity provider login completed
                    auth.Completed += (sender, eventArgs) =>
                    {
                        if (eventArgs.IsAuthenticated)
                        {
                            OAuthConfig.User = new UserDetails();
                            // Get and Save User Details
                            OAuthConfig.User.Token       = eventArgs.Account.Properties["oauth_token"];
                            OAuthConfig.User.TokenSecret = eventArgs.Account.Properties["oauth_token_secret"];
                            OAuthConfig.User.TwitterId   = eventArgs.Account.Properties["user_id"];
                            OAuthConfig.User.ScreenName  = eventArgs.Account.Properties["screen_name"];

                            OAuthConfig.SuccessfulLoginAction.Invoke();
                        }
                        else
                        {
                            // The user cancelled
                        }
                    };


                    activity.StartActivity(auth.GetUI(activity));
                }
            }
        }
Пример #7
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            //Get and Assign ProviderName from ProviderLoginPage
            var    loginPage    = Element as ProviderLoginPage;
            string providername = loginPage.ProviderName;


            if (showLogin && OAuthConfig.User == null)
            {
                showLogin = false;

                //Create OauthProviderSetting class with Oauth Implementation .Refer Step 6
                OAuthProviderSetting oauth = new OAuthProviderSetting();

                if (providername == "Twitter")
                {
                    var auth = oauth.LoginWithTwitter();
                    // After Twitter  login completed
                    auth.Completed += (sender, eventArgs) =>
                    {
                        if (eventArgs.IsAuthenticated)
                        {
                            OAuthConfig.User = new UserDetails();
                            // Get and Save User Details
                            OAuthConfig.User.Token       = eventArgs.Account.Properties["oauth_token"];
                            OAuthConfig.User.TokenSecret = eventArgs.Account.Properties["oauth_token_secret"];
                            OAuthConfig.User.TwitterId   = eventArgs.Account.Properties["user_id"];
                            OAuthConfig.User.ScreenName  = eventArgs.Account.Properties["screen_name"];

                            OAuthConfig.SuccessfulLoginAction.Invoke();
                        }
                        else
                        {
                            // The user cancelled
                        }
                    };


                    PresentViewController(auth.GetUI(), true, null);
                }
                else
                {
                    var auth = oauth.LoginWithProvider(providername);

                    // After facebook,google and all identity provider login completed
                    auth.Completed += (sender, eventArgs) =>
                    {
                        if (eventArgs.IsAuthenticated)
                        {
                            OAuthConfig.User = new UserDetails();
                            // Get and Save User Details
                            OAuthConfig.User.Token       = eventArgs.Account.Properties["oauth_token"];
                            OAuthConfig.User.TokenSecret = eventArgs.Account.Properties["oauth_token_secret"];
                            OAuthConfig.User.TwitterId   = eventArgs.Account.Properties["user_id"];
                            OAuthConfig.User.ScreenName  = eventArgs.Account.Properties["screen_name"];

                            OAuthConfig.SuccessfulLoginAction.Invoke();
                        }
                        else
                        {
                            // The user cancelled
                        }
                    };


                    PresentViewController(auth.GetUI(), true, null);
                }
            }
        }
Пример #8
0
        private void LoginClick(object sendervalue, RoutedEventArgs e)
        {
            Button btnname = (Button)sendervalue;

            string providername = btnname.Content.ToString();


            if (showLogin && OAuthConfig.User == null)
            {
                showLogin = false;

                //Create OauthProviderSetting class with Oauth Implementation .Refer Step 6
                OAuthProviderSetting oauth = new OAuthProviderSetting();

                if (providername == "Twitter")
                {
                    var auth = oauth.LoginWithTwitter();
                    // After Twitter  login completed
                    auth.Completed += (sender, eventArgs) =>
                    {
                        if (eventArgs.IsAuthenticated)
                        {
                            OAuthConfig.User = new UserDetails();
                            // Get and Save User Details
                            OAuthConfig.User.Token       = eventArgs.Account.Properties["oauth_token"];
                            OAuthConfig.User.TokenSecret = eventArgs.Account.Properties["oauth_token_secret"];
                            OAuthConfig.User.TwitterId   = eventArgs.Account.Properties["user_id"];
                            OAuthConfig.User.ScreenName  = eventArgs.Account.Properties["screen_name"];

                            OAuthConfig.SuccessfulLoginAction.Invoke();
                        }
                        else
                        {
                            // The user cancelled
                        }
                    };


                    //Uri uri = auth.GetUI();
                    Type page_type = auth.GetUI();

                    //(System.Windows.Application.Current.RootVisual as PhoneApplicationFrame).Navigate(uri);
                    this.Frame.Navigate(page_type, auth);
                }
                else
                {
                    var auth = oauth.LoginWithProvider(providername);

                    // After facebook,google and all identity provider login completed
                    auth.Completed += (sender, eventArgs) =>
                    {
                        if (eventArgs.IsAuthenticated)
                        {
                            OAuthConfig.User = new UserDetails();
                            // Get and Save User Details
                            OAuthConfig.User.Token       = eventArgs.Account.Properties["oauth_token"];
                            OAuthConfig.User.TokenSecret = eventArgs.Account.Properties["oauth_token_secret"];
                            OAuthConfig.User.TwitterId   = eventArgs.Account.Properties["user_id"];
                            OAuthConfig.User.ScreenName  = eventArgs.Account.Properties["screen_name"];

                            OAuthConfig.SuccessfulLoginAction.Invoke();
                        }
                        else
                        {
                            // The user cancelled
                        }
                    };

                    auth.Error             += Auth_Error;
                    auth.BrowsingCompleted += Auth_BrowsingCompleted;

                    //Uri uri = auth.GetUI();
                    Type page_type = auth.GetUI();

                    //(System.Windows.Application.Current.RootVisual as PhoneApplicationFrame).Navigate(uri);
                    this.Frame.Navigate(page_type, auth);
                }
            }
        }