Depracted
see: https://www.npmjs.com/package/@b-flower/bdn-oauth2-server
OAuth2 server installed quickly, used with express
Using oauth2orize & passport
//server sidevar express = ;var app = ;var oauth_server = ;var passport = ; //mimic mongoose db user collection - DO NOT USE ON PRODUCTIONvar users = ; //fake user creation'id' 'superuser' 'superpassword'; //mimic mongoose db token collection - DO NOT USE ON PRODUCTIONvar tokens = ; oauth_server;//could use dbClients// var clients = require('jab-oauth2-server/default_db_clients');// new clients('james', '007').save();// oauth_server.init({dbUsers: users, dbTokens: tokens, dbClients: clients}); app;app;app;oauth_server; app; //unprotected resourceapp; //protected resourceapp; app;
//client side - using request ;
//client side - with jQuery var bearer_token; //exchange token $; //... //access protected resource { $; }
Installation
$ npm install jab-oauth2-server
Implementation
The following methods MUST be implemented in your db models (see default_db_*.js)
db_client
- static : DBClients.findOneByClientId
- prototype: client.clientSecretCompare
db_user
-
static : findOneByUsername
-
static : findOneById
-
prototype: comparePassword
-
prototype: toObject
-
prototype: isActive
Optional method :
If implemented, refuse connection if !user.isActive()
db_tokens
- static : createByParams
- static : findOneByToken
More Information
Running Tests
To run the test suite first invoke the following command within the repo, installing the development dependencies:
$ npm install
then run the tests:
$ grunt test
License
(The MIT License)
Copyright (c) 2009-2012 A. Mélon <paztaga@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.