# passport-github-token-nest

> Passport strategy for authenticating with GitHub via OAuth2 access tokens

Latest version **3.0.0** (published 2021-09-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install passport-github-token-nest
pnpm add passport-github-token-nest
yarn add passport-github-token-nest
bun add passport-github-token-nest
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2021-09-22 |
| First published | 2021-09-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 19 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | ghaiklor |
| Maintainers | 0xb4lamx |
| Keywords | passport, github, token, auth, authentication |

## Links

- npm: https://www.npmjs.com/package/passport-github-token-nest
- Repository: https://github.com/ghaiklor/passport-github-token
- Issues: https://github.com/ghaiklor/passport-github-token/issues
- npm.io page: https://npm.io/package/passport-github-token-nest

## Dependencies (1)

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

- 3.0.0 (latest) — 2021-09-22

## README

# passport-github-token-nest

### This is passport-github-token but transpiled with @babel-plugin-transform-classes so now it works with Nest.js as expected

#### Why? Nest.js PassportStrategy expects a function, not a class

#### Usage:

```html
import { Strategy } from 'passport-github-token-nest';

export class GithubStrategy extends PassportStrategy(Strategy, 'github'){}
```

![Build Status](https://img.shields.io/travis/ghaiklor/passport-github-token.svg)
![Coverage](https://img.shields.io/coveralls/ghaiklor/passport-github-token.svg)

![Downloads](https://img.shields.io/npm/dm/passport-github-token.svg)
![Downloads](https://img.shields.io/npm/dt/passport-github-token.svg)
![npm version](https://img.shields.io/npm/v/passport-github-token.svg)
![License](https://img.shields.io/npm/l/passport-github-token.svg)

[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
![dependencies](https://img.shields.io/david/ghaiklor/passport-github-token.svg)
![dev dependencies](https://img.shields.io/david/dev/ghaiklor/passport-github-token.svg)

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

This module lets you authenticate using GitHub in your Node.js applications.
By plugging into Passport, GitHub 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

```shell
npm install passport-github-token
```

## Usage

### Configure Strategy

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

```javascript
var GitHubTokenStrategy = require('passport-github-token');

passport.use(new GitHubTokenStrategy({
    clientID: GITHUB_CLIENT_ID,
    clientSecret: GITHUB_CLIENT_SECRET,
    passReqToCallback: true
}, function(req, accessToken, refreshToken, profile, next) {
    User.findOrCreate({'github.id': profile.id}, function(error, user) {
        return next(error, user);
    });
}));
```

### Authenticate Requests

Use `passport.authenticate()`, specifying the `github-token` strategy, to authenticate requests.

For example, as route middleware in an [Express](http://expressjs.com/) application:

```javascript
app.get('/auth/github', passport.authenticate('github-token'));
```

Or if you are using Sails framework:

```javascript
// AuthController.js
module.exports = {
    github: function(req, res) {
        passport.authenticate('github-token', function(error, user, info) {
            if (error) return res.serverError(error);
            if (info) return res.unauthorized(info);
            return res.ok(user);
        })(req, res);
    }
};
```

The request to this route should include a GET or POST data with the keys `access_token` and optionally, `refresh_token` set to the credentials you receive from GitHub.

```
GET /auth/github?access_token=<TOKEN>
```

## Issues

If you receive a `401 Unauthorized` error, it is most likely because you have wrong access token or not yet specified any application permissions.
Once you refresh access token with new permissions, try to send this access token again.

## License

[MIT](./LICENSE)

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