/// <summary> /// Handles user login. /// clientID is from Facebook developer page. /// Sets the scope needed to publish messages on users wall. /// Creates LoginUrl and redirect URL. /// Authentication is handled by WebAuthenticationBroker for save Authentication. /// </summary> public async void FBLogin() { try { //Facebook app id var clientId = "1269278043097270"; //Facebook permissions var scope = "public_profile, publish_actions, manage_pages"; var redirectUri = WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString(); var fb = new Facebook.FacebookClient(); Uri loginUrl = fb.GetLoginUrl(new { client_id = clientId, redirect_uri = redirectUri, response_type = "token", scope = scope }); Uri startUri = loginUrl; Uri endUri = new Uri(redirectUri, UriKind.Absolute); WebAuthenticationResult webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, startUri, endUri); //Get acces token out of resonse data to create a facebook client and facebook user. if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success) { var outputToken = webAuthenticationResult.ResponseData.ToString(); var pattern = string.Format("{0}#access_token={1}&expires_in={2}", WebAuthenticationBroker.GetCurrentApplicationCallbackUri(), "(?<access_token>.+)", "(?<expires_in>.+)"); var match = Regex.Match(outputToken, pattern); var access_token = match.Groups["access_token"]; var expires_in = match.Groups["expires_in"]; accessToken = access_token.Value; TokenExpiry = DateTime.Now.AddSeconds(double.Parse(expires_in.Value)); fbClient = new Facebook.FacebookClient(accessToken); fbUser = await fbClient.GetTaskAsync("me"); WebRequest profilePicRequest = HttpWebRequest.Create(string.Format("https://graph.facebook.com/{0}/picture", fbUser.id)); WebResponse response = await profilePicRequest.GetResponseAsync(); var pictureUrl = response.ResponseUri.ToString(); fbProfilePic.Visibility = Visibility.Visible; fbProfilePic.Source = new BitmapImage(new Uri(pictureUrl, UriKind.Absolute)); fbInfo.Values["token"] = accessToken; fbInfo.Values["profilePicUrl"] = pictureUrl; } else { return; } } catch { return; } }
public ActionResult Facebook(object sender, EventArgs e) { var client = new FacebookClient(); dynamic result = client.GetLoginUrl(new { client_id = "520025764710565", client_secret = "0d7ea70fb467f9f5a5c9444b63f2f8a6", redirect_uri = RedirectUri.AbsoluteUri, response_type = "code", scope = "read_stream" }); return Redirect(result.AbsoluteUri); }
//Khi nhấn nút login vào facebook public ActionResult LoginFacebook(LoginModel model) { var fb = new Facebook.FacebookClient(); var loginUrl = fb.GetLoginUrl(new { client_id = System.Configuration.ConfigurationManager.AppSettings["FbAppId"], client_secret = System.Configuration.ConfigurationManager.AppSettings["FbAppSecret"], redirect_uri = RedirectUri.AbsoluteUri, response_type = "code", scope = "email", }); return(Redirect(loginUrl.AbsoluteUri)); }
public ActionResult Facebook(object sender, EventArgs e) { var client = new FacebookClient(); dynamic result = client.GetLoginUrl(new { client_id = "520025764710565", client_secret = "0d7ea70fb467f9f5a5c9444b63f2f8a6", redirect_uri = RedirectUri.AbsoluteUri, response_type = "code", scope = "read_stream" }); return(Redirect(result.AbsoluteUri)); }
public static string getfburl() { Facebook.FacebookClient fb = new Facebook.FacebookClient(); var loginUrl = fb.GetLoginUrl(new { client_id = APIID, // "1156176144545912", client_secret = SECRETKEY, // "cf33a7b17de11a033c3514a61ea2b233", redirect_uri = REDIRECTURI, // "http://localhost:50903/Account/FacebookLoginResult", response_type = "code", scope = "user_birthday, email" }); return(loginUrl.AbsoluteUri); }
public HttpResponseMessage LoginOpenID() { var fb = new Facebook.FacebookClient(); var loginUrl = fb.GetLoginUrl(new { client_id = "1792549730783013", client_secret = "5fd8d1fe75779972717e0881fc121882", redirect_uri = "https://api.buscity.xyz/Account/Token", response_type = "code", }); var response = Request.CreateResponse(HttpStatusCode.Moved); response.Headers.Location = new Uri(loginUrl.AbsoluteUri); return(response); }
public void Login() { dynamic parameters = new ExpandoObject(); parameters.client_id = client_id; parameters.redirect_uri = redirect_uri; parameters.response_type = "token"; parameters.display = "popup"; if (!string.IsNullOrEmpty(_ExtendedPermissions)) { parameters.scope = _ExtendedPermissions; } Uri login_uri = fb.GetLoginUrl(parameters); this.Navigate(login_uri.AbsoluteUri); }
public ActionResult Facebook(string return_url) { var fb = new Facebook.FacebookClient(); var loginUrl = fb.GetLoginUrl(new { client_id = Util.GetConfigValue("AppFaceBookID", string.Empty), client_secret = Util.GetConfigValue("AppFacebookSecret", string.Empty), redirect_uri = this.RedirectUri.AbsoluteUri, response_type = "code", scope = "email" //// Add other permissions as needed }); if (Url.IsLocalUrl(return_url)) { this.Session["FaceBook_return"] = return_url; } return(this.Redirect(loginUrl.AbsoluteUri)); }
public ActionResult Facebook(string id) { var fb = new Facebook.FacebookClient(); RedirectUri = id == "login" ? new UriBuilder() { Query = null, Fragment = null, Host = Request.Url.Host,Path = Url.Action("FacebookCallbackLogin"), Port = Request.Url.Port}.Uri : new UriBuilder() { Query = null, Fragment = null, Host = Request.Url.Host, Path = Url.Action("FacebookCallback"), Port = Request.Url.Port }.Uri; var loginUrl = fb.GetLoginUrl( new { client_id = "510735142346763", client_secret = "c4df6a6934bc013daa1560bd063921b0", redirect_uri = RedirectUri.AbsoluteUri, response_type = "code", scope = "email" }); return Redirect(loginUrl.AbsoluteUri); }
public ActionResult Facebook(string id) { var fb = new Facebook.FacebookClient(); RedirectUri = id == "login" ? new UriBuilder() { Query = null, Fragment = null, Host = Request.Url.Host,Path = Url.Action("FacebookCallbackLogin"), Port = Request.Url.Port}.Uri : new UriBuilder() { Query = null, Fragment = null, Host = Request.Url.Host, Path = Url.Action("FacebookCallback"), Port = Request.Url.Port }.Uri; var loginUrl = fb.GetLoginUrl( new { client_id = Config.FacebookClientId, client_secret = Config.FacebookClientSecret, redirect_uri = RedirectUri.AbsoluteUri, response_type = "code", scope = "email,user_birthday,publish_actions" }); return Redirect(loginUrl.AbsoluteUri); }