npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-sign-in-with-google

v0.1.4

Published

Angular package implementing Sign In with Google, including automatic refresh and access token injection.

Downloads

26

Readme

NgxSignInWithGoogle

Motivation

Sign In with Google for Web offers user authentication through Google Accounts. From their website:

Sign In With Google helps you to quickly and easily manage user authentication and sign-in 
to your website. Users sign into a Google Account, provide their consent, and securely share 
their profile information with your platform.
Customizable buttons and multiple flows are supported for user sign up and sign in.

However, implementing this into an Angular application didn't feel very straightforward, that's why this library was created.

Features

  • Easily render the login button with the with-google-auth-button directive
  • Use the WithGoogleAuthService to get id and access tokens, and have them automatically refreshed
  • rxjs subject that publishes events like a login or a logout
  • Intercepting httpClient requests which match defined prefixes with the WithGoogleAuthInterceptor to add access token to the request

Installation

npm install ngx-sign-in-with-google

Usage

Setup

At first, follow the setup guide.

Extend your app.module.ts with the following config (more details about the config can be found in the JavaScript API:

  imports: [
    ...,
    WithGoogleAuthModule
  ],
  providers: [
    ...,
    {
      provide: 'WithGoogleAuthConfig',
      useValue: {
        clientId: '123456789-abcdefghijklmnop.apps.googleusercontent.com',
        scopes: 'openid profile email',
        prompt: "none",
        enableOneTap: false,
        buttonConfig: {
          type: 'standard',           // 'standard' | 'icon'
          theme: 'outline',           // 'outline' | 'filled_blue' | 'filled_black'
          size: 'large',              // 'small' | 'medium' | 'large'
          text: 'signin_with',        // 'signin_with' | 'signup_with' | 'continue_with' | 'signin'
          shape: 'rectangular',       // 'rectangular' | 'pill' | 'circle' | 'square'
          logo_alignment: 'left',     // 'left' | 'center' 
          width: '400',               // string, value in pixel
          locale: 'de_DE'             // locale of button text, default is browser's locale
        },
        interceptUrlPrefixes: [
         "https://example.com/v1/auth/",
         "https://example.com/v2/",
        ]
      } as WithGoogleAuthConfig,
    },
    {
          provide: HTTP_INTERCEPTORS,
          useClass: WithGoogleAuthInterceptor,
          multi: true
    },
  ]

The interceptUrlPrefixes in the example would

  • intercept: https://example.com/v1/auth/some/route
  • intercept: https://example.com/v1/auth/
  • NOT intercept: https://example.com/v1/auth
  • NOT intercept: https://example.com/v1
  • NOT intercept: https://example.com/v1/another/route
  • intercept: https://example.com/v2/route

If you don't want to intercept anything, assign the interceptUrlPrefixes an empty array.

Injecting the service

constructor(
  private authService: WithGoogleAuthService
) {}

Render login button

<with-google-auth-button></with-google-auth-button>

Access user details

Use this.authService.getIdToken() to get an instance of WithGoogleAuthIdToken.

let idToken = this.authService.getIdToken()
console.log(idToken.name)       // display user's name
<!-- Show the user's profile picture if they are logged in -->
<img
  *ngIf="authService.getIdToken() !== undefined"
  [src]="authService.getIdToken()!.picture"
>

Get notified of login/logout

let authEvents = this.authService.getEventSubject()

authEvents.subscribe({
  next: (v) => console.log(v.event),
  error: (e) => console.error(e)
})

Author

Simon Klimaschka (@klimaschkas)