# passport-google-oauth-token

> Google access token authentication strategy for Passport

Latest version **1.0.7** (published 2023-05-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install passport-google-oauth-token
pnpm add passport-google-oauth-token
yarn add passport-google-oauth-token
bun add passport-google-oauth-token
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2023-05-21 |
| First published | 2019-12-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 35.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | Alpha |
| Maintainers | zgid123 |
| Keywords | passport, google, auth, authn, authentication, identity |

## Links

- npm: https://www.npmjs.com/package/passport-google-oauth-token
- Repository: https://github.com/zgid123/passport-google-oauth-token
- npm.io page: https://npm.io/package/passport-google-oauth-token

## Dependencies (1)

- [passport-oauth2](https://npm.io/package/passport-oauth2.md) ^1.7.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

- 1.0.7 (latest) — 2023-05-21
- 1.0.6 — 2023-04-08
- 1.0.5 — 2023-03-08
- 1.0.4 — 2022-07-06
- 1.0.3 — 2022-02-12
- 1.0.2 — 2020-01-09
- 1.0.1 — 2019-12-31

## README

# passport-google-oauth-token

[Passport](http://passportjs.org/) strategy for authenticating with [Google](http://www.google.com/)
access tokens using the OAuth 2.0 API.

This module is created based on [passport-facebook-token](https://github.com/drudge/passport-facebook-token)
and [passport-google-oauth2](https://github.com/jaredhanson/passport-google-oauth2).

This module lets you authenticate using Google in your Node.js applications.
By plugging into Passport, Google authentication can be easily and
unobtrusively integrated into any application or framework that supports
[Connect](http://www.senchalabs.org/connect/)-style middleware, including
[Express](http://expressjs.com/).

## Installation

    $ npm install passport-google-oauth-token

## Usage

### Configure Strategy

The Google authentication strategy authenticates users using a Google
account and OAuth 2.0 tokens.  The strategy requires a `verify` callback, which
accepts these credentials and calls `cb` providing a user, as well as
`options` specifying an app ID and app secret.

```js
const GoogleOauthTokenStrategy = require('passport-google-oauth-token');

passport.use(new GoogleOauthTokenStrategy({
  clientID: GOOGLE_CLIENT_ID,
  clientSecret: GOOGLE_CLIENT_SECRET,
}, (accessToken, refreshToken, profile, cb) => {
  User.findOrCreate({ googleId: profile.id }, (error, user) => {
    return done(error, user);
  });
}));
```

### Authenticate Requests

Use `passport.authenticate()`, specifying the `'google-oauth-token'` strategy, to authenticate requests.

```js
app.post('/auth/google/token',
  passport.authenticate('google-oauth-token'),
  (req, res) => {
    // do something with req.user
    res.send(req.user ? 200 : 401);
  },
);
```

### Client Requests

Clients can send requests to routes that use passport-google-oauth-token authentication using `query parms`, `body`, or `HTTP headers`. Clients will need to transmit the `access_token`
and optionally the `refresh_token` that are received from google after login.

## Options

| Field              | Description                       | Default Value                                 |
| ------------------ | --------------------------------- | --------------------------------------------- |
| clientID           | Google's client id                |                                               |
| clientSecret       | Google's client secret            |                                               |
| tokenURL           | Google's oauth2 token url         | https://www.googleapis.com/oauth2/v4/token    |
| profileURL         | Google's scope profile url        | https://www.googleapis.com/oauth2/v3/userinfo |
| authorizationURL   | Google's oauth2 authorization url | https://accounts.google.com/o/oauth2/v2/auth  |
| tokenURLVersion    | Version of token url              | v4                                            |
| userinfoURLVersion | Version of profile url            | v3                                            |
| authURLVersion     | Version of authorization url      | v2                                            |

## Profile Example

```js
{
  provider: 'google',
  id: '1234',
  displayName: 'Alpha',
  name: {
    familyName: 'Lucifer',
    givenName: 'Alpha',
  },
  emails: [
    {
      value: 'alphanolucifer@gmail.com',
      verified: true,
    },
  ],
  photos: [
    {
      value: 'https://google.com',
    },
  ],
  _json: {},
  _raw: {},
}
```

## License

The MIT License (MIT)

Copyright (c) 2015 Nicholas Penree

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

---
_Source: https://npm.io/package/passport-google-oauth-token · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
