PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/facebook.Linq/Web/FacebookCallback.cs

https://bitbucket.org/assaframan/facebooklinq
C# | 65 lines | 58 code | 4 blank | 3 comment | 7 complexity | 8384c3e7144799311312327cc0764b84 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Web;
  6. using System.Web.SessionState;
  7. namespace facebook.Web
  8. {
  9. /// <summary>
  10. /// Facebook callback URL should be pointed to here
  11. /// </summary>
  12. public class FacebookCallback : IHttpHandler, IRequiresSessionState
  13. {
  14. public void ProcessRequest(HttpContext context)
  15. {
  16. var fc = FacebookContext.Get(context);
  17. var session = fc.Session;
  18. var authenticated = session.IsAuthenticated;
  19. if (!authenticated)
  20. authenticated = session.TryAuthenticating(context.Request);
  21. if (authenticated)
  22. {
  23. var page = Facebook.DefaultPage ?? "./?";
  24. if (page.Contains("?"))
  25. page += "&";
  26. else
  27. page += "?";
  28. page += HttpUtility.UrlDecode(context.Request.QueryString.ToString());
  29. context.Response.Redirect(page);
  30. }
  31. else
  32. {
  33. if (context.Request["app"].IsNotNullOrEmpty())
  34. {
  35. var appName = context.Request["app"];
  36. if (appName.Contains("?"))
  37. appName = appName.Substring(0, appName.IndexOf('?'));
  38. var requestUrl = context.Request.Url;
  39. var redirectedPageQueryString = HttpUtility.UrlEncode("?" + HttpUtility.UrlDecode(context.Request.QueryString.ToString()).Replace('?', '&'));
  40. var url = String.Format("http://apps.facebook.com/{0}/?redirectTo=http://{1}{2}{3}", appName, requestUrl.Host, requestUrl.AbsolutePath, redirectedPageQueryString);
  41. fc.RedirectTopFrame(url);
  42. }
  43. else if (Facebook.HasValidConfiguration)
  44. {
  45. fc.RedirectTopFrame(Facebook.FacebookLoginUrl);
  46. }
  47. else
  48. {
  49. context.Response.Write("Facebook configuration is missing. (facebook.Linq.APIKey, facebook.Linq.Secret, facebook.Linq.ApplicationID)");
  50. }
  51. }
  52. }
  53. public bool IsReusable
  54. {
  55. get
  56. {
  57. return false;
  58. }
  59. }
  60. }
  61. }