https://github.com/jaredhanson/passport-oauth2-client-password
OAuth 2.0 client password authentication strategy for Passport and Node.js.
https://github.com/jaredhanson/passport-oauth2-client-password
Last synced: about 1 year ago
JSON representation
OAuth 2.0 client password authentication strategy for Passport and Node.js.
- Host: GitHub
- URL: https://github.com/jaredhanson/passport-oauth2-client-password
- Owner: jaredhanson
- License: mit
- Created: 2012-07-10T05:28:10.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2020-07-06T18:53:07.000Z (about 6 years ago)
- Last Synced: 2024-10-29T21:10:45.745Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://www.passportjs.org/packages/passport-oauth2-client-password/?utm_source=github&utm_medium=referral&utm_campaign=passport-oauth2-client-password&utm_content=about
- Size: 17.6 KB
- Stars: 96
- Watchers: 5
- Forks: 27
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# passport-oauth2-client-password
OAuth 2.0 client password authentication strategy for [Passport](https://github.com/jaredhanson/passport).
This module lets you authenticate requests containing client credentials in the
request body, as [defined](http://tools.ietf.org/html/draft-ietf-oauth-v2-27#section-2.3.1)
by the OAuth 2.0 specification. These credentials are typically used protect
the token endpoint and used as an alternative to HTTP Basic authentication.
---
Advertisement
Node.js API Masterclass With Express & MongoDB
Create a real world backend for a bootcamp directory app
---
[](https://www.npmjs.com/package/passport-oauth2-client-password)
[](https://travis-ci.org/jaredhanson/passport-oauth2-client-password)
[](https://coveralls.io/github/jaredhanson/passport-oauth2-client-password)
[...](https://github.com/jaredhanson/passport-oauth2-client-password/wiki/Status)
## Install
```sh
$ npm install passport-oauth2-client-password
```
## Usage
#### Configure Strategy
The OAuth 2.0 client password authentication strategy authenticates clients
using a client ID and client secret. The strategy requires a `verify` callback,
which accepts those credentials and calls `done` providing a client.
```js
passport.use(new ClientPasswordStrategy(
function(clientId, clientSecret, done) {
Clients.findOne({ clientId: clientId }, function (err, client) {
if (err) { return done(err); }
if (!client) { return done(null, false); }
if (client.clientSecret != clientSecret) { return done(null, false); }
return done(null, client);
});
}
));
```
#### Authenticate Requests
Use `passport.authenticate()`, specifying the `'oauth2-client-password'`
strategy, to authenticate requests. This strategy is typically used in
combination with HTTP Basic authentication (as provided by [passport-http](https://github.com/jaredhanson/passport-http)),
allowing clients to include credentials in the request body.
For example, as route middleware in an [Express](http://expressjs.com/)
application, using [OAuth2orize](https://github.com/jaredhanson/oauth2orize)
middleware to implement the token endpoint:
```
app.get('/profile',
passport.authenticate(['basic', 'oauth2-client-password'], { session: false }),
oauth2orize.token());
```
## Examples
The [example](https://github.com/jaredhanson/oauth2orize/tree/master/examples/express2)
included with [OAuth2orize](https://github.com/jaredhanson/oauth2orize)
demonstrates how to implement a complete OAuth 2.0 authorization server.
`ClientPasswordStrategy` is used to authenticate clients as they request access
tokens from the token endpoint.
## Tests
```sh
$ npm install --dev
$ make test
```
## Credits
- [Jared Hanson](http://github.com/jaredhanson)
## License
[The MIT License](http://opensource.org/licenses/MIT)
Copyright (c) 2012-2013 Jared Hanson <[http://jaredhanson.net/](http://jaredhanson.net/)>