olinapps

0.1.3 • Public • Published

node-olinapps

npm install olinapps

In the top of your file:

var olinapps = require('olinapps');

In your express app, right after your app.configure:

/**
 * Authentication
 */
 
app.post('/login', olinapps.login);
app.all('/logout', olinapps.logout);
app.all('/*', olinapps.middleware);
app.all('/api/*', olinapps.loginRequiredJSON); // (optional) login required, no redirect, returns 401
app.all('/*', olinapps.loginRequired);

Remove the loginRequired line if logging in is optional. Then in any route:

app.get('/', function (req, res) {
  var user = olinapps.user(req);
  console.log(user);
  // ...
})

Yields:

{ id: 'timothy.ryan',
  created: 1354933883,
  domain: 'students.olin.edu',
  username: 'timothy.ryan',
  email: 'timothy.ryan@students.olin.edu' }

Directory & Mailing Lists

You can request information from the Olin Directory or Mailing List APIs.

app.get('/me', function (req, res) {
  olinapps.directory.me(req, function (err, json) {
    res.json(json);
  });
});

app.get('/people', function (req, res) {
  olinapps.directory.people(req, function (err, json) {
    res.json(json);
  });
});

app.get('/list', function (req, res) {
  olinapps.lists.search(req, 'helpme', 'ride to eliot', function (err, messages) {
    res.json(messages);
  });
});

API

Session:

olinapps.user(req);
olinapps.sessionid(req);

Middleware:

olinapps.login
olinapps.logout
olinapps.middleware
olinapps.loginRequired
olinapps.loginRequiredJSON

APIs:

olinapps.directory.me(req, callback)
olinapps.directory.people(req, callback)

olinapps.lists.search(req, list_name, keywords, callback)

Example

See the source for quotes.olinapps.com for an example.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.3
    0
    • latest

Version History

Package Sidebar

Install

npm i olinapps

Weekly Downloads

0

Version

0.1.3

License

MIT

Last publish

Collaborators

  • tcr