void LoginToFacebook (object sender, EventArgs e)
		{
			var auth = new OAuth2Authenticator (
				clientId: "346691492084618",
				scope: "",
				authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
				redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));

			// If authorization succeeds or is canceled, .Completed will be fired.
			auth.Completed += (s, ee) => {
				if (!ee.IsAuthenticated) {
					this.facebookStatus.Text = "Not Authenticated";
					return;
				}

				// Now that we're logged in, make a OAuth2 request to get the user's info.
				var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, ee.Account);
				request.GetResponseAsync().ContinueWith (t => {
					if (t.IsFaulted)
						this.facebookStatus.Text = "Error: " + t.Exception.InnerException.Message;
					else if (t.IsCanceled)
						this.facebookStatus.Text = "Canceled";
					else
					{
						var obj = JsonValue.Parse (t.Result.GetResponseText());
						this.facebookStatus.Text = "Logged in as " + obj["name"];
					}
				}, uiScheduler);
			};

			var intent = auth.GetUI (this);
			StartActivityForResult (intent, 42);
		}
		private void FacebookAuthorizationCompleted(object sender, AuthenticatorCompletedEventArgs e)
		{
			dialog.DismissViewController (true, null);
			
			if (!e.IsAuthenticated) {
				facebookStatus.Caption = "Not authorized";
				dialog.ReloadData();
				return;
			}

			String accessToken = String.Empty;
			e.Account.Properties.TryGetValue("access_token", out accessToken);

			var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, e.Account);
			request.GetResponseAsync().ContinueWith (t =>
         	{
				if (t.IsFaulted)
					facebookStatus.Caption = "Error: " + t.Exception.InnerException.Message;
				else if (t.IsCanceled)
					facebookStatus.Caption = "Canceled";
				else
				{
					//Parse Json result

					var obj = JsonValue.Parse (t.Result.GetResponseText());
					facebookStatus.Caption = "Logged in as " + obj["name"];
				}
				
				dialog.ReloadData();
			},
			uiScheduler);
		}
Exemple #3
0
		void LoginToFacebook (bool allowCancel)
		{
			var auth = new OAuth2Authenticator (
				clientId: "App ID from https://developers.facebook.com/apps",
				scope: "",
				authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
				redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));

			auth.AllowCancel = allowCancel;

			// If authorization succeeds or is canceled, .Completed will be fired.
			auth.Completed += (s, ee) => {
				if (!ee.IsAuthenticated) {
					var builder = new AlertDialog.Builder (this);
					builder.SetMessage ("Not Authenticated");
					builder.SetPositiveButton ("Ok", (o, e) => { });
					builder.Create().Show();
					return;
				}

				// Now that we're logged in, make a OAuth2 request to get the user's info.
				var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, ee.Account);
				request.GetResponseAsync().ContinueWith (t => {
					var builder = new AlertDialog.Builder (this);
					if (t.IsFaulted) {
						builder.SetTitle ("Error");
						builder.SetMessage (t.Exception.Flatten().InnerException.ToString());
					} else if (t.IsCanceled)
						builder.SetTitle ("Task Canceled");
					else {
						var obj = JsonValue.Parse (t.Result.GetResponseText());

						builder.SetTitle ("Logged in");
						builder.SetMessage ("Name: " + obj["name"]);
					}

					builder.SetPositiveButton ("Ok", (o, e) => { });
					builder.Create().Show();
				}, UIScheduler);
			};

			var intent = auth.GetUI (this);
			StartActivity (intent);
		}
Exemple #4
0
		void LoginToFacebook (bool allowCancel)
		{
			var auth = new OAuth2Authenticator (
				clientId: "App ID from https://developers.facebook.com/apps",
				scope: "",
				authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
				redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));

			auth.AllowCancel = allowCancel;

			// If authorization succeeds or is canceled, .Completed will be fired.
			auth.Completed += (s, e) =>
			{
				// We presented the UI, so it's up to us to dismiss it.
				dialog.DismissViewController (true, null);

				if (!e.IsAuthenticated) {
					facebookStatus.Caption = "Not authorized";
					dialog.ReloadData();
					return;
				}

				// Now that we're logged in, make a OAuth2 request to get the user's info.
				var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, e.Account);
				request.GetResponseAsync().ContinueWith (t => {
					if (t.IsFaulted)
						facebookStatus.Caption = "Error: " + t.Exception.InnerException.Message;
					else if (t.IsCanceled)
						facebookStatus.Caption = "Canceled";
					else
					{
						var obj = JsonValue.Parse (t.Result.GetResponseText());
						facebookStatus.Caption = "Logged in as " + obj["name"];
					}

					dialog.ReloadData();
				}, uiScheduler);
			};

			UIViewController vc = auth.GetUI ();
			dialog.PresentViewController (vc, true, null);
		}
Exemple #5
0
        async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            var authenticator = sender as OAuth2Authenticator;

            if (authenticator != null)
            {
                authenticator.Completed -= OnAuthCompleted;
                authenticator.Error     -= OnAuthError;
            }

            UserProfile userProfile = null;

            if (e.IsAuthenticated)
            {
                var tokeType    = e.Account.Properties.ContainsKey("token_type") ? e.Account.Properties["token_type"] : "";
                var accessToken = e.Account.Properties.ContainsKey("access_token") ?  e.Account.Properties["access_token"] : "";
                var expires     = e.Account.Properties.ContainsKey("expires_in") ? e.Account.Properties["expires_in"] : "";

                Debug.WriteLine($"{tokeType} Access Token : {accessToken}");
                var request  = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account);
                var response = await request.GetResponseAsync();

                if (response != null)
                {
                    var result = await response.GetResponseTextAsync();

                    userProfile = JsonConvert.DeserializeObject <UserProfile>(result, new JsonSerializerSettings()
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    });

                    Debug.WriteLine(result);
                }

                if (_account != null)
                {
                    await _store.DeleteAsync(_account, Constants.AppName);

                    await _store.SaveAsync(_account = e.Account, Constants.AppName);
                }
            }
        }
Exemple #6
0
        public async void InstagramCompletedAutgenticated(object sender, AuthenticatorCompletedEventArgs eventArgs)
        {
            if (eventArgs.IsAuthenticated)
            {
                Account loggedInAccount = eventArgs.Account;
                var     request         = new OAuth2Request("GET",
                                                            new Uri("https://api.instagram.com/v1/users/self/?access_token=8496248657.f23b40b.fbb30e8c10ff4214ad833e2ea3035deb"),
                                                            null,
                                                            eventArgs.Account);
                var response = await request.GetResponseAsync();

                var json    = response.GetResponseText();
                var jobject = JObject.Parse(json);
                var id_user = jobject["data"]["id"]?.ToString();
                loggedInAccount.Properties.Add("id", id_user);
                CurrentInstagramUser.CurrentInstagramUserId = id_user;
                AccountStore.Create().Save(loggedInAccount, "InstagramUser");
                OnLoggedInHandler();
            }
        }
Exemple #7
0
        void LoginToFacebook(object sender, EventArgs e)
        {
            var auth = new OAuth2Authenticator(
                clientId: "597442676937621",
                scope: "email,user_about_me",
                authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"),
                redirectUrl: new Uri("http://www.facebook.com/connect/login_success.html"));

            // If authorization succeeds or is canceled, .Completed will be fired.
            auth.Completed += (s, ee) => {
                if (!ee.IsAuthenticated)
                {
                    _facebookStatusView.Text = "Not Authenticated";
                    return;
                }

                // Now that we're logged in, make a OAuth2 request to get the user's info.
                var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me"), null, ee.Account);
                request.GetResponseAsync().ContinueWith(t => {
                    if (t.IsFaulted)
                    {
                        _facebookStatusView.Text = "Error: " + t.Exception.InnerException.Message;
                    }
                    else if (t.IsCanceled)
                    {
                        _facebookStatusView.Text = "Canceled";
                    }
                    else
                    {
                        var obj = JsonValue.Parse(t.Result.GetResponseText());
                        _facebookStatusView.Text = "Logged in as " + obj["name"];
                        _emailView.Text          = obj["email"];
                        _genderView.Text         = obj["gender"];
                    }
                }, uiScheduler);
            };

            var intent = auth.GetUI(this);

            StartActivityForResult(intent, 42);
        }
Exemple #8
0
        // Listener per l'autenticazione.
        async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            // Se l'utente è stato autenticato con successo si tenta di accedere alle informazioni dell'account Google tramite una richiesta GET.
            if (e.IsAuthenticated)
            {
                NotLogged.IsVisible     = false;
                LoadContainer.IsVisible = true;
                IsLoading.IsRunning     = true;
                Console.WriteLine("------------ YATTASO: User successfully authenticated!");
                string UserInfoUrl = "https://www.googleapis.com/oauth2/v2/userinfo";
                var    request     = new OAuth2Request("GET", new Uri(UserInfoUrl), null, e.Account);
                var    response    = await request.GetResponseAsync();

                if (response != null)
                {
                    string userJson = response.GetResponseText();
                    // Console.WriteLine("JSON User: "******"User: "******"--------- WAIT A SECOND: User not authenticated! --- ");
            }
        }
        private void FacebookPost(Account facebookAccount, string message, string clientID, string link)
        {
            var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me"), null, facebookAccount);
            request.GetResponseAsync().ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        Console.WriteLine("Error: " + t.Exception.InnerException.Message);
                        FacebookLoginPost(clientID, message, link);
                    }
                    else
                    {
                        // 1. Create the service
                        var facebook = new FacebookService { ClientId = clientID };

                        facebook.SaveAccount(Forms.Context, facebookAccount);

                        // 2. Create an item to share
                        var item = new Item();
                        item.Text = message;
                        if (link != null)
                        {
                            item.Links.Add(new Uri(link));
                        }
                        Device.BeginInvokeOnMainThread(() =>
                            {
                                // 3. Present the UI on iOS
                                var shareIntent = facebook.GetShareUI((Activity)Forms.Context, item, result =>
                                    {
                                        // result lets you know if the user shared the item or canceled
                                    });
                                Forms.Context.StartActivity(shareIntent);
                            });
                    }
                });
        }
Exemple #10
0
        private void FacebookPost(Account facebookAccount, string message, string clientID, string link)
        {
            var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me?"), null, facebookAccount);
            request.GetResponseAsync().ContinueWith(t =>
                {
                    InvokeOnMainThread(() =>
                    {
                        if (t.IsFaulted)
                        {
                            FacebookLoginPost(clientID, message, link);
                        }
                        else
                        {
                            // 1. Create the service
                            var facebook = new FacebookService
                            {
                                ClientId = clientID,
                            };

                            facebook.SaveAccount(facebookAccount);

                            // 2. Create an item to share
                            var item = new Item();
                            item.Text = message;
                            if (!String.IsNullOrEmpty(link) )
                            {
                                item.Links.Add(new Uri(link));
                            }

                            // 3. Present the UI on iOS
                            UIViewController cur_ViewController=(auth_ViewController==null?c_ViewController:auth_ViewController);
                            var shareController = facebook.GetShareUI(item, result =>
                            {
                                            new UIAlertView ("Result",result.ToString(), null, "Ok").Show ();
                                            c_ViewController.DismissViewController(true,null);
                            });
                                    cur_ViewController.PresentViewController(shareController, true, null);
                        }
                    });
                });
        }
        private void FacebookPost(Account facebookAccount, string message, string clientID, string link)
        {
            var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me"), null, facebookAccount);
            request.GetResponseAsync().ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        Console.WriteLine("Error: " + t.Exception.InnerException.Message);
                        FacebookLoginPost(clientID, message, link);
                    }
                    else
                    {
                        // 1. Create the service
                        var facebook = new FacebookService
                        {
                            ClientId = clientID,
                        };

                        facebook.SaveAccount(facebookAccount);

                        // 2. Create an item to share
                        var item = new Item();
                        item.Text = message;
                        if (link != null)
                        {
                            item.Links.Add(new Uri(link));
                        }

                        // 3. Present the UI on iOS
                        InvokeOnMainThread(() =>
                            {
                                var shareController = facebook.GetShareUI(item, result =>
                                    {
                                        UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, null);
                                    });
                                UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(shareController, true, null);
                            });
                    }
                });
        }
		private void VkontakteAuthorizationCompleted(object sender, AuthenticatorCompletedEventArgs e)
		{
			dialog.DismissViewController (true, null);
			
			if (!e.IsAuthenticated)
			{
				vkontakteStatus.Caption = "Not authorized";
				dialog.ReloadData();
				return;
			}
			
			String accessToken = String.Empty;
			e.Account.Properties.TryGetValue("access_token", out accessToken);
			
			String userId = String.Empty;
			e.Account.Properties.TryGetValue("user_id", out userId);
			
			String uri = String.Format("https://api.vk.com/method/users.get?uid={0}&access_token={1}", userId, accessToken);
			
			var request = new OAuth2Request ("GET", new Uri (uri), null, e.Account);
			request.GetResponseAsync().ContinueWith (t => {
				if (t.IsFaulted)
					vkontakteStatus.Caption = "Error: " + t.Exception.InnerException.Message;
				else if (t.IsCanceled)
					vkontakteStatus.Caption = "Canceled";
				else
				{
					//Parse Json result

					var obj = JsonObject.Parse (t.Result.GetResponseText());
					var resp = obj["response"] as JsonArray;
					vkontakteStatus.Caption = "Logged in as " + resp.FirstOrDefault()["first_name"];
				}
				
				dialog.ReloadData();
			}, uiScheduler);
		
		}
		void LoginToVk (bool allowCancel)
		{
			var auth = new OAuth2Authenticator (
				clientId: "5042701",
				scope: "messages",
				authorizeUrl: new Uri("https://oauth.vk.com/authorize"),
				redirectUrl: new Uri("https://oauth.vk.com/blank.html"));

			auth.AllowCancel = allowCancel;

			// If authorization succeeds or is canceled, .Completed will be fired.
			auth.Completed += (s, ee) => {
				if (!ee.IsAuthenticated) {
					var builder = new AlertDialog.Builder (this);
					builder.SetMessage ("Not Authenticated");
					builder.SetPositiveButton ("Ok", (o, e) => { });
					builder.Create().Show();
					return;
				}

				// Now that we're logged in, make a OAuth2 request to get the user's info.
				var request = new OAuth2Request("GET", new Uri("https://api.vk.com/method/users.get"), null, ee.Account);
				request.GetResponseAsync().ContinueWith (t => 
				{
					if (t.IsCompleted)
					{
						Token = ee.Account.Properties["access_token"].ToString();
						Account = ee.Account;

						var response = t.Result.GetResponseText();

						var users = JsonConvert.DeserializeObject<VkUsers>(response);

						string uid = users.response[0].uid;
						string firstName = users.response[0].first_name;
						string lastName = users.response[0].last_name;

						new AlertDialog.Builder(this).SetPositiveButton("Ok", (o, e) => { })
																				 .SetMessage("You logged in succesfully!")
																				 .SetTitle("TalkManager")
																				 .Show();
					}
					else
					{
						var builder = new AlertDialog.Builder(this);
						builder.SetMessage("Not Authenticated");
						builder.SetPositiveButton("Ok", (o, e) => { });
						builder.Create().Show();
						return;
					}
				}, UIScheduler);
			};


			var intent = auth.GetUI (this);
			StartActivity (intent);
		}
		async Task<OAuth2Request> GetDialogs()
		{
			var request = new OAuth2Request("GET", new Uri("https://api.vk.com/method/messages.getDialogs"), null, Account);
			request.Parameters.Add("count", "1");
			request.Parameters.Add("access_token", Token);
			request.Parameters.Add("v", "5.37");

			var res = await request.GetResponseAsync();
			var responseText =  res.GetResponseText();

			var msg = JsonConvert.DeserializeObject<VkMessagesResponse>(responseText);
			string message = msg.Response.Messages.First().Message.Body;

			return null;
		}