Пример #1
0
 /// <summary>
 /// Initializes the Facebook Authentication Service using the Application Key and Secret assigned
 /// by Facebook.com
 /// </summary>
 public FacebookService()
 {
     _fbService = new facebook.Components.FacebookService();
     //  _fbService.ApplicationKey = "6560061f1ff3e1765a19102f085580d5";
     //  _fbService.Secret = "09237e7733e8aaab94f0c716a5e3b569";
     _fbService.ApplicationKey       = StorageManager.getEnvValue("fbServiceApplicationKey");
     _fbService.Secret               = StorageManager.getEnvValue("fbServiceSecret");
     _fbService.IsDesktopApplication = false;
     if (_service == null)
     {
         List <Security.Service> extServices = Security.ExternalService.List();
         foreach (Security.Service service in extServices)
         {
             if (service.ServiceName.Equals(serviceName))
             {
                 _service = service;
             }
         }
     }
 }
Пример #2
0
        public ActionResult Index()
        {
            facebook.Components.FacebookService fbSvc = new facebook.Components.FacebookService();
            fbSvc.ApplicationKey = Settings.FacebookApiKey;
            fbSvc.Secret = Settings.FacebookApiSecret;
            fbSvc.IsDesktopApplication = false;

            // if this cookie is set, the user should have a session
            if (null != Request.Cookies[Constants.Keys.FACEBOOK_USER_SESSION_COOKIE_KEY])
            {
                HttpCookie cookie = Request.Cookies[Constants.Keys.FACEBOOK_USER_SESSION_COOKIE_KEY];
                fbSvc.SessionKey = cookie[Constants.Keys.FACEBOOK_USER_SESSION_KEY];
                fbSvc.uid = long.Parse(cookie[Constants.Keys.FACEBOOK_USER_ID_KEY]);
            }

            // when the user uses the facebook login page, the redirect back here will have the auth_token in the query params
            else if (!string.IsNullOrEmpty(Request.QueryString[Constants.QueryStringKeys.FACEBOOK_AUTH_TOKEN]))
            {
                fbSvc.CreateSession(Request.QueryString[Constants.QueryStringKeys.FACEBOOK_AUTH_TOKEN]);
                HttpCookie cookie = new HttpCookie(Constants.Keys.FACEBOOK_USER_SESSION_COOKIE_KEY);
                cookie[Constants.Keys.FACEBOOK_USER_SESSION_KEY] = fbSvc.SessionKey;
                cookie[Constants.Keys.FACEBOOK_USER_ID_KEY] = fbSvc.uid.ToString();
                cookie[Constants.Keys.FACEBOOK_USER_SESSION_EXPIRES] = fbSvc.SessionExpires.ToString();

                // if the facebook session never expires, set our cookie to expire
                // if the facebook session does expire, not setting the cookie expiry will wipe
                // cookie clean on browser close
                if (!fbSvc.SessionExpires) cookie.Expires = DateTime.Now.AddMinutes(60);

                Response.Cookies.Add(cookie);
            }
            else
            {
                Response.Redirect(Settings.FacebookLoginPageUrl, true);
            }

            return View("Facebook1", fbSvc.friends.getUserObjects());
        }