Esempio n. 1
0
        /// <summary>
        /// Facebook authentication
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void fb_OnClick(object sender, EventArgs e)
        {
            try
            {
                Session["channel"] = Channel.Facebook.ToString();

                //Retrieve values from settings file
                var facebookConsumerKeySettings = ConfigurationManager.AppSettings["FacebookConsumerKey"];
                var facebookConsumerSecretSettings = ConfigurationManager.AppSettings["FacebookConsumerSecret"];
                var facebookVerifierUrlSettings = ConfigurationManager.AppSettings["FacebookVerifierUrl"];
                var facebookRequestAccessTokenUrlSettings = ConfigurationManager.AppSettings["FacebookRequestAccessTokenUrl"];
                var facebookRequestProfileUrlSettings = ConfigurationManager.AppSettings["FacebookRequestProfileUrl"];
                var facebookScopeSettings = ConfigurationManager.AppSettings["FacebookScope"];

                string facebookConsumerKey = string.Empty;
                string facebookConsumerSecret = string.Empty;
                string facebookVerifierUrl = string.Empty;
                string facebookRequestAccessTokenUrl = string.Empty;
                string facebookRequestProfileUrl = string.Empty;
                string facebookScope = string.Empty;

                if (facebookConsumerKeySettings != null)
                    facebookConsumerKey = facebookConsumerKeySettings.ToString();
                if (facebookConsumerSecretSettings != null)
                    facebookConsumerSecret = facebookConsumerSecretSettings.ToString();
                if (facebookVerifierUrlSettings != null)
                    facebookVerifierUrl = facebookVerifierUrlSettings.ToString();
                if (facebookRequestAccessTokenUrlSettings != null)
                    facebookRequestAccessTokenUrl = facebookRequestAccessTokenUrlSettings.ToString();
                if (facebookRequestProfileUrlSettings != null)
                    facebookRequestProfileUrl = facebookRequestProfileUrlSettings.ToString();
                if (facebookScopeSettings != null)
                    facebookScope = facebookScopeSettings.ToString();

                //Create Credential object with consumer specific credentials
                Credentials credential = new Credentials();
                credential.ConsumerKey = facebookConsumerKey;
                credential.ConsumerSecret = facebookConsumerSecret;
                credential.VerifierUrl = facebookVerifierUrl;
                credential.RequestAccessTokenUrl = facebookRequestAccessTokenUrl;
                credential.RequestProfileUrl = facebookRequestProfileUrl;
                credential.Scope = facebookScope;

                var tClient = new OAuthFacebookClient();
                tClient.BeginAuthentication(credential);
            }
            catch (Exception ex)
            {
                txtFBResponse.Text = "Error occurred while accessing facebook accesstoken! " + ex.Message;
            }
        }
 protected void fb_OnClick(object sender, EventArgs e)
 {
     var tClient = new OAuthFacebookClient();
     tClient.BeginAuthentication();
 }