# passport-microsoft-typescript

> Microsoft (OAuth 2.0) authentication strategy for Passport.

Latest version **6.0.2** (published 2020-11-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install passport-microsoft-typescript
pnpm add passport-microsoft-typescript
yarn add passport-microsoft-typescript
bun add passport-microsoft-typescript
```

## 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 | 6.0.2 |
| Published | 2020-11-16 |
| First published | 2020-11-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Terry Vimont |
| Maintainers | tavimont-usgs |

## Links

- npm: https://www.npmjs.com/package/passport-microsoft-typescript
- Repository: git@code.chs.usgs.gov:vwe/passport-microsoft-typescript
- npm.io page: https://npm.io/package/passport-microsoft-typescript

## Dependencies (1)

- [passport-oauth2](https://npm.io/package/passport-oauth2.md) ^1.5.0

## Recent versions

- 6.0.2 (latest) — 2020-11-16
- 6.0.1 — 2020-11-16
- 5.0.1 — 2020-11-16
- 5.0.0 — 2020-11-13
- 4.0.1 — 2020-11-12
- 4.0.0 — 2020-11-12

## README

# Passport-Microsoft

[Passport](http://passportjs.org/) strategy for authenticating with Microsoft organizations
using the OAuth 2.0 API.

This module lets you authenticate using Microsoft in your Node.js applications.
By plugging into Passport, Microsoft 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/).

## Install

`$ npm install passport-microsoft-typescript`

## Usage

### Configure Strategy

The Microsoft authentication strategy authenticates users using a Microsoft organization 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 client ID, client secret, and callback URL.

```ts
passport.use(new MicrosoftStrategy({
    clientID: MICROSOFT_CLIENT_ID,
    clientSecret: MICROSOFT_CLIENT_SECRET,
    callbackURL: "http://127.0.0.1:3000/auth/microsoft/callback"
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ username: profile.username }, function (err, user) {
      return done(err, user);
    });
  }
));
```

#### Authenticate Requests

Use `passport.authenticate()`, specifying the `'microsoft'` strategy, to
authenticate requests.

For example, as route middleware in an [Express](http://expressjs.com/)
application:

```ts
app.get('/auth/microsoft',
  passport.authenticate('microsoft'));

app.get('/auth/microsoft/callback',
  passport.authenticate('microsoft', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  }
);
```

## License

[The MIT License](http://opensource.org/licenses/MIT)

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