The LoopBack oAuth 2.0 component provides full integration between OAuth 2.0 and LoopBack. It enables LoopBack applications to function as an oAuth 2.0 provider to authenticate and authorize client applications and/or resource owners (i.e. users) to access protected API endpoints.
The oAuth 2.0 protocol implementation is based on oauth2orize and passport.
See LoopBack Documentation - OAuth 2.0 Component for more information.
Install the component as usual:
$ npm install loopback-component-oauth2
Use in an application as follows:
varoauth2=require('loopback-component-oauth2');varoptions={dataSource: app.dataSources.db,// Data source for oAuth2 metadata persistenceloginPage: '/login',// The login page urlloginPath: '/login'// The login form processing url};oauth2.oAuth2Provider(app,// The app instanceoptions// The options);The app instance will be used to set up middleware and routes. The data source provides persistence for the oAuth 2.0 metadata models.
For more information, see OAuth 2.0 LoopBack component official documentation.
This example demonstrates how to implement an OAuth service provider, complete with protected API access.