|
1 |
| -Complete, compliant and well tested module for implementing an OAuth2 server in [node.js](https://nodejs.org/). |
| 1 | +# oauth2-server |
2 | 2 |
|
3 |
| - [![NPM Version][npm-image]][npm-url] |
4 |
| - [![Build Status][travis-image]][travis-url] |
5 |
| - [![NPM Downloads][downloads-image]][downloads-url] |
| 3 | +[![npm Version][npm-image]][npm-url] |
| 4 | +[![npm Downloads][downloads-image]][downloads-url] |
| 5 | +[![Test Status][travis-image]][travis-url] |
| 6 | +[![MIT Licensed][license-image]][license-url] |
| 7 | +[![oauthjs Slack][slack-image]][slack-url] |
6 | 8 |
|
7 |
| -# Quick Start |
| 9 | +Complete, compliant and well tested module for implementing an OAuth2 server in [Node.js](https://nodejs.org). |
8 | 10 |
|
9 |
| - The _node-oauth2-server_ module is framework-agnostic but there are several wrappers available for popular frameworks such as [express](https://github.com/oauthjs/express-oauth-server) and [koa 2](https://github.com/oauthjs/koa-oauth-server). |
10 | 11 |
|
11 |
| - Using the _express_ wrapper (_recommended_): |
| 12 | +## Installation |
12 | 13 |
|
13 |
| -```js |
14 |
| -var express = require('express'); |
15 |
| -var oauthServer = require('express-oauth-server'); |
16 |
| -var app = express(); |
| 14 | +```bash |
| 15 | +npm install oauth2-server |
| 16 | +``` |
17 | 17 |
|
18 |
| -var oauth = new oauthServer({ model: model }); |
| 18 | +The *oauth2-server* module is framework-agnostic but there are several officially supported wrappers available for popular HTTP server frameworks such as [Express](https://npmjs.org/package/express-oauth-server) and [Koa](https://npmjs.org/package/koa-oauth-server). If you're using one of those frameworks it is strongly recommended to use the respective wrapper module instead of rolling your own. |
19 | 19 |
|
20 |
| -app.use(oauth.authenticate()); |
21 | 20 |
|
22 |
| -app.get('/', function (req, res) { |
23 |
| - res.send('Hello World'); |
24 |
| -}) |
| 21 | +## Features |
25 | 22 |
|
26 |
| -app.listen(3000); |
27 |
| -``` |
| 23 | +- Supports `authorization_code`, `client_credentials`, `refresh_token` and `password` grant, as well as *extension grants*, with scopes. |
| 24 | +- Can be used with *promises*, *Node-style callbacks*, *ES6 generators* and *async*/*await* (using [Babel](https://babeljs.io)). |
| 25 | +- Fully [RFC 6749](https://tools.ietf.org/html/rfc6749.html) and [RFC 6750](https://tools.ietf.org/html/rfc6749.html) compliant. |
| 26 | +- Implicitly supports any form of storage, e.g. *PostgreSQL*, *MySQL*, *MongoDB*, *Redis*, etc. |
| 27 | +- Complete [test suite](https://github.com/oauthjs/node-oauth2-server/tree/master/test). |
28 | 28 |
|
29 |
| - Using this module directly (_for custom servers only_): |
30 | 29 |
|
31 |
| -```js |
32 |
| -var Request = require('oauth2-server').Request; |
33 |
| -var oauthServer = require('oauth2-server'); |
| 30 | +## Documentation |
34 | 31 |
|
35 |
| -var oauth = new oauthServer({ model: model }); |
| 32 | +[Documentation](https://oauth2-server.readthedocs.io) is hosted on Read the Docs. |
36 | 33 |
|
37 |
| -var request = new Request({ |
38 |
| - headers: { authorization: 'Bearer foobar' } |
39 |
| -}); |
40 | 34 |
|
41 |
| -oauth.authenticate(request) |
42 |
| - .then(function(data) { |
43 |
| - // Request is authorized. |
44 |
| - }) |
45 |
| - .catch(function(e) { |
46 |
| - // Request is not authorized. |
47 |
| - }); |
48 |
| -``` |
| 35 | +## Examples |
49 | 36 |
|
50 |
| - _Note: see the documentation for the [specification][wiki-model-specification] of what's required from the model._ |
| 37 | +Most users should refer to our [Express](https://github.com/oauthjs/express-oauth-server/tree/master/examples) or [Koa](https://github.com/oauthjs/koa-oauth-server/tree/master/examples) examples. |
51 | 38 |
|
52 |
| -# Features |
| 39 | +Examples for v3 are yet to be made. Examples for v2 can still be found [here](https://github.com/oauthjs/node-oauth2-server/tree/b36a06b445ad0a676e6175d68a8bd0b2f3353dbf/examples). |
53 | 40 |
|
54 |
| - - Supports `authorization_code` (with scopes), `client_credentials`, `password`, `refresh_token` and custom `extension` grant types. |
55 |
| - - Can be used with _node-style_ callbacks, promises and ES6 _async_/_await_. |
56 |
| - - Fully [RFC6749](https://tools.ietf.org/html/rfc6749) and [RFC6750](https://tools.ietf.org/html/rfc6750) compliant. |
57 |
| - - Implicitly supports any form of storage e.g. _PostgreSQL_, _MySQL_, _Mongo_, _Redis_, _etc_. |
58 |
| - - Full test suite. |
| 41 | +[//]: # (If you're implementing a custom server, we have many examples available:) |
59 | 42 |
|
60 |
| -# Documentation |
| 43 | +[//]: # (- A simple **password** grant [example](https://github.com/oauthjs/node-oauth2-server/tree/master/examples/password).) |
| 44 | +[//]: # (- A more complex **password** and **refresh_token** grant [example](https://github.com/oauthjs/node-oauth2-server/tree/master/examples/refresh-token).) |
| 45 | +[//]: # (- An advanced **password**, **refresh_token** and **authorization_code** grant [example](https://github.com/oauthjs/node-oauth2-server/tree/master/examples/authorization-code) with scopes.) |
61 | 46 |
|
62 |
| - - [Server options][wiki-server-options] |
63 |
| - - [Model specification][wiki-model-specification] |
64 |
| - - [Authorization Code][wiki-model-specification] |
65 |
| - - [Client Credentials][wiki-model-specification] |
66 |
| - - [Password][wiki-model-specification] |
67 |
| - - [Refresh token][wiki-model-specification] |
68 |
| - - [Custom extension][wiki-model-specification] |
69 | 47 |
|
70 |
| -# Examples |
| 48 | +## Upgrading from 2.x |
71 | 49 |
|
72 |
| - Most users should refer to our [express](https://github.com/seegno/express-oauth-server/tree/master/examples) or [koa](https://github.com/thomseddon/koa-oauth-server/tree/master/examples) examples. If you're implementing a custom server, we have many examples available: |
| 50 | +This module has been rewritten using a promise-based approach, introducing changes to the API and model specification. |
73 | 51 |
|
74 |
| - - A simple **password** grant authorization [example](examples/password). |
75 |
| - - A more complex **password** and **refresh_token** [example](examples/refresh-token). |
76 |
| - - An advanced **password**, **refresh_token** and **authorization_code** (with scopes) [example](examples/authorization-code). |
| 52 | +Please refer to our [3.0 migration guide](https://github.com/oauthjs/node-oauth2-server/wiki/Migrating-from-2-x-to-3-x) for more information. |
77 | 53 |
|
78 |
| -# Upgrading from 2.x |
79 | 54 |
|
80 |
| - This module has been rewritten with a promise-based approach and introduced a few changes in the model specification. |
| 55 | +## Tests |
81 | 56 |
|
82 |
| - Please refer to our [3.0 migration guide][wiki-migrating-from-2x-to-3x] for more information. |
| 57 | +To run the test suite, install dependencies, then run `npm test`: |
83 | 58 |
|
84 |
| -## License |
| 59 | +```bash |
| 60 | +npm install |
| 61 | +npm test |
| 62 | +``` |
85 | 63 |
|
86 |
| - [MIT](LICENSE) |
87 | 64 |
|
88 |
| -<!--- badge links --> |
89 | 65 | [npm-image]: https://img.shields.io/npm/v/oauth2-server.svg
|
90 | 66 | [npm-url]: https://npmjs.org/package/oauth2-server
|
91 |
| -[travis-image]: https://img.shields.io/travis/oauthjs/node-oauth2-server/master.svg |
92 |
| -[travis-url]: https://travis-ci.org/oauthjs/node-oauth2-server |
93 | 67 | [downloads-image]: https://img.shields.io/npm/dm/oauth2-server.svg
|
94 | 68 | [downloads-url]: https://npmjs.org/package/oauth2-server
|
| 69 | +[travis-image]: https://img.shields.io/travis/oauthjs/node-oauth2-server/master.svg |
| 70 | +[travis-url]: https://travis-ci.org/oauthjs/node-oauth2-server |
| 71 | +[license-image]: https://img.shields.io/badge/license-MIT-blue.svg |
| 72 | +[license-url]: https://raw.githubusercontent.com/oauthjs/node-oauth2-server/master/LICENSE |
| 73 | +[slack-image]: https://img.shields.io/badge/slack-join-E01563.svg |
| 74 | +[slack-url]: https://oauthjs.slack.com |
95 | 75 |
|
96 |
| -<!--- wiki links --> |
97 |
| -[wiki-model-specification]: https://github.com/oauthjs/node-oauth2-server/wiki/Model-specification |
98 |
| -[wiki-migrating-from-2x-to-3x]: https://github.com/oauthjs/node-oauth2-server/wiki/Migrating-from-2-x-to-3-x |
99 |
| -[wiki-server-options]: https://github.com/oauthjs/node-oauth2-server/wiki/Server-options |
0 commit comments