Bacancy Bacancy
  • Our Engagement Models

    We offer flexible engagement models tailored to your project scope and timeline.

    Software Development Outsourcing
    Staff Augmentation
    Dedicated Teams
    Engagement Models

    High-Quality, Affordable IT Outsourcing

    Explore All Services

    AI & ML

    • AI Strategy & Roadmap
    • AI Development
    • Generative AI
    • AI Agent Development
    • Machine Learning
    • Computer Vision
    • LLM Development
    • RAG Development

    Data

    • Data Engineering
    • Data Analytics & BI
    • Data Science
    • Data Warehouse
    • Data Governance

    Cloud

    • Cloud Consulting
    • Cloud Migration
    • AWS Services
    • Azure Services
    • GCP Services
    • Kubernetes
    • DevOps

    Product Engineering

    • Full Stack Development
    • Custom Software Development
    • SaaS Development
    • App Modernization
    • Mobile App Development
    • Web Development
    • UI/UX Design

    Platforms

    • Salesforce
    • SAP
    • ServiceNow
    • Microsoft Dynamics
    • Snowflake
    • Databricks
  • Why Bacancy

    14+ years building domain-specific products for regulated and high-growth industries worldwide.

    Global delivery, every time zone

    Global delivery, every time zone

    1050+ vetted engineers

    1050+ vetted engineers

    Onboard in 48 hours

    Onboard in 48 hours

    Explore Our Case Studies

    Industries

    • Healthcare
    • Fintech
    • Real Estate
    • Logistics
    • Education
    • eCommerce
    How Bacancy Built a Custom Epic EHR Solution to Automate Clinical Workflows

    How Bacancy Built a Custom Epic EHR Solution to Automate Clinical Workflows

    Read case study
  • About.

    1050+ world-class tech experts. One standard: customer satisfaction.

    About Company

    About Company

    • About Us
    • Leadership Team
    • Customer Reviews
    • Infrastructure
    • Our Locations
    • Partnership

    Resources

    • Press Room
    • Blog
    • Insights
    ISO/IEC 27001:2022 Certified

    ISO/IEC 27001:2022 Certified

    Built for enterprise security and compliance.

    Get Quote
  • Technologies
  • Customer Stories
  • Contact Us
Find a Developer
book a 30 min call
  • AI Strategy & Roadmap
  • AI Development
  • Generative AI
  • AI Agent Development
  • Machine Learning
  • Computer Vision
  • LLM Development
  • RAG Development
  • Data Engineering
  • Data Analytics & BI
  • Data Science
  • Data Warehouse
  • Data Governance
  • Cloud Consulting
  • Cloud Migration
  • AWS Services
  • Azure Services
  • GCP Services
  • Kubernetes
  • DevOps
  • Full Stack Development
  • Custom Software Development
  • SaaS Development
  • App Modernization
  • Mobile App Development
  • Web Development
  • UI/UX Design
  • Salesforce
  • SAP
  • ServiceNow
  • Microsoft Dynamics
  • Snowflake
  • Databricks
  • Healthcare
  • Fintech
  • Real Estate
  • Logistics
  • Education
  • eCommerce
  • About Us
  • Leadership Team
  • Customer Reviews
  • Infrastructure
  • Our Locations
  • Partnership
  • Press Room
  • Blog
  • Insights

Technologies

Customer Stories

Contact Us

Find a Developer
book a 30 min call
FB Authenticate Using Angular 8

How to Integrate Google and Facebook Authenticate Using Angular 8

Aishwary Rawat
Aishwary Rawat Director of Engineering
Last Updated on March 10, 2025 | Written By: Aishwary Rawat

Many of you might have used Sign-In with Google or Facebook in several websites to escape prolonged Sign Up procedure. Right?

Yes, I have too logged in this way. As I dive into a developer career, I was always fascinated to know how social logins actually work on any website. So, after exploring, I am here to share my knowledge.

So, in this article, we will gradually learn how any user can register into our application using Google or Facebook Sign-In in Angular.

Note:- I am not going to use any NPM package for this.

Let’s get started!

GMAIL

To integrate Gmail Sign in, we need to have an OAuth Client ID from the developer’s console. So, first of all, let’s create it.

Step (1) Go to Google developer console. And login with your developer’s credentials.

Step (2) Click on select a project.

Gmail

Step (3) A modal popup will be open. Click on NEW PROJECT. If you already have a project, you can go directly to Step5.

NEW PROJECT.

Step (4) Write your Google project name and click on the CREATE
button.

Create

Step (5) Go to the OAuth consent screen from the left sidebar and then select External. So your OAuth consent screen will be available to all users who are holding google accounts. Click on CREATE.

OAuth consent screen

Step (6) Write the name of your application. This name will be shown on your OAuth consent screen. There are also other optional fields like Authorised domain link, Application Homepage link, Privacy policy link, and Terms of Service link. And these must be hosted on an Authorised domain.

If provided, these links will be shown on your OAuth consent screen.

After providing these details, click on the Save button below.

 OAuth consent screen2

Step (7) Now go to Credentials from the left sidebar and click on + CREATE CREDENTIALS.

CREATE CREDENTIALS

Now click on OAuth Client ID

OAuth Client ID

Then select a Web application and fill the below details.

This name will be the name of your credentials. Also, you must enter the Authorised javascript origins. I am running my application on localhost:4200.

 Authorised javascript origins

Authorized redirect URIs are optional.

After filling all the details, click on CREATE.

A modal popup will get open; there you will get your Client ID and Client Secret.

Now you have successfully created your OAuth Client ID.

NOTE: If I change my authorized javascript origin to localhost:4100,

As this origin is not listed in Authorised Javascript Origins, an error will be thrown in an application at runtime.

Authorised Javascript Origins

Now let’s add code in our Angular 8 application.

Open your index.html file and add below lines in < head > tag.

< meta name="google-signin-client_id" content="your-client-id" >
< script src="https://apis.google.com/js/platform.js" >< /script >

Now, add the below code in your component.

component.html:

< div id="googleBtn" >< /div > < br / >

component.ts:

Firstly, Declare a global variable after all the import statements.

declare var gapi: any;

Now declare and define the below function

public btnRender(): void {
   const options = {
     scope: 'profile email', 
     width: 250,
     height: 50,
     longtitle: true,
     theme: 'dark',
     onsuccess: (googleUser => {
       let profile = googleUser.getBasicProfile();
       console.log('Token || ' + googleUser.getAuthResponse().id_token);
       console.log('ID: ' + profile.getId());
       console.log('Name: ' + profile.getName());
       console.log('Image URL: ' + profile.getImageUrl());
       console.log('Email: ' + profile.getEmail());
	
	// your-code-goes-here
      
     }),
     onfailure: ((error) => {
       console.log('failure', error);
     })
   };
   gapi.signin2.render('googleBtn', options);
 }

Now, Call the above function in ngOninit() lifecycle,

 ngOnInit() {
   this.btnRender();
 }

Now run the application…
You should see a Gmail Login button.

After successful login, you will get user id token. This id token should be sent to your server with an HTTPS request. There you must verify this token.

All information is given in this here.

That’s it! This is all you need to do.

NOTE: I have described only one of the methods to integrate Gmail sign-in button. But there are many other different ways to do it. You can check it in the official documentation.

FACEBOOK

For integrating Facebook login button in any application, we must have an APP ID, for that we need to create an application in Facebook developer’s console.

So, to set up your Facebook application, follow these steps.

Step (1) Go to Facebook developor’s console. And login with your developer’s credentials.

Step (2) After successful login, go to My Apps and click on Create App.

Facebook developor’s console

Step (3) A modal popup of Create a New App ID will be shown. Write the name of your application and then click on Create App ID.

Create a New App ID

You will see ReCaptcha dialog, check on it, and then click on submit.

Step (4) You can see your APP ID below the navigation bar. But it is a must to whitelist your site URL. So Set Up the Facebook Login option.

Facebook Login

Step (5) Select the Web option.

Facebook Login web

Step (6) Write your application running URL and save it. I am running my application on http:\\localhost:4200.

Angular 8

Save it.

That’s it. Your Facebook application is set up.

On clicking continue, you can see the steps to integrate Facebook login in your application. You can go through it. But don’t worry. I am not going to show you in just a moment.

Now let’s add code in our Angular 8 application.

Open index.html

< script async defer crossorigin="anonymous"
src="https://connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v5.0&appId=your-app-id&autoLogAppEvents=1" >< /script >

Now open your component,

component.html

< div class="fb-login-button" data-width="250px" data-size="medium" data-button-type="login_with" data-use-continue-as="true" data-auto-logout-link="false" >< /div >

component.ts

Declare a global variable after all import statements,

declare var FB: any;

In your class constructor,

FB.fbAsyncInit = () => {
     FB.init({
       appId: ‘your-app-id’,
       cookie: true,
       xfbml: true,
       version: 'v5.0'
     });
     FB.AppEvents.logPageView();
   };

In ngOninit lifecycle,

  ngOnInit() {
   ((d, s, id) => {
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) { return; }
     js = d.createElement(s); js.id = id;
     js.src = "https://connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   })(document, 'script', 'facebook-jssdk');

   this.statusChange();
 }

Add the below function,

 private statusChange(): void {
   FB.Event.subscribe('auth.statusChange', (response) => {
     console.log("submit login to facebook", response);
     if (response.status === 'connected') {
       if (response.authResponse) {
         FB.api('/me', {
           fields: 'last_name, first_name, email , picture , middle_name, name, name_format, short_name',
         }, (userInfo) => {
           console.log('userInfo', userInfo);
  		// your-code-goes-here
         });
       }
     }
     else {
       console.log('User login failed');
     }
   });
 }

Make sure that the application id you have mentioned in index.html and in the component should be the same.

That’s it. Now run the application.

You should see the Facebook login button.

This is the official documentation for Facebook login.

Few Points :

i) For getting more information about users aside from the above scopes, you need to grant your application. You can check this here.

ii) Facebook fetches only test user and developer account’s data in test mode. To fetch each user’s data, you need to make your application live. You can find test users in Roles Tab.

For more, please check out my GITHUB repository.

This is it. I hope you have enjoyed reading this blog post, and soon. In case if you are looking for Angular minds, to make user authentication even more secure, then hire angular developer from us to leverage our top-of-the-line expertise. For any suggestions and queries, feel free to comment to below

Happy Coding


Expand Your Digital Horizons With Us.

Start a new project or take an existing one to the next level. Get in touch to start small, scale-up, and go Agile.


Or
E-mail us : [email protected]

Your Success Is Guaranteed !

Related Articles

Darshan Joshi

June 23, 2025

Web Development

13 Top Web Development Challenges and How To Solve Them

By : Darshan Joshi

Web development can be considered an exciting, but intense ride of a rollercoaster – fast-paced and full of challenges. It...

Read More
Dipal Bhavsar

May 29, 2025

AngularJS

Angular 20: Your Guide to the Latest Features and Improvements

By : Dipal Bhavsar

Angular 20 just launched, and it’s packed with exciting updates that make your app development faster, easier, and more modern....

Read More
Darshan Joshi

April 21, 2025

Web Development

Top Web Portal Examples To Inspire Your Next Project

By : Darshan Joshi

This blog post covers everything a business or enterprise owner needs to know in terms of web portals. From the...

Read More

Offices and Development Centers

Bacancy Ahmedabad Ahmedabad

15-16, Times Corporate Park, Thaltej, Ahmedabad, 380059

Bacancy Gandhinagar Gandhinagar

422-A, 4th Floor, Pragya Tower Road 11, Block 15, Zone 1, SEZ-PA Gandhinagar, 382355

Bacancy Hyderabad Hyderabad

Awfis, Level 1, N Heights, Plot No 38, Phase 2, Hitech City Hyderabad, 500081

Bacancy Mumbai Mumbai

18th Floor, Cyberone, opp. CIDCO Exhibition Centre, Sector 30, Vashi, Navi Mumbai, 400703

Bacancy Pune Pune

2nd FloorMarisoft-1, Marigold IT Park, Pune - 411014

Bacancy Bengaluru Bengaluru

Raheja Towers, 26/27, Mahatma Gandhi Rd, East Wing, Craig Park Layout, Ashok Nagar, Bengaluru, 560001

Global Presence

Bacancy New Jersey New Jersey

33 South Wood Ave, Suite 600, Iselin NJ 08830

Bacancy California California

535 Mission St 14th floor, San Francisco, CA 94105

Bacancy Massachusetts Massachusetts

501 Boylston St, Boston, MA 02116

Bacancy Florida Florida

4995 NW, 72nd Avenue, Suite 307, Miami, FL, 33166

Bacancy London London

90 York Wy, London N1 9AG, United Kingdom

Bacancy Ontario Ontario

71 Dawes Road, Brampton, On L6X 5N9, Toronto

Bacancy Australia Australia

351A Hampstead Rd, Northfield SA 5085

Bacancy UAE UAE

One Central 8th and 9th Floor - Trade Centre - Trade Centre 2 - Dubai - United Arab Emirates

Bacancy Sweden Sweden

Junkergatan 4, 126 53 Hagersten

Get in Touch

Great Place to Work

Get in Touch

cal-icon

Looking for expert advice?

Schedule a Expert Call

gmail-icon

Email Us

[email protected]


  • Brochure
  • Quality Assurance
  • Resources
  • Tutorials
  • Customer Reviews
  • Privacy Policy
  • FAQs
  • Press Room
  • Contact Us
  • Sitemap
  • Employee

bacancy google review 4.6
bacancy google review
bacancy clutch review 4.8
bacancy clutch review
bacancy glassdoor review 4.5
bacancy glassdoor review
bacancy goodfirms review 4.8
bacancy goodfirms review
iso
  • Bacancy Behance
  • Bacancy Pinterest

Copyright © 2026 BACANCY SERVICES PRIVATE LIMITED All rights reserved.