public void ResultShouldNotBeNull() { string whiteSpaceQueryString = " "; var result = FacebookUtils.ParseUrlQueryString(whiteSpaceQueryString); Assert.NotNull(result); }
public void TheCountOfResultShouldBe0() { string whiteSpaceQueryString = " "; var result = FacebookUtils.ParseUrlQueryString(whiteSpaceQueryString); Assert.Equal(0, result.Count); }
public void ItShouldDecodeCorrectly() { var queryString = "code=2.XeyH7lWz33itx1R86_uBeg__.3600.1294930800-100001327642026%7Ct8SsfSR2XI6yhBAkhX95J7p9hJ0"; var result = FacebookUtils.ParseUrlQueryString(queryString); Assert.Equal("2.XeyH7lWz33itx1R86_uBeg__.3600.1294930800-100001327642026|t8SsfSR2XI6yhBAkhX95J7p9hJ0", result["code"]); }
public void Error_descriptionShouldBeDecodedCorrectly() { var queryString = "error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request."; var result = FacebookUtils.ParseUrlQueryString(queryString); Assert.Equal("The user denied your request.", result["error_description"]); }
public void ExpiresInShouldBeDecodedCorrectly() { var queryString = "access_token=124973200873702%7C2.16KX_wTFlY2IAvWucsCKWA__.3600.1294927200-100001327642026%7CERLPsyFd8CP4ZI57VzAn0nl6WXo&expires_in=3699"; var result = FacebookUtils.ParseUrlQueryString(queryString); Assert.Equal("3699", result["expires_in"]); }
protected internal override Uri GetLoginUrl(IFacebookApplication settings, HttpContextBase httpContext, IDictionary <string, object> parameters) { var authorizer = new CanvasAuthorizer(settings, httpContext) { ReturnUrlPath = ReturnUrlPath, CancelUrlPath = CancelUrlPath, LoginDisplayMode = LoginDisplayMode }; if (!String.IsNullOrEmpty(Permissions)) { authorizer.Permissions = Permissions.Replace(" ", String.Empty).Split(','); } if (string.IsNullOrEmpty(CancelUrlPath)) { // set it to this same url instead of going to facebook.com var canvasUrlBuilder = new CanvasUrlBuilder(settings, httpContext.Request); var currentPathAndQuery = canvasUrlBuilder.CurrentCanvasPathAndQuery; if (currentPathAndQuery.Contains("?")) { var parts = currentPathAndQuery.Split('?'); if (parts.Length == 2 && !string.IsNullOrEmpty(parts[1])) { var queryStrings = FacebookUtils.ParseUrlQueryString(parts[1]); // remove oauth 2 error querystrings. // error_reason=user_denied&error_denied=access_denied&error_description=The+user+denied+your+request. if (queryStrings.ContainsKey("error_reason")) { queryStrings.Remove("error_reason"); } if (queryStrings.ContainsKey("error_denied")) { queryStrings.Remove("error_denied"); } if (queryStrings.ContainsKey("error_description")) { queryStrings.Remove("error_description"); } currentPathAndQuery = parts[0] + "?" + FacebookUtils.ToJsonQueryString(queryStrings); } } authorizer.CancelUrlPath = currentPathAndQuery; } return(authorizer.GetLoginUrl(null)); }
public void TheCountOfResultShouldBe0() { var result = FacebookUtils.ParseUrlQueryString(null); Assert.Equal(0, result.Count); }
public void TheResultShouldNotBeNull() { var result = FacebookUtils.ParseUrlQueryString(null); Assert.NotNull(result); }
public void TheCountOfResultShouldBeNumberOfQuerystringKeys(string queryString, int total) { var result = FacebookUtils.ParseUrlQueryString(queryString); Assert.Equal(total, result.Count); }
protected Uri GetUrl(HttpContextBase context) { if (context == null) { throw new ArgumentNullException("context"); } if (context.Request == null) { throw new Exception("context.Request is null"); } // TODO: need unit tests for this method, might as well need to refactor this method. UriBuilder redirectUriBuilder; if (!context.Request.QueryString.AllKeys.Contains("state")) { // todo: better to redirect to the default canvas page. return(new Uri("http://www.facebook.com")); } // if state is present. var state = Encoding.UTF8.GetString(FacebookWebUtils.Base64UrlDecode(context.Request.QueryString["state"])); var json = (IDictionary <string, object>)JsonSerializer.Current.DeserializeObject(state); // make it one letter character so more info can fit in. // r -> return_url_path (full uri) // c -> cancel_url_path (full uri) // s -> user_state FacebookOAuthResult oauthResult; if (!FacebookOAuthResult.TryParse(context.Request.Url, out oauthResult)) { // todo: better to redirect to the default canvas page. return(new Uri("http://www.facebook.com")); } if (oauthResult.IsSuccess) { var returnUrl = json["r"].ToString(); redirectUriBuilder = new UriBuilder(returnUrl); if (returnUrl.Contains("?")) { // incase return url path contains querystrings. var returnUrlParts = returnUrl.Split('?'); if (returnUrlParts.Length == 2 && !string.IsNullOrEmpty(returnUrlParts[1])) { var queryStrings = FacebookUtils.ParseUrlQueryString(returnUrlParts[1]); if (queryStrings.ContainsKey("error_reason")) { // remove oauth stuffs. if (queryStrings.ContainsKey("error_reason")) { queryStrings.Remove("error_reason"); } if (queryStrings.ContainsKey("error")) { queryStrings.Remove("error"); } if (queryStrings.ContainsKey("error_description")) { queryStrings.Remove("error_description"); } redirectUriBuilder.Query = FacebookUtils.ToJsonQueryString(queryStrings); } } } } else { if (!json.ContainsKey("c")) { // there is no cancel url path redirectUriBuilder = new UriBuilder("http://facebook.com"); } else { var cancelUrl = json["c"].ToString(); IDictionary <string, object> cancelUrlQueryStrings = new Dictionary <string, object> { { "error_reason", context.Request.QueryString["error_reason"] }, { "error", context.Request.QueryString["error"] }, { "error_description", context.Request.QueryString["error_description"] } }; if (cancelUrl.Contains("?")) { // incase cancel url path contains querystrings. var cancelUrlParts = cancelUrl.Split('?'); if (cancelUrlParts.Length == 2 && !string.IsNullOrEmpty(cancelUrlParts[1])) { var queryStrings = FacebookUtils.ParseUrlQueryString(cancelUrlParts[1]); cancelUrlQueryStrings = FacebookUtils.Merge(cancelUrlQueryStrings, queryStrings); } } redirectUriBuilder = new UriBuilder(cancelUrl) { Query = FacebookUtils.ToJsonQueryString(cancelUrlQueryStrings) }; } } return(redirectUriBuilder.Uri); }