Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/buttercup/google-oauth2-client
Google OAuth2 authentication client
https://github.com/buttercup/google-oauth2-client
google-authentication google-oauth2 oauth2 oauth2-client
Last synced: about 2 months ago
JSON representation
Google OAuth2 authentication client
- Host: GitHub
- URL: https://github.com/buttercup/google-oauth2-client
- Owner: buttercup
- License: mit
- Created: 2019-07-20T08:39:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-11-11T05:47:18.000Z (about 1 year ago)
- Last Synced: 2024-10-29T16:58:14.385Z (2 months ago)
- Topics: google-authentication, google-oauth2, oauth2, oauth2-client
- Language: TypeScript
- Size: 555 KB
- Stars: 9
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Google OAuth2 Client
> Minimal compatibility-first Google OAuth2 client implementation[![Buttercup](https://cdn.rawgit.com/buttercup-pw/buttercup-assets/6582a033/badge/buttercup-slim.svg)](https://buttercup.pw) [![npm version](https://badge.fury.io/js/%40buttercup%2Fgoogle-oauth2-client.svg)](https://www.npmjs.com/package/@buttercup/google-oauth2-client) ![Tests status](https://github.com/buttercup/google-oauth2-client/actions/workflows/test.yml/badge.svg)
## About
This library is a minimal implementation of the [`google-auth-library`](https://github.com/googleapis/google-auth-library-nodejs) project, designed to be compatible with NodeJS, the browser and React Native. The `google-auth-library` package has had [problems with compatibility](https://github.com/googleapis/google-auth-library-nodejs/issues/150) in this regard and rather than wait for that to get sorted, this library was released to solve the exact problem without the overhead of project politics, wait times and package excess (extra features not needed that are causing the incompatibilities in the first place).
This library is targeted at NodeJS but should work everywhere.
## Usage
Install by running `npm install @buttercup/google-oauth2-client --save`.
Import the `OAuth2Client` class to get started, similarly to the original implemenation:
```javascript
import { OAuth2Client } from "@buttercup/google-oauth2-client";const client = new OAuth2Client(
"my-client-id",
"my-client-secret",
"http://redirect.uri"
);const authURL = client.generateAuthUrl(/* ... */);
```### Implemented features
The following methods are implemented:
| Method | Example | Description |
|-----------------------|-----------------------------------|-------------------------------------------|
| `generateAuthUrl` | `generateAuthUrl({ access_type: "offline", prompt: "consent", scope: "profile" })` | Generate an authorisation URL |
| `exchangeAuthCodeForToken` | `await exchangeAuthCodeForToken(authCode)` | Get the tokens for an authorisation code |
| `refreshAccessToken` | `await refreshAccessToken(refreshToken`)| Refresh the tokens |