Google Sign-in with Angular Front End

Here is Google sign-in official website:

https://developers.google.com/identity/sign-in/web/sign-inarrow-up-right

However, I found Angular Social Login library will be easier to use:

https://www.npmjs.com/package/angularx-social-loginarrow-up-right

Implementation

Get credentials on Google developers console

  1. Go to this url https://console.developers.google.com/apis/credentialsarrow-up-right and login with your google account.

  2. Create a new project if you don't have one.

  3. You need to register OAuth consent form screen

    1. Under App information section, put your apps basic info.

    2. Under App domain section, put http://localhost:4200/arrow-up-right as your application home domain.

    3. Under Authorized domains, leave it as blank

    4. On Scopes tab, choose the information you request users to authorize for your app.

    5. On Test users tab, you can only test with test user for 100 times if you have sensitive scope loginsarrow-up-right, and put your testing google account here.

    6. On summary tab, you can review the information.

  4. Once you have the OAuth consent form, you can create Credentials now

    1. Select OAuth clientID

    2. Select Web application as Application type

    3. Under Authorized JavaScript origins, put http://localhost:4200/arrow-up-right

    4. Under Authorized redirect URIs, put http://localhost:4200/arrow-up-right

    5. Once completed, it will pop up Your Client ID and Your Client Secret which will be used in your angular app.

Angular Social Login library

It's simple to follow the steps on the official web site.

https://www.npmjs.com/package/angularx-social-loginarrow-up-right

Settings in app.module.ts file

  1. Add SocialLoginModule

  2. Add your app client ID in the providers

Add a login button at your html

At your type script file, call google api with angularx-social-login

Check your browser console to see if you get the response from Google.

Ref

https://codinglatte.com/posts/angular/sign-in-with-google-angular/arrow-up-right

https://levelup.gitconnected.com/sign-in-with-google-oauth-in-angular-8-e716ed7f3b2farrow-up-right

https://saikiran1298.medium.com/implementing-google-authentication-in-angular-and-node-js-application-31f49301673carrow-up-right

Client Id

https://stackoverflow.com/questions/53622075/what-prevents-another-app-from-stealing-my-google-oauth-client-idarrow-up-right

https://stackoverflow.com/questions/22266729/google-oauth-keeping-the-client-id-secretarrow-up-right

Last updated