Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to use google oauth for angular 11?


Asked by Brantley Martinez on Dec 04, 2021 OAuth 2.0 Series



You may use any provider like Google, Twitter, Facebook, VK, or even the custom one to signin into angular; when the user clicks on the login auth button, the user information is collected from the social login platform.
And,
Install the dependencies: We are using an OAUTH 2.0 client for Angular 4.3+, i.e. angular-oauth2-oidc. So, the first step is to install this in your project: Configure it with your app: In your app.module.ts, import OAuthModule: and initialize the module Now, in your app.component.ts, initialize the OAuthService with the config for google oauth 2.0
In addition, To begin, head over to https://console.developers.google.com/ and create a new project. Enable the OAuth client for this project. Next, copy the Client ID as you’re going to need it later. Although something like Passport can be used for OAuth2, in a regular NodeJS app, using it in Angular is made easier due to the angularx-social-login library
Next,
For Google login integration in angular 11/12, first you need to go to Google Developer Console and create Google App. After creating this Google app, it will give you client id and secret. Which you have to configure in this app.
Thereof,
The Google OAuth 2.0 endpoint supports JavaScript applications that run in a browser. The authorization sequence begins when your application redirects a browser to a Google URL; the URL includes query parameters that indicate the type of access being requested. Google handles the user authentication, session selection, and user consent.