• Home
  • About Us
    • Our Mission & Values
    • B Corp
    • Awards & Recognitions
    • TCG Partners
  • Solutions and Services
    • TCG’s Glass Box AI
    • Artificial Intelligence
    • Digital Transformation
    • Application and Web Development
    • Cloud Services
  • Contracts
    • GSA Multiple Award Schedule
    • NASA SEWP VI
    • OASIS+ Unrestricted
    • MDA Shield IDIQ
    • FCC ITC ADSS
  • Careers
    • Open Positions
    • Benefits & Perqs
    • TCG Employee Happiness
    • The TCG Experience
  • Our Work
  • Insights
  • Home
  • About Us
    • Our Mission & Values
    • B Corp
    • Awards & Recognitions
    • TCG Partners
  • Solutions and Services
    • TCG’s Glass Box AI
    • Artificial Intelligence
    • Digital Transformation
    • Application and Web Development
    • Cloud Services
  • Contracts
    • GSA Multiple Award Schedule
    • NASA SEWP VI
    • OASIS+ Unrestricted
    • MDA Shield IDIQ
    • FCC ITC ADSS
  • Careers
    • Open Positions
    • Benefits & Perqs
    • TCG Employee Happiness
    • The TCG Experience
  • Our Work
  • Insights
202–986-5533
Contact us
  • Home
  • About Us
    • Our Mission & Values
    • B Corp
    • Awards & Recognitions
    • TCG Partners
  • Solutions and Services
    • TCG’s Glass Box AI
    • Artificial Intelligence
    • Digital Transformation
    • Application and Web Development
    • Cloud Services
  • Contracts
    • GSA Multiple Award Schedule
    • NASA SEWP VI
    • OASIS+ Unrestricted
    • MDA Shield IDIQ
    • FCC ITC ADSS
  • Careers
    • Open Positions
    • Benefits & Perqs
    • TCG Employee Happiness
    • The TCG Experience
  • Our Work
  • Insights
  • Home
  • About Us
    • Our Mission & Values
    • B Corp
    • Awards & Recognitions
    • TCG Partners
  • Solutions and Services
    • TCG’s Glass Box AI
    • Artificial Intelligence
    • Digital Transformation
    • Application and Web Development
    • Cloud Services
  • Contracts
    • GSA Multiple Award Schedule
    • NASA SEWP VI
    • OASIS+ Unrestricted
    • MDA Shield IDIQ
    • FCC ITC ADSS
  • Careers
    • Open Positions
    • Benefits & Perqs
    • TCG Employee Happiness
    • The TCG Experience
  • Our Work
  • Insights
202–986-5533
Contact us
Contact us
  • Home
  • About Us
    • Our Mission & Values
    • B Corp
    • Awards & Recognitions
    • TCG Partners
  • Solutions & Services
    • Application and Web Development
    • Cloud Services
    • Artificial Intelligence
    • Digital Transformation
    • Glass Box AI
  • TCG Contracts
    • GSA IT Schedule 70
    • One Acquisition Solution for Integrated Services (OASIS+) Multi-Agency Contract (MAC) Unrestricted
    • CIO-SP3 Small Business
    • FCC ITC Application Development Support Services
  • TCG Careers
    • Open Positions
    • The TCG Experience
    • TCG Employee Happiness
    • Benefits & Perqs
  • Our Work
  • Insights
    • Insights
    • TCG News
  • Contact Us
  • Home
  • About Us
    • Our Mission & Values
    • B Corp
    • Awards & Recognitions
    • TCG Partners
  • Solutions & Services
    • Application and Web Development
    • Cloud Services
    • Artificial Intelligence
    • Digital Transformation
    • Glass Box AI
  • TCG Contracts
    • GSA IT Schedule 70
    • One Acquisition Solution for Integrated Services (OASIS+) Multi-Agency Contract (MAC) Unrestricted
    • CIO-SP3 Small Business
    • FCC ITC Application Development Support Services
  • TCG Careers
    • Open Positions
    • The TCG Experience
    • TCG Employee Happiness
    • Benefits & Perqs
  • Our Work
  • Insights
    • Insights
    • TCG News
  • Contact Us
  • March 30, 2012
  • Insights, Technology, We value our families

Project: Facebook Data Liberation – Part 3 – Authentication

Back in Part 1 I explained why I'm making this HTML5 application. The condensed version of what I'm making is a web/mobile app that can read a running/fitness Facebook group feed. In the Part 2 I explained how I was going to process the group feed once I got it.  In this part I will show you how to authenticate with Facebook and download the data into your web app.

There are a few ways to work with the Facebook API in a HTML5 application.  You can use their JavaScript SDK, you can do the integration on the server side, or you can make direct calls with your own JavaScript functions.  I'm going to use that last technique.

The basic process works like this:

  1. The user loads your web page
  2. JavaScript on the page checks for a Facebook authentication token.
  3. If the token isn't found, JavaScript will redirect your user to the Facebook login URL, (https://www.facebook.com/dialog/oauth) with certain GET parameters
  4. The user logs in  and Facebook redirects them back to your application with the authenticaion token included in the URL
  5. JavaScript in the application examines the URL and finds the auth token indicating a successful login

I mentioned in step 3 that there are parameters you pass into the Facebook auth system.  Here are the ones I use:

  • redirect_uri - this is the URL that Facebook will use to send the user back to your application
  • response_type - this can be set to a value of "token" or "code".  A value of code is used for server side authentication.  Since we are building a stand alone HTML5 app, we will use token.  When Facebook redirects the user back to your page, it will append a #access_token=XXXXXX to the URL so you can read the token from the location.
  • scope - This is how you request certain privileges for your token.  Since our app needs to see group information, we will request "user_groups".  If you need to get more privileges, use a comma separated list.  Facebook docs have the complet list of privileges you can request.

The documentation lists the other parameters you can use, but that's all we need for this application.

That's the outline, here is the code I am using:

var appID = 'YOUR-APP-ID';
if (window.location.hash.length == 0) {   
    var path = 'https://www.facebook.com/dialog/oauth?';   
    var queryParams = ['client_id=' + appID,     'redirect_uri=' + window.location,     'response_type=token', 'scope=user_groups'];
    var query = queryParams.join('&');
    var url = path + query;
    window.location = url;
} 

Using this code as-is will automatically send the user to the login page.  A good UI would have some kind of warning or login button to press before that.  Every app will want to do that differently, so pick the method that is right for you.

If you look at the code above, you see that an application ID is needed.  You can get this by registering your application on the Facebook developer app: http://developers.facebook.com/setup/

One important note, when you register you have to list the Website URL of your application.  When you try to use the Facebook API, your referring URL (or at least the domain) will be checked against the value you put in there.  If things don't match up, you will see the message "An error occurred.  Please try again later."  on the Facebook login screen.  Clearly not very helpful to a developer, but I guess it's better for your end users to see that than something like "The developer of the web app you are trusting with your personal Facebook data isn't smart enough to code it properly and here is what he/she did wrong: XYZ"

The name restriction makes local development a little trickier than most HTML5 applications.  This means you can either do your development on a public web server or setup and match a DNS entry for you local system with the URL you register with Facebook.  

This is a bit annoying for me as my local system is a Windows 7 box without a web server installed. I could do my coding on my Linux server I have on Amazon's EC2, but I really like Visual Studio as an editor.  My solution was to use Server2Go as my local web server and register my home router's public name as my website URL with Facebook.  When I'm ready to deploy my app to the world, I will update my URL with Facebook.

In the next part, I will talk about pulling the feed pragmatically and parsing the data.

    Tags:
    • authentication., Facebook API, javascript, login

    Related Insights

    • Insights
    Psychology Principles Behind Great UX
    • July 16, 2026

    By Dr. Robert Buccigrossi, TCG CIO I’m not a UX expert (we have real ones at TCG), but I watched a video breaking down some psychology principles that top designers use, and couldn’t stop thinking about how I am happily...

    • Insights
    AI Can Write More Code. People Still Make It Shippable.
    • June 28, 2026

    As reported widely, AI development tools are excelling at producing large volumes of code. But the data points to a practical limit: increases in code activity do not translate one-for-one into increases in shipped software. The chart below traces a...

    • Insights
    A New NIST ITL Project Can Help Build Trust in Federal AI
    • May 12, 2026

    By Dr. Robert Buccigrossi, TCG CTO There is a strong push by the administration for Federal agencies to adopt artificial intelligence. But how can we support this shift when AI systems are opaque and unreliable? One key is “Agentic AI”....

    Ready to Move Faster?

    Develop Secure Digital Solutions Around Your Agency’s Needs

    From AI-powered development to cloud modernization and mission-critical transformation, TCG helps federal agencies innovate faster while maintaining the highest standards of security, transparency, and trust.

    Schedule a Consultation
    Explore Glass Box AI
    202-986-5533
    Contact Us

    TCG delivers secure, human-managed AI and digital transformation solutions for federal agencies. 

    Company
    • Home
    • Our Work
    • Insights
    • About Us
    • Contact Us
    • Home
    • Our Work
    • Insights
    • About Us
    • Contact Us
    Solutions
    • TCG’s Glass Box AI
    • Cloud Services
    • Digital Transformation
    • TCG Contracts
    • TCG’s Glass Box AI
    • Cloud Services
    • Digital Transformation
    • TCG Contracts
    Resources
    • TCG Careers
    • Open Positions
    • The TCG Experience
    • TCG Employee Happiness
    • Benefits & Perqs
    • TCG Careers
    • Open Positions
    • The TCG Experience
    • TCG Employee Happiness
    • Benefits & Perqs
    Contact Us
    talktous@tcg.com
    202-986-5533
    Facebook Linkedin X-twitter
    Trusted by Government & Industry
    CMMI-Services-V2.0-CMMI-SVC 1
    CMMI-Development-V2.0-CMMI-DEV 1
    bcorp 1
    Remove background project - August 26, 2026 at 10.45.09
    Untitled - August 26, 2026 at 11.18.43
    Untitled - August 26, 2026 at 11.18.43-1
    © TCG, Inc. 2026
    All Rights Reserved. Human-Managed AI & Digital Solutions for Government.
    • Privacy Policy
    • Cookie Policy
    • Privacy Policy
    • Cookie Policy
    top

    Inactive

    WHAT WE'RE THINKING
    • Insights
    • TCG News
    • Client Success Stories
    LATEST INSIGHT

    Psychology Principles Behind Great UX

    LATEST NEWS

    TCG Awarded NASA SEWP VI GWAC

    Stay ahead in a rapidly changing world

    Our regular insights for strategic IT perspectives.

    • Follow Us on LinkedIn

    Inactive

    Solutions & Services
    Application & Web Development
    Secure, scalable solutions for modern government needs.
    Cloud Services
    Flexible cloud infrastructure built for compliance and performance.
    Artificial Intelligence
    Human-managed AI focused on trust and transparency.
    Digital Transformation
    Modernizing systems through agile digital innovation.
    Glass Box AI
    Transparent AI development with human oversight.
    Government Contracts
    GSA IT Schedule 70
    Streamlined procurement vehicle for trusted IT products and services.
    GSA OASIS+ Unrestricted
    Flexible contracting solution for complex professional service requirements.
    CIO-SP3 Small Business
    Government-wide IT solutions contract supporting federal technology initiatives.
    DOT SWES
    Engineering and technology support for transportation-focused initiatives.
    FCC ADSS
    Secure digital services for federal communications.
    Life at TCG
    Open Positions
    Explore career opportunities shaping the future of government technology.
    The TCG Experience
    A collaborative culture focused on innovation, growth, and impact.
    Employee Happiness
    Supporting employee well-being through flexibility, balance, and engagement.
    Testimonials
    Hear directly from team members about life and growth at TCG.
    Benefits & Perqs
    Comprehensive benefits designed to support both work and life.
    Explore
    Solutions, Contracts & Careers
    Discover TCG’s technology capabilities, federal contract vehicles, and career opportunities driving innovation across government services.

    Inactive

    Search