{"id":12024,"date":"2020-03-09T11:50:07","date_gmt":"2020-03-09T11:50:07","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/blog\/?p=12024"},"modified":"2025-03-10T11:09:16","modified_gmt":"2025-03-10T11:09:16","slug":"integrate-google-and-facebook-authenticate-using-angular-8","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/blog\/integrate-google-and-facebook-authenticate-using-angular-8","title":{"rendered":"How to Integrate Google and Facebook Authenticate Using Angular 8"},"content":{"rendered":"<p>Many of you might have used Sign-In with Google or Facebook in several websites to escape prolonged Sign Up procedure. Right?<\/p>\n<p>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. <\/p>\n<p>So, in this article, we will gradually learn how any user can register into our application using Google or Facebook Sign-In in Angular.<\/p>\n<p><strong>Note:- I am not going to use any NPM package for this.<\/strong><\/p>\n<p>Let\u2019s get started! <\/p>\n<h2>GMAIL<\/h2>\n<p>To integrate Gmail Sign in, we need to have an <strong>OAuth Client ID<\/strong> from the developer&#8217;s console. So, first of all, let\u2019s create it. <\/p>\n<p><strong>Step (1)<\/strong> Go to <a href=\"https:\/\/console.developers.google.com\/\" rel=\"nofollow noopener\" target=\"_blank\">Google developer console<\/a>. And login with your developer&#8217;s credentials.<\/p>\n<p><strong>Step (2)<\/strong> Click on select a project. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Gmail.png\" alt=\"Gmail\" width=\"1366\" height=\"572\" class=\"aligncenter size-full wp-image-12025\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Gmail.png 1366w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Gmail-300x126.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Gmail-1024x429.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Gmail-768x322.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Gmail-20x8.png 20w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p><strong>Step (3)<\/strong> A modal popup will be open. Click on <strong>NEW PROJECT<\/strong>. If you already have a project, you can go directly to <strong>Step5<\/strong>.  <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/NEW-PROJECT..png\" alt=\"NEW PROJECT.\" width=\"1365\" height=\"571\" class=\"aligncenter size-full wp-image-12026\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/NEW-PROJECT..png 1365w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/NEW-PROJECT.-300x125.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/NEW-PROJECT.-1024x428.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/NEW-PROJECT.-768x321.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/NEW-PROJECT.-20x8.png 20w\" sizes=\"auto, (max-width: 1365px) 100vw, 1365px\" \/><\/p>\n<p><strong>Step (4)<\/strong> Write your Google project name and click on the <strong>CREATE<\/strong><br \/>\nbutton.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/CREATE.png\" alt=\"Create\" width=\"596\" height=\"245\" class=\"aligncenter size-full wp-image-12027\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/CREATE.png 596w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/CREATE-300x123.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/CREATE-20x8.png 20w\" sizes=\"auto, (max-width: 596px) 100vw, 596px\" \/><\/p>\n<p><strong>Step (5)<\/strong> Go to the <strong>OAuth consent screen<\/strong> from the left sidebar and then select <strong>External<\/strong>. So your OAuth consent screen will be available to all users who are holding google accounts. Click on <strong>CREATE<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-consent-screen.png\" alt=\"OAuth consent screen\" width=\"1366\" height=\"572\" class=\"aligncenter size-full wp-image-12028\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-consent-screen.png 1366w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-consent-screen-300x126.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-consent-screen-1024x429.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-consent-screen-768x322.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-consent-screen-20x8.png 20w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p><strong>Step (6)<\/strong> Write the name of your application. This name will be shown on your <strong>OAuth consent screen<\/strong>. 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 <strong>hosted on an Authorised domain<\/strong>.<\/p>\n<p>If provided, these links will be shown on your  <strong>OAuth consent screen<\/strong>.<\/p>\n<p>After providing these details, click on the <strong>Save<\/strong> button below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-consent-screen2.png\" alt=\" OAuth consent screen2\" width=\"1366\" height=\"571\" class=\"aligncenter size-full wp-image-12029\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-consent-screen2.png 1366w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-consent-screen2-300x125.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-consent-screen2-1024x428.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-consent-screen2-768x321.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-consent-screen2-20x8.png 20w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p><strong>Step (7)<\/strong>  Now go to Credentials from the left sidebar and click on <strong>+ CREATE CREDENTIALS.<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/CREATE-CREDENTIALS.png\" alt=\"CREATE CREDENTIALS\" width=\"1366\" height=\"571\" class=\"aligncenter size-full wp-image-12030\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/CREATE-CREDENTIALS.png 1366w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/CREATE-CREDENTIALS-300x125.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/CREATE-CREDENTIALS-1024x428.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/CREATE-CREDENTIALS-768x321.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/CREATE-CREDENTIALS-20x8.png 20w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p>Now click on <strong>OAuth Client ID<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-Client-ID.png\" alt=\"OAuth Client ID\" width=\"1366\" height=\"568\" class=\"aligncenter size-full wp-image-12031\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-Client-ID.png 1366w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-Client-ID-300x125.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-Client-ID-1024x426.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-Client-ID-768x319.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/OAuth-Client-ID-20x8.png 20w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p>Then select a <strong>Web application<\/strong> and fill the below details.<\/p>\n<p>This name will be the name of your credentials. Also, you must enter the <strong>Authorised javascript origins<\/strong>. I am running my application on localhost:4200.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Authorised-javascript-origins.png\" alt=\" Authorised javascript origins\" width=\"1365\" height=\"569\" class=\"aligncenter size-full wp-image-12033\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Authorised-javascript-origins.png 1365w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Authorised-javascript-origins-300x125.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Authorised-javascript-origins-1024x427.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Authorised-javascript-origins-768x320.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Authorised-javascript-origins-20x8.png 20w\" sizes=\"auto, (max-width: 1365px) 100vw, 1365px\" \/><\/p>\n<p><strong>Authorized redirect URIs<\/strong> are optional. <\/p>\n<p>After filling all the details, click on <strong>CREATE<\/strong>. <\/p>\n<p>A modal popup will get open; there you will get your <strong>Client ID<\/strong> and <strong>Client Secret<\/strong>.<\/p>\n<p>Now you have successfully created your <strong>OAuth Client ID.<\/strong> <\/p>\n<p><strong>NOTE:<\/strong> If I change my authorized javascript origin to localhost:4100,<\/p>\n<p>As this origin is not listed in <strong>Authorised Javascript Origins<\/strong>, an error will be thrown in an application at runtime.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Authorised-Javascript-Origins-1.png\" alt=\"Authorised Javascript Origins\" width=\"1361\" height=\"511\" class=\"aligncenter size-full wp-image-12034\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Authorised-Javascript-Origins-1.png 1361w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Authorised-Javascript-Origins-1-300x113.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Authorised-Javascript-Origins-1-1024x384.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Authorised-Javascript-Origins-1-768x288.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Authorised-Javascript-Origins-1-20x8.png 20w\" sizes=\"auto, (max-width: 1361px) 100vw, 1361px\" \/><\/p>\n<p>Now let\u2019s add code in our Angular 8 application. <\/p>\n<p>Open your <strong>index.html<\/strong> file and add below lines in < head > tag. <\/p>\n<pre>\r\n< meta name=\"google-signin-client_id\" content=\"<strong>your-client-id<\/strong>\" >\r\n< script src=\"https:\/\/apis.google.com\/js\/platform.js\" >< \/script >\r\n<\/pre>\n<p>Now, add the below code in your component. <\/p>\n<p><em>component.html:<\/em> <\/p>\n<pre>\r\n< div id=\"googleBtn\" >< \/div > < br \/ >\r\n<\/pre>\n<p><em>component.ts:<\/em><\/p>\n<p>Firstly, Declare a global variable after all the import statements.  <\/p>\n<pre>\r\ndeclare var gapi: any;\r\n<\/pre>\n<p>Now declare and define the below function<\/p>\n<pre>\r\npublic btnRender(): void {\r\n   const options = {\r\n     scope: 'profile email', \r\n     width: 250,\r\n     height: 50,\r\n     longtitle: true,\r\n     theme: 'dark',\r\n     onsuccess: (googleUser => {\r\n       let profile = googleUser.getBasicProfile();\r\n       console.log('Token || ' + googleUser.getAuthResponse().id_token);\r\n       console.log('ID: ' + profile.getId());\r\n       console.log('Name: ' + profile.getName());\r\n       console.log('Image URL: ' + profile.getImageUrl());\r\n       console.log('Email: ' + profile.getEmail());\r\n\t\r\n\t\/\/ your-code-goes-here\r\n      \r\n     }),\r\n     onfailure: ((error) => {\r\n       console.log('failure', error);\r\n     })\r\n   };\r\n   gapi.signin2.render('googleBtn', options);\r\n }\r\n<\/pre>\n<p>Now, Call the above function in ngOninit() lifecycle,<\/p>\n<pre>\r\n ngOnInit() {\r\n   this.btnRender();\r\n }\r\n<\/pre>\n<p>Now run the application\u2026<br \/>\nYou should see a Gmail Login button.<\/p>\n<p>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. <\/p>\n<p>All information is given in this <a href=\"https:\/\/developers.google.com\/identity\/sign-in\/web\/backend-auth\" rel=\"nofollow noopener\" target=\"_blank\">here<\/a>.<\/p>\n<p>That\u2019s it! This is all you need to do. <\/p>\n<p><strong>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 <a href=\"https:\/\/developers.google.com\/identity\/sign-in\/web\/sign-in\" rel=\"nofollow noopener\" target=\"_blank\">official documentation<\/a>.<\/strong><\/p>\n<h2>FACEBOOK<\/h2>\n<p>For integrating Facebook login button in any application, we must have an <strong>APP ID<\/strong>, for that we need to create an application in Facebook developer\u2019s console. <\/p>\n<p>So, to set up your Facebook application, follow these steps.<\/p>\n<p><strong>Step (1)<\/strong> Go to <a href=\"https:\/\/developers.facebook.com\/\" rel=\"nofollow noopener\" target=\"_blank\">Facebook developor\u2019s console<\/a>. And login with your developer&#8217;s credentials.<\/p>\n<p><strong>Step (2)<\/strong> After successful login, go to <strong>My Apps<\/strong> and click on <strong>Create App<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-developor\u2019s-console.png\" alt=\"Facebook developor\u2019s console\" width=\"1366\" height=\"569\" class=\"aligncenter size-full wp-image-12035\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-developor\u2019s-console.png 1366w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-developor\u2019s-console-300x125.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-developor\u2019s-console-1024x427.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-developor\u2019s-console-768x320.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-developor\u2019s-console-20x8.png 20w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p><strong>Step (3)<\/strong> A modal popup of <strong>Create a New App ID<\/strong> will be shown. Write the name of your application and then click on <strong>Create App ID<\/strong>. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Create-a-New-App-ID.png\" alt=\"Create a New App ID\" width=\"1366\" height=\"566\" class=\"aligncenter size-full wp-image-12036\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Create-a-New-App-ID.png 1366w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Create-a-New-App-ID-300x124.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Create-a-New-App-ID-1024x424.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Create-a-New-App-ID-768x318.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Create-a-New-App-ID-20x8.png 20w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p>You will see ReCaptcha dialog, check on it, and then click on submit.<\/p>\n<p><strong>Step (4)<\/strong> You can see your <strong>APP ID<\/strong> below the navigation bar. But it is a must to whitelist your site URL. So <strong>Set Up<\/strong> the <strong>Facebook Login<\/strong> option. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-Login.png\" alt=\"Facebook Login\" width=\"1366\" height=\"563\" class=\"aligncenter size-full wp-image-12037\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-Login.png 1366w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-Login-300x124.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-Login-1024x422.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-Login-768x317.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-Login-20x8.png 20w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p><strong>Step (5)<\/strong> Select the <strong>Web<\/strong> option.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-Login-web.png\" alt=\"Facebook Login web\" width=\"1366\" height=\"561\" class=\"aligncenter size-full wp-image-12038\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-Login-web.png 1366w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-Login-web-300x123.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-Login-web-1024x421.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-Login-web-768x315.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/Facebook-Login-web-20x8.png 20w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p><strong>Step (6)<\/strong> Write your application running URL and <strong>save<\/strong> it. I am running my application on http:\\\\localhost:4200.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/localhost-4200.png\" alt=\"Angular 8\" width=\"1366\" height=\"558\" class=\"aligncenter size-full wp-image-12039\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/localhost-4200.png 1366w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/localhost-4200-300x123.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/localhost-4200-1024x418.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/localhost-4200-768x314.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/03\/localhost-4200-20x8.png 20w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p>Save it. <\/p>\n<p>That\u2019s it. Your Facebook application is set up.<\/p>\n<p>On clicking continue, you can see the steps to integrate Facebook login in your application. You can go through it. But don\u2019t worry. I am not going to show you in just a moment.<\/p>\n<p>Now let\u2019s add code in our Angular 8 application. <\/p>\n<p>Open index.html <\/p>\n<pre>\r\n< script async defer crossorigin=\"anonymous\"\r\nsrc=\"https:\/\/connect.facebook.net\/en_GB\/sdk.js#xfbml=1&#038;version=v5.0&#038;appId=<strong>your-app-id<\/strong>&autoLogAppEvents=1\" >< \/script >\r\n<\/pre>\n<p>Now open your component,<\/p>\n<p><em>component.html<\/em><\/p>\n<pre>\r\n< 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 >\r\n<\/pre>\n<p><em>component.ts<\/em><\/p>\n<p>Declare a global variable after all import statements,<\/p>\n<pre>declare var FB: any;<\/pre>\n<p>In your class constructor, <\/p>\n<pre>\r\nFB.fbAsyncInit = () => {\r\n     FB.init({\r\n       appId: \u2018your-app-id\u2019,\r\n       cookie: true,\r\n       xfbml: true,\r\n       version: 'v5.0'\r\n     });\r\n     FB.AppEvents.logPageView();\r\n   };\r\n<\/pre>\n<p>In ngOninit lifecycle,<\/p>\n<pre>\r\n  ngOnInit() {\r\n   ((d, s, id) => {\r\n     var js, fjs = d.getElementsByTagName(s)[0];\r\n     if (d.getElementById(id)) { return; }\r\n     js = d.createElement(s); js.id = id;\r\n     js.src = \"https:\/\/connect.facebook.net\/en_US\/sdk.js\";\r\n     fjs.parentNode.insertBefore(js, fjs);\r\n   })(document, 'script', 'facebook-jssdk');\r\n\r\n   this.statusChange();\r\n }\r\n<\/pre>\n<p>Add the below function,<\/p>\n<pre>\r\n private statusChange(): void {\r\n   FB.Event.subscribe('auth.statusChange', (response) => {\r\n     console.log(\"submit login to facebook\", response);\r\n     if (response.status === 'connected') {\r\n       if (response.authResponse) {\r\n         FB.api('\/me', {\r\n           fields: 'last_name, first_name, email , picture , middle_name, name, name_format, short_name',\r\n         }, (userInfo) => {\r\n           console.log('userInfo', userInfo);\r\n  \t\t\/\/ your-code-goes-here\r\n         });\r\n       }\r\n     }\r\n     else {\r\n       console.log('User login failed');\r\n     }\r\n   });\r\n }\r\n<\/pre>\n<p>Make sure that the application id you have mentioned in index.html and in the component should be the same.<\/p>\n<p>That\u2019s it. Now run the application.<\/p>\n<p>You should see the Facebook login button. <\/p>\n<p>This is the <a href=\"https:\/\/developers.facebook.com\/docs\/facebook-login\/web\" rel=\"nofollow noopener\" target=\"_blank\">official documentation<\/a> for Facebook login.<\/p>\n<h2>Few Points : <\/h2>\n<p>i) For getting more information about users aside from the above scopes, you need to grant your application. You can check this <a href=\"https:\/\/developers.facebook.com\/docs\/facebook-login\/web\/permissions\" rel=\"nofollow noopener\" target=\"_blank\">here<\/a>.<\/p>\n<p>ii) Facebook fetches only test user and developer account\u2019s data in test mode. To fetch each user&#8217;s data, you need to make your application live. You can find test users in Roles Tab.<\/p>\n<p>For more, please check out my  <a href=\"https:\/\/github.com\/dollyshah96\/SocialLoginApp\" rel=\"nofollow noopener\" target=\"_blank\">GITHUB<\/a> repository. <\/p>\n<p>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 <a href=\"https:\/\/www.bacancytechnology.com\/angular-js-development\" rel=\"noopener\" target=\"_blank\">hire angular developer<\/a> from us to leverage our top-of-the-line expertise. For any suggestions and queries, feel free to comment to below <\/p>\n<p>Happy Coding<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":146,"featured_media":12045,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"_lmt_disableupdate":"no","_lmt_disable":"","footnotes":""},"categories":[989,1265],"tags":[],"coauthors":[2427],"class_list":["post-12024","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angularjs","category-web-development"],"acf":[],"modified_by":"Binal Prajapati","_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts\/12024","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/users\/146"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=12024"}],"version-history":[{"count":0,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts\/12024\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/media\/12045"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=12024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=12024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=12024"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/coauthors?post=12024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}