|
| 1 | +# loopback-component-oauth2 |
| 2 | + |
| 3 | +The LoopBack oAuth 2.0 component provides full integration between [OAuth 2.0](http://tools.ietf.org/html/rfc6749) |
| 4 | +and [LoopBack](http://loopback.io). It enables LoopBack applications to function |
| 5 | +as an oAuth 2.0 provider to authenticate and authorize client applications and/or |
| 6 | +resource owners (i.e. users) to access protected API endpoints. |
| 7 | + |
| 8 | +The oAuth 2.0 protocol implementation is based on [oauth2orize](https://github.com/jaredhanson/oauth2orize) |
| 9 | +and [passport](http://passportjs.org/). |
| 10 | + |
| 11 | +See [LoopBack Documentation - OAuth 2.0 Component](http://loopback.io/doc/en/lb2/OAuth-2.0.html) for more information. |
| 12 | + |
| 13 | +## Install |
| 14 | + |
| 15 | +Install the component as usual: |
| 16 | + |
| 17 | +``` |
| 18 | +$ npm install loopback-component-oauth2 |
| 19 | +``` |
| 20 | + |
| 21 | +## Use |
| 22 | + |
| 23 | +Use in an application as follows: |
| 24 | + |
| 25 | +```js |
| 26 | +var oauth2 = require('loopback-component-oauth2'); |
| 27 | + |
| 28 | +var options = { |
| 29 | + dataSource: app.dataSources.db, // Data source for oAuth2 metadata persistence |
| 30 | + loginPage: '/login', // The login page url |
| 31 | + loginPath: '/login' // The login form processing url |
| 32 | +}; |
| 33 | + |
| 34 | +oauth2.oAuth2Provider( |
| 35 | + app, // The app instance |
| 36 | + options // The options |
| 37 | +); |
| 38 | +``` |
| 39 | + |
| 40 | +The app instance will be used to set up middleware and routes. The data source |
| 41 | +provides persistence for the oAuth 2.0 metadata models. |
| 42 | + |
| 43 | +For more information, see [OAuth 2.0](http://loopback.io/doc/en/lb2/OAuth-2.0.html) LoopBack component official documentation. |
| 44 | + |
| 45 | +## Example |
| 46 | + |
| 47 | +This [example](https://github.com/strongloop/strong-gateway) demonstrates |
| 48 | +how to implement an OAuth service provider, complete with protected API access. |
0 commit comments