Hamid Aijaz
Hamid Aijaz

Reputation: 47

Google Authenticate in Angular 5

How to enable Google Authentication in Angular 5 app?

I want to implement to enabled otp setup and when someone login to app whose otp is enabled than they input 6 digit code from Google Authenticator.

Upvotes: 1

Views: 3334

Answers (3)

Nino Filiu
Nino Filiu

Reputation: 18473

For Angular 2+, there is a library that does just that: Speakeasy. Here's the workflow:

1 - Creation:

  1. Speakeasy generates a secret
  2. A QR code is generated based on that secret
  3. The user scans it using Google Authenticator

Now, both the user and the server share a secret that is used to generate time-based one-time passwords (TOTP).

2 - Authentication

  1. The user enter its credentials + the token generated by Google Authenticator for your app at this moment
  2. The server can check the authenticity of the user by comparing the token given by the user and the token generated by the secret he saved for this user

Note there is no communication with Google Authenticator - don't bother looking for an API. Tokens are generated based on the time and the secret.

Upvotes: 1

user9528504
user9528504

Reputation: 34

As such there is no Google authentication directly provide in angular 5. Some how you have to write the API in other language like PHP or else which will contain your Google authentication code. And that API will return you the qrcode with the help of that you can simply integrate that along with UI in angular 5. Once user scan the qrcode , in next login just ask for 6 digit and give call to API by passing that 6 digit and get validate the same. I have implemented the same and it worked

Upvotes: 1

Dinesh Arora
Dinesh Arora

Reputation: 2255

There are many sample apps on GitHub and articles out there. - https://github.com/tjoudeh/AngularJSTwoFactorAuthentication - Use nodes plugin - https://www.npmjs.com/package/angular2-google-login

Upvotes: -1

Related Questions