# passport-stack-exchange-token

> Stack Exchange token authentication strategy for Passport.

Latest version **0.1.0** (published 2017-12-07) · 0 weekly downloads

## Install

```sh
npm install passport-stack-exchange-token
pnpm add passport-stack-exchange-token
yarn add passport-stack-exchange-token
bun add passport-stack-exchange-token
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2017-12-07 |
| First published | 2017-12-07 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.4.0 |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Nazar Mozol |
| Maintainers | acruxray |
| Keywords | passport, google, auth, authn, authentication, identity |

## Links

- npm: https://www.npmjs.com/package/passport-stack-exchange-token
- Repository: https://github.com/acruxray/passport-stack-exchange-token
- Homepage: https://github.com/acruxray/passport-stack-exchange-token#readme
- Issues: http://github.com/acruxray/passport-stack-exchange-token/issues
- npm.io page: https://npm.io/package/passport-stack-exchange-token

## Dependencies (3)

- [pkginfo](https://npm.io/package/pkginfo.md) 0.2.x
- [request](https://npm.io/package/request.md) ^2.83.0
- [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

- 0.1.0 (latest) — 2017-12-07

## README

# Passport-Stack-Exchange-Token

[Passport](http://passportjs.org/) strategy for authenticating with [Stack Exchange](https://stackexchange.com/)  access tokens using the OAuth 2.0 API.

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

```bash
npm install passport-stack-exchange-token
```

## Usage

#### Configure Strategy

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

```javascript
var StackExchangeTokenStrategy = require('passport-stack-exchange-token').Strategy;

passport.use(new StackExchangeTokenStrategy({
    clientID: STACK_EXCHANGE_CLIENT_ID,
    clientSecret: STACK_EXCHANGE_CLIENT_SECRET,
    stackAppsKey: STACK_EXCHANGE_APPS_KEY,
    site: 'stackoverflow'
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ stackExchangeId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));
```

#### Authenticate Requests

Use `passport.authenticate('stack-exchange-token')` to authenticate requests.

```javascript
router.get('/auth/stack-exchange/token', passport.authenticate('stack-exchange-token'),
  function(req, res) {
    res.send(req.user);
  });
```

GET request need to have `access_token` and optionally the `refresh_token` in either the query string or set as a header.  If a POST is being preformed they can also be included in the body of the request.

## Credits

* [Rob DiMarco](https://github.com/robertdimarco)
* [Nicholas Penree](https://github.com/drudge)
* [Jared Hanson](https://github.com/jaredhanson)

## License

[The MIT License](https://opensource.org/licenses/MIT)

Copyright (c) 2017 Nazar Mozol

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