/// <summary> /// Initializes a new instance of the <see cref="FacebookSettings"/> class. /// </summary> /// <param name="facebookSettings"> /// The facebook settings. /// </param> /// <remarks> /// Copy constructor /// </remarks> public FacebookSettings(FacebookSettings facebookSettings) { if (facebookSettings == null) return; AccessToken = facebookSettings.AccessToken; ApplicationKey = facebookSettings.ApplicationKey; ApplicationSecret = facebookSettings.ApplicationSecret; PostAuthorizeUrl = facebookSettings.PostAuthorizeUrl; CanvasUrl = facebookSettings.CanvasUrl; AccessExpires = facebookSettings.AccessExpires; DefaultApplicationPermissions = facebookSettings.DefaultApplicationPermissions; UserAgent = facebookSettings.UserAgent; }
/// <summary> /// Initializes a new instance of the <see cref="FacebookSettings"/> class. /// </summary> /// <param name="facebookSettings"> /// The facebook settings. /// </param> /// <remarks> /// Copy constructor /// </remarks> public FacebookSettings(FacebookSettings facebookSettings) { if (facebookSettings == null) { return; } AccessToken = facebookSettings.AccessToken; ApplicationKey = facebookSettings.ApplicationKey; ApplicationSecret = facebookSettings.ApplicationSecret; PostAuthorizeUrl = facebookSettings.PostAuthorizeUrl; CanvasUrl = facebookSettings.CanvasUrl; AccessExpires = facebookSettings.AccessExpires; DefaultApplicationPermissions = facebookSettings.DefaultApplicationPermissions; UserAgent = facebookSettings.UserAgent; }
public static FacebookAuthenticationResult Parse(string url, FacebookSettings facebookSettings) { IDictionary<string, string> paramters; if (url.StartsWith("http://www.facebook.com/connect/login_success.html")) { Uri uri = new Uri(url); if (!string.IsNullOrEmpty(uri.Fragment)) { var pars = FacebookUtils.ParseUrlQueryString(uri.Fragment); paramters = new Dictionary<string, string>(); foreach (var p in pars) { if (p.Key.StartsWith("#")) paramters.Add(p.Key.Substring(1), p.Value[0]); else paramters.Add(p.Key, p.Value[0]); } } else { var pars = FacebookUtils.ParseUrlQueryString(url); paramters = new Dictionary<string, string>(); foreach (var p in pars) { paramters.Add(p.Key, p.Value[0]); } } return new FacebookAuthenticationResult(paramters); } // for now don't allow to parse silverlight and windows phone web, // coz ExchangeAccessTokenForCode needs to have async version. #if !(SILVERLIGHT || WINDOWS_PHONE) else { // its from web var uri = new Uri(url); var pars = FacebookUtils.ParseUrlQueryString(uri.Query); paramters = new Dictionary<string, string>(); foreach (var p in pars) { paramters.Add(p.Key, p.Value[0]); } if (paramters.ContainsKey("signed_request")) { // if we are accessing from iframe canvas // note: needs to enable Canvas Session Parameter and OAuth 2.0 for Canvas (beta) in Migration Tab in app settings. // might add other features later on. if (facebookSettings == null) throw new ArgumentNullException("facebookSettings"); if (string.IsNullOrEmpty(facebookSettings.ApplicationSecret)) throw new ArgumentNullException("facebookSettings.ApplicationSecret"); IDictionary<string, object> jsonObject; if (!ValidateSignedRequest(paramters["signed_request"], facebookSettings.ApplicationSecret, out jsonObject)) throw new InvalidSignedRequestException(); return new FacebookAuthenticationResult(jsonObject); } else if (paramters.ContainsKey("code")) { // incase this is from the web, we need to exchange the code with access token if (facebookSettings == null) throw new ArgumentNullException("facebookSettings"); long expiresIn; string accessToken = Facebook.ExchangeAccessTokenForCode(paramters["code"], facebookSettings.ApplicationKey, facebookSettings.ApplicationSecret, facebookSettings.PostAuthorizeUrl, facebookSettings.UserAgent, out expiresIn); return new FacebookAuthenticationResult(accessToken, expiresIn, null); } } #endif // if its parse error return new FacebookAuthenticationResult(string.Empty, 0, string.Empty); }
public static FacebookAuthenticationResult Parse(string url, FacebookSettings facebookSettings) { IDictionary <string, string> paramters; if (url.StartsWith("http://www.facebook.com/connect/login_success.html")) { Uri uri = new Uri(url); if (!string.IsNullOrEmpty(uri.Fragment)) { var pars = FacebookUtils.ParseUrlQueryString(uri.Fragment); paramters = new Dictionary <string, string>(); foreach (var p in pars) { if (p.Key.StartsWith("#")) { paramters.Add(p.Key.Substring(1), p.Value[0]); } else { paramters.Add(p.Key, p.Value[0]); } } } else { var pars = FacebookUtils.ParseUrlQueryString(url); paramters = new Dictionary <string, string>(); foreach (var p in pars) { paramters.Add(p.Key, p.Value[0]); } } return(new FacebookAuthenticationResult(paramters)); } // for now don't allow to parse silverlight and windows phone web, // coz ExchangeAccessTokenForCode needs to have async version. #if !(SILVERLIGHT || WINDOWS_PHONE) else { // its from web var uri = new Uri(url); var pars = FacebookUtils.ParseUrlQueryString(uri.Query); paramters = new Dictionary <string, string>(); foreach (var p in pars) { paramters.Add(p.Key, p.Value[0]); } if (paramters.ContainsKey("signed_request")) { // if we are accessing from iframe canvas // note: needs to enable Canvas Session Parameter and OAuth 2.0 for Canvas (beta) in Migration Tab in app settings. // might add other features later on. if (facebookSettings == null) { throw new ArgumentNullException("facebookSettings"); } if (string.IsNullOrEmpty(facebookSettings.ApplicationSecret)) { throw new ArgumentNullException("facebookSettings.ApplicationSecret"); } IDictionary <string, object> jsonObject; if (!ValidateSignedRequest(paramters["signed_request"], facebookSettings.ApplicationSecret, out jsonObject)) { throw new InvalidSignedRequestException(); } return(new FacebookAuthenticationResult(jsonObject)); } else if (paramters.ContainsKey("code")) { // incase this is from the web, we need to exchange the code with access token if (facebookSettings == null) { throw new ArgumentNullException("facebookSettings"); } long expiresIn; string accessToken = Facebook.ExchangeAccessTokenForCode(paramters["code"], facebookSettings.ApplicationKey, facebookSettings.ApplicationSecret, facebookSettings.PostAuthorizeUrl, facebookSettings.UserAgent, out expiresIn); return(new FacebookAuthenticationResult(accessToken, expiresIn, null)); } } #endif // if its parse error return(new FacebookAuthenticationResult(string.Empty, 0, string.Empty)); }
/// <summary> /// Initializes a new instance of the <see cref="Facebook"/> class. /// </summary> /// <param name="facebookSettings"> /// The facebook settings. /// </param> public Facebook(FacebookSettings facebookSettings) { _settings = facebookSettings ?? (_settings = new FacebookSettings()); }