ot-passport-password-grant

Password grant OAuth2.0 strategy for Passport.

Usage no npm install needed!

<script type="module">
  import otPassportPasswordGrant from 'https://cdn.skypack.dev/ot-passport-password-grant';
</script>

README

passport-password-grant

HTTP OAuth2.0 Password Grant authentication strategy for Passport.

This module lets you authenticate users via username and password provided to an authozization server using a password grant REST call and receiving a access token and refresh token issued using OAuth 2.0.

Usage

Configure Strategy

The grant strategy will return a token containing token.access_token and token.refresh_token

    passport.use(new GrantStrategy({
      usernameField: 'email',
      passwordField: 'password',
      clientId: 'theClientId',
      scope: 'theScope',
      host: 'https://auth.server'
      port: '8443',
      function(token, done) {
        // Do something with the token
      }
    ));

Authenticate Requests

Use passport.authenticate(), specifying the 'password-grant' strategy, to authenticate requests.

    passport.authenticate('password-grant',
      function(req, res) {
        res.json(req.user);
      }
    );

License

The MIT License