/// <summary> /// Internal method for parsing the Facebook oauth ur.. /// </summary> /// <param name="uri"> /// The url to parse. /// </param> /// <param name="throws"> /// Whether to throw the exception or not incase an error occurs. /// </param> /// <returns> /// The <see cref="FacebookOAuthResult"/>. /// </returns> /// <exception cref="InvalidOperationException"> /// Throws if cannot parse the specified url. /// </exception> private static FacebookOAuthResult Parse(Uri uri, bool throws) { IDictionary <string, object> parameters = null; try { bool found = false; if (!string.IsNullOrEmpty(uri.Fragment)) { // #access_token and expires_in are in fragment var fragment = uri.Fragment.Substring(1); parameters = FacebookUtils.ParseUrlQueryString(fragment); if (parameters.ContainsKey("access_token")) { found = true; } } // code, state, error_reason, error and error_description are in query // ?error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request. var queryPart = FacebookUtils.ParseUrlQueryString(uri.Query); if (queryPart.ContainsKey("code") || (queryPart.ContainsKey("error") && queryPart.ContainsKey("error_description"))) { found = true; } if (found) { parameters = FacebookUtils.Merge(parameters, queryPart); return(new FacebookOAuthResult(parameters)); } } catch { if (throws) { throw; } return(null); } if (throws) { throw new InvalidOperationException("Could not parse authentication url."); } return(null); }