# @rray/oauth2

> A very simple OAuth2 implementation

Latest version **1.0.0** (published 2022-08-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rray/oauth2
pnpm add @rray/oauth2
yarn add @rray/oauth2
bun add @rray/oauth2
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-08-08 |
| First published | 2022-08-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=16.9.0 |
| Dependencies | 0 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Nikita Skovoroda |
| Maintainers | chalker |

## Links

- npm: https://www.npmjs.com/package/@rray/oauth2
- npm.io page: https://npm.io/package/@rray/oauth2

## Recent versions

- 1.0.0 (latest) — 2022-08-08

## README

# `@rray/oauth2`

A very simple OAuth2 implementation

## Global `fetch` expectation

Note: this package expects a global `fetch` to be set, which is present on newer Node.js versions.

It can be polyfilled with `node-fetch`, for example.

## Usage

```js
import { OAuth2 } from './oauth2.mjs'

// provides { full_auth_url, async auth(code) }
const oauth = OAuth2('google', { g_client_id, g_client_secret, g_redirect_uri })

server.get('/oauth', (req, res) => res.redirect(oauth.full_auth_url))

server.get('/oauth/callback', async (req, res) => {
  const userinfo = await oauth.auth(req.query.code)
  ...
})
```

## Providers support

Currently two providers have built-in support: `'google'` and `'yandex'`.

In order to use this with another provider, just pass in the corresponding provider object manually:

```js
const provider = { ... }
const oauth = OAuth2(provider, { client_id, client_secret, redirect_uri })
```

See [providers list](./providers.mjs) for the structure of the `provider` object.

## License

[MIT](./LICENSE)

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