Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7678117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:34:17+00:00 2026-05-31T17:34:17+00:00

I am trying to add a simple log in with Facebook button to my

  • 0

I am trying to add a simple log in with Facebook button to my ASP.NET (C#) website. All I need is on the server side to retrieve the Facebook user’s email address once they have logged in.

I was trying to use this example but it seems that the cookie “fbs_appid” is no longer used and instead there is one called “fbsr_appid”.

How can I change the sample to use the different cookie? Alternately does anyone have a working example of retrieving the logged in Facebook user’s email address.

I know there is an SDK I can use but I want to keep things simple. The above example would be perfect if it worked.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:34:18+00:00Added an answer on May 31, 2026 at 5:34 pm

    I managed to get the information needed using the fbsr cookie. I created the following class which does all of the work to confirm the user logged in with Facebook and then retrieves the user’s details:

    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Configuration;
    using System.IO;
    using System.Net;
    using System.Security.Cryptography;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Web.Script.Serialization;
    
    namespace HarlequinShared
    {
    public class FacebookLogin
    {
        protected static string _appId = null;
        protected static string AppId
        {
            get
            {
                if (_appId == null)
                    _appId = ConfigurationManager.AppSettings["FacebookAppId"] ?? null;
                return _appId;
            }
        }
    
        protected static string _appSecret = null;
        protected static string AppSecret
        {
            get
            {
                if (_appSecret == null)
                    _appSecret = ConfigurationManager.AppSettings["FacebookAppSecret"] ?? null;
                return _appSecret;
            }
        }
    
        public static FacebookUser CheckLogin()
        {
            string fbsr = HttpContext.Current.Request.Cookies["fbsr_" + AppId].Value;
    
            int separator = fbsr.IndexOf(".");
            if (separator == -1)
            {
                return null;
            }
    
            string encodedSig = fbsr.Substring(0, separator);
            string payload = fbsr.Substring(separator + 1);
    
            string sig = Base64Decode(encodedSig);
    
            var serializer = new JavaScriptSerializer();
            Dictionary<string, string> data = serializer.Deserialize<Dictionary<string, string>>(Base64Decode(payload));
    
            if (data["algorithm"].ToUpper() != "HMAC-SHA256")
            {
                return null;
            }
    
            HMACSHA256 crypt = new HMACSHA256(Encoding.ASCII.GetBytes(AppSecret));
            crypt.ComputeHash(Encoding.UTF8.GetBytes(payload));
            string expectedSig = Encoding.UTF8.GetString(crypt.Hash);
    
            if (sig != expectedSig)
            {
                return null;
            }
    
            string accessTokenResponse = FileGetContents("https://graph.facebook.com/oauth/access_token?client_id=" + AppId + "&redirect_uri=&client_secret=" + AppSecret + "&code=" + data["code"]);
            NameValueCollection options = HttpUtility.ParseQueryString(accessTokenResponse);
    
            string userResponse = FileGetContents("https://graph.facebook.com/me?access_token=" + options["access_token"]);
    
            userResponse = Regex.Replace(userResponse, @"\\u([\dA-Fa-f]{4})", v => ((char)Convert.ToInt32(v.Groups[1].Value, 16)).ToString());
    
            FacebookUser user = new FacebookUser();
    
            Regex getValues = new Regex("(?<=\"email\":\")(.+?)(?=\")");
            Match infoMatch = getValues.Match(userResponse);
            user.Email = infoMatch.Value;
    
            getValues = new Regex("(?<=\"first_name\":\")(.+?)(?=\")");
            infoMatch = getValues.Match(userResponse);
            user.FirstName = infoMatch.Value;
    
            getValues = new Regex("(?<=\"last_name\":\")(.+?)(?=\")");
            infoMatch = getValues.Match(userResponse);
            user.LastName = infoMatch.Value;
    
            return user;
        }
    
        protected static string FileGetContents(string url)
        {
            string result;
            WebResponse response;
            WebRequest request = HttpWebRequest.Create(url);
            response = request.GetResponse();
            using (StreamReader sr = new StreamReader(response.GetResponseStream()))
            {
                result = sr.ReadToEnd();
                sr.Close();
            }
            return result;
        }
    
        protected static string Base64Decode(string input)
        {
            UTF8Encoding encoding = new UTF8Encoding();
            string encoded = input.Replace("=", string.Empty).Replace('-', '+').Replace('_', '/');
            var decoded = Convert.FromBase64String(encoded.PadRight(encoded.Length + (4 - encoded.Length % 4) % 4, '='));
            var result = encoding.GetString(decoded);
            return result;
        }
    
    }
    
    public class FacebookUser
    {
        public string UID { get; set; }
        public string Email { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
    }
    

    And then I can use this in my login page:

    FacebookUser user = FacebookLogin.CheckLogin();
    if (user != null)
    {
    Response.Write("&lt;p&gt;" + user.Email);
    Response.Write("&lt;p&gt;" + user.FirstName);
    Response.Write("&lt;p&gt;" + user.LastName);
    }
    

    This is further explained here.

    I believe that this method is secure and does the job as simply as possible. Please comment if there is any concerns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add simple login page to ASP.NET MVC app. I actually use
I'm trying to create a simple Add-On for SQL Server 2008; it is simply
I am trying to add a simple form to allow my users to edit
I'm trying to add some simple peer-to-peer connection functionality to an iOS library. Coding
I'm using Magento Community Edition ver. 1.6.2.0. I’m trying to add a Simple product
I'm trying to add a very simple action to the context menu of Eclipse:
I am trying to add a draggable object to to a simple html page.
I'm currently trying to implement a simple Add-In for InfoPath 2010 Filler/Editor mode, which
This may be a simple answer, but I'm trying to add a dom-created element
I'm trying to implement a simple method to read new lines from a log

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.