0.2.0 • Published 2 years ago

ngx-one-tap v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

NgxOneTap - Google One Tap for Angular

This library is a wrapper around the Google One Tap SDK for Angular.

Installation

npm install --save ngx-one-tap

Usage

Import the module

import {NgxOneTapModule} from 'ngx-one-tap';

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    // ... any other imports you need
    NgxOneTapModule.config({
      // For the full list of options, see the documentation:
      // https://developers.google.com/identity/gsi/web/reference/js-reference#IdConfiguration
        client_id: 'CLIENT_ID.apps.googleusercontent.com',
        cancel_on_tap_outside: true,
        auto_select: false,
      }),
    // ... any other imports you need
  ],
  providers: [],
  bootstrap: [AppComponent]
});

Import and inject the service into your component

import {Component, OnInit} from '@angular/core';
import {CredentialResponse, NgxOneTapService, PromptMomentNotification} from 'ngx-one-tap';

@Component({
  selector: 'app-auth',
  templateUrl: './auth.component.html',
  styleUrls: ['./auth.component.scss']
})
export class AuthComponent implements OnInit {
  constructor(private oneTap: NgxOneTapService) {
  }

  ngOnInit() {
    this.oneTap.init({
      // For the full list of options, see the documentation:
      // https://developers.google.com/identity/gsi/web/reference/js-reference#IdConfiguration
      client_id: 'CLIENT_ID.apps.googleusercontent.com',
      context: 'signin',
    });

    this.onetap.identity$
      .subscribe((res: CredentialResponse) => {
        /**
         * The response contains a JWT response object
         * containing the user information
         * that can be used to authenticate the user.
         *
         * This should be validated before using it.
         * Please read the documentation for more details.
         *
         * For example:
         *   NodeJS: https://cloud.google.com/nodejs/docs/reference/google-auth-library/latest#verifying-id-tokens
         *   Python: https://googleapis.dev/python/google-auth/latest/reference/google.oauth2.id_token.html#module-google.oauth2.id_token
         */
      });

    this.oneTap.promptNotification$
      .subscribe((event: PromptMomentNotification) => {
        /**
         * The response contains a prompt-related event.
         * The event allows you to determine what the event and the cause were.
         * 
         * Please read the documentation for more details:
         * https://developers.google.com/identity/gsi/web/reference/js-reference#PromptMomentNotification
         */
        event.getMomentType();
        event.isDismissedMoment();
        event.getDismissedReason();
        event.isDisplayed();
        event.isNotDisplayed();
        event.getNotDisplayedReason();
        event.isSkippedMoment();
        event.getSkippedReason();
      });
    
    this.oneTap.prompt();
  }
}
0.2.0

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago