# ngx-oauth2-utils

> A utility library that can be used to request OAuth2 tokens from multiple OAuth2 providers.

Latest version **0.0.3** (published 2019-08-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngx-oauth2-utils
pnpm add ngx-oauth2-utils
yarn add ngx-oauth2-utils
bun add ngx-oauth2-utils
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2019-08-11 |
| First published | 2019-08-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 150.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Matías Hermosilla |
| Maintainers | matiasah |
| Keywords | angular, javascript, typescript, oauth2, utils, ngx |

## Links

- npm: https://www.npmjs.com/package/ngx-oauth2-utils
- Repository: https://github.com/matiasah/ngx-oauth2-utils
- Issues: https://github.com/matiasah/ngx-oauth2-utils/issues
- npm.io page: https://npm.io/package/ngx-oauth2-utils

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^1.9.0

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2019-08-11
- 0.0.2 — 2019-08-05
- 0.0.1 — 2019-08-05

## README

# ngx-oauth2-utils

A utility library that can be used to request OAuth2 tokens from multiple OAuth2 providers.

## Installation
Run the following command in your project folder.
```
npm install ngx-oauth2-utils
```

## Usage
Import the following method in your module file.
```
import { OAuth2ProviderFor } from 'ngx-oauth2-utils';
```

Define the following provider in your module's NgModule declaration.
```ts
import { OAUTH2_PROVIDERS, OAuth2Provider } from 'ngx-oauth2-utils';

const oauth2Providers: OAuth2Provider[] = [
  {
    name: 'Google',
    authorizationUri: 'https://accounts.google.com/o/oauth2/v2/auth',
    clientId: '',
    scope: 'email profile',
    authorizationParams: {
      prompt: 'consent',
      access_type: 'online'
    }
  },
  {
    name: 'Facebook',
    authorizationUri: 'https://www.facebook.com/v4.0/dialog/oauth',
    clientId: '',
    scope: 'public_profile email'
  }
];

@NgModule({
    ...
    providers: [
        {
            provide: OAUTH2_PROVIDERS,
            useValue: oauth2Providers
        }
    ],
    ...
})
export class AppModule { }
```

Inject the ```OAuth2Service``` into your components.
```ts
import { Component } from '@angular/core';
import { OAuth2Service, OAuth2Authentication } from 'ngx-oauth2-utils';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {

    // The authentication
    private authentication: OAuth2Authentication;

    public constructor(
        private oauth2Service: OAuth2Service
    ) {

        // Attempt to handle the authentication in the activated route
        this.oauth2Service.getSignInAuthentication().subscribe(
            authentication => {

                // Authentication found, store authentication in localStorage
                this.oauth2Service.setAuthentication(authentication);
            }
        );

        // Get the authentication stored in the localStorage
        this.authentication = this.oauth2Service.getAuthentication();

    }

    public signInWithGoogle(): void {
        this.oauth2Service.signIn('Google');
    }

    public signInWithFacebook(): void {
        this.oauth2Service.signIn('Facebook');
    }

}
```

---
_Source: https://npm.io/package/ngx-oauth2-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
