/// <summary> /// Generates the login URL. /// </summary> /// <param name="pCSRFstate">The CSRF web session state. <seealso cref="https://developers.facebook.com/docs/authentication/server-side/" /><seealso cref="http://en.wikipedia.org/wiki/Cross-site_request_forgery" /></param> /// <param name="pPermissions">comma separated list of permission names.<example>email,user_about_me</example></param> /// <param name="pRedirectUrl">The redirect URL.</param> /// <returns></returns> /// <exception cref="System.ApplicationException">pCSRFstate or pRedirectUrl cannot be null</exception> public Uri GenerateLoginUrl(string pCSRFstate, string pPermissions, string pRedirectUrl, OpenStyle pOpenStyle) { if (string.IsNullOrEmpty(pCSRFstate)) throw new ApplicationException("pCSRFstate cannot be null"); if (string.IsNullOrEmpty(pRedirectUrl)) throw new ApplicationException("pRedirectUrl cannot be null"); // for .net 3.5 // var parameters = new Dictionary<string,object> // parameters["client_id"] = appId; dynamic parameters = new ExpandoObject(); parameters.client_id = this._facebookAppId; parameters.redirect_uri = pRedirectUrl; // The requested response: an access token (token), an authorization code (code), or both (code token). parameters.response_type = "code"; // list of additional display modes can be found at http://developers.facebook.com/docs/reference/dialogs/#display switch (pOpenStyle) { case OpenStyle.Popup: parameters.display = "popup"; break; case OpenStyle.Page: parameters.display = "page"; break; default: break; } parameters.state = pCSRFstate; // add the 'scope' parameter only if we have extendedPermissions. if (!string.IsNullOrWhiteSpace(pPermissions)) parameters.scope = pPermissions; // generate the login url var fb = new FacebookClient(); return fb.GetLoginUrl(parameters); }
/// <summary> /// Generates the login URL. /// </summary> /// <param name="pCSRFstate">The CSRF web session state. <seealso cref="https://developers.facebook.com/docs/authentication/server-side/" /><seealso cref="http://en.wikipedia.org/wiki/Cross-site_request_forgery" /></param> /// <param name="pPermissions">comma separated list of permission names.<example>email,user_about_me</example></param> /// <param name="pRedirectUrl">The redirect URL.</param> /// <returns></returns> /// <exception cref="System.ApplicationException">pCSRFstate or pRedirectUrl cannot be null</exception> public Uri GenerateLoginUrl(string pCSRFstate, string pPermissions, string pRedirectUrl, OpenStyle pOpenStyle) { if (string.IsNullOrEmpty(pCSRFstate)) { throw new ApplicationException("pCSRFstate cannot be null"); } if (string.IsNullOrEmpty(pRedirectUrl)) { throw new ApplicationException("pRedirectUrl cannot be null"); } // for .net 3.5 // var parameters = new Dictionary<string,object> // parameters["client_id"] = appId; dynamic parameters = new ExpandoObject(); parameters.client_id = this._facebookAppId; parameters.redirect_uri = pRedirectUrl; // The requested response: an access token (token), an authorization code (code), or both (code token). parameters.response_type = "code"; // list of additional display modes can be found at http://developers.facebook.com/docs/reference/dialogs/#display switch (pOpenStyle) { case OpenStyle.Popup: parameters.display = "popup"; break; case OpenStyle.Page: parameters.display = "page"; break; default: break; } parameters.state = pCSRFstate; // add the 'scope' parameter only if we have extendedPermissions. if (!string.IsNullOrWhiteSpace(pPermissions)) { parameters.scope = pPermissions; } // generate the login url var fb = new FacebookClient(); return(fb.GetLoginUrl(parameters)); }