# @lazy/oauth2-implicit-grant-client

> A simple Oauth2 Implicit Grant client for the lazy developer.

Latest version **1.0.0-rc.3** (published 2021-11-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @lazy/oauth2-implicit-grant-client
pnpm add @lazy/oauth2-implicit-grant-client
yarn add @lazy/oauth2-implicit-grant-client
bun add @lazy/oauth2-implicit-grant-client
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-rc.3 |
| Published | 2021-11-28 |
| First published | 2021-09-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | aidant |
| Keywords | grant, implicit, oauth, oauth2 |

## Links

- npm: https://www.npmjs.com/package/@lazy/oauth2-implicit-grant-client
- Repository: https://github.com/aidant/implicit-grant
- Homepage: https://github.com/aidant/implicit-grant#readme
- Issues: https://github.com/aidant/implicit-grant/issues
- npm.io page: https://npm.io/package/@lazy/oauth2-implicit-grant-client

## Recent versions

- 1.0.0-rc.3 (latest) — 2021-11-28
- 1.0.0-rc.2 — 2021-09-10
- 1.0.0-rc.1 — 2021-09-10
- 1.0.0-rc.0 — 2021-09-09

## README

# Lazy Oauth2 Implicit Grant Client

<p align='center'>
  A simple Oauth2 Implicit Grant client for the lazy developer.
  <br>
  <a href='https://www.npmjs.com/package/@lazy/oauth2-implicit-grant-client'>
    <img src="https://img.shields.io/npm/v/@lazy/oauth2-implicit-grant-client?style=flat-square">
  </a>
  <a href='https://bundlephobia.com/package/@lazy/oauth2-implicit-grant-client'>
    <img src="https://img.shields.io/bundlephobia/minzip/@lazy/oauth2-implicit-grant-client?label=minified%20%26%20gzipped&style=flat-square">
  </a>
  <a href='https://github.com/aidant/implicit-grant/actions/workflows/publish.yml'>
    <img src="https://img.shields.io/github/workflow/status/aidant/implicit-grant/Publish?style=flat-square">
  </a>
</p>

---

## Table of Contents

- [Example](#example)
- [API](#api)
  - [`getAccessToken`]
  - [`handleImplicitGrantCallback`]

## Example

```ts
import { getAccessToken, handleImplicitGrantCallback } from '@lazy/oauth2-implicit-grant-client'

handleImplicitGrantCallback()

const token = await getAccessToken('https://api.example.com/authorize', {
  client_id: 'example-client-id',
})
```

## API

### `getAccessToken`

The [`getAccessToken`] function handles the Implicit Grant authentication flow. A new window is created where the user is then prompted to authenticate with the Oauth2 provider, once the user had accepted or rejected the request the `handleImplicitGrantCallback` function then handles the response and returns it back via the promise from `getAccessToken` - just like magic.

#### Parameters

- `endpoint` - **string** - The Authorization endpoint of the Oauth2 provider.
- `parameters` - **object** - The Oauth2 parameters such as; `client_id`, `scope`, or `redirect_uri`.

#### Example

```ts
import { getAccessToken } from '@lazy/oauth2-implicit-grant-client'

const token = await getAccessToken('https://api.example.com/authorize', {
  client_id: 'example-client-id',
})
```

Returns `Promise<string>`

### `handleImplicitGrantCallback`

The [`handleImplicitGrantCallback`] function is responsible for returning the response from the authentication endpoint back to the [`getAccessToken`] function. If you call the [`getAccessToken`] and [`handleImplicitGrantCallback`] functions in the same page make sure you call the [`handleImplicitGrantCallback`] function before the [`getAccessToken`].

#### Example

```ts
import { handleImplicitGrantCallback } from '@lazy/oauth2-implicit-grant-client'

handleImplicitGrantCallback()
```

[`getaccesstoken`]: #getaccesstoken
[`handleimplicitgrantcallback`]: #handleimplicitgrantcallback

---
_Source: https://npm.io/package/@lazy/oauth2-implicit-grant-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
