Skip to content

Sliding expiration of access token #257

@bajtos

Description

@bajtos

It should be possible to configure LoopBack application in such way that the access token expires after a certain time of inactivity. The current implementation supports only the expiration after a fixed time since login.

See strongloop/loopback-sdk-angular#39 for a possible solution:

// ...
app.use(loopback.token({/* config */});
app.use(function(req, res, next) {
  var token = req.accessToken;
  if (!token) return next();

  var now = new Date();

  // performance optimization:
  // do not update the token more often than once per second
  if (now.getTime() - token.created.getTime() < 1000) return;

  // update the token and save the changes
  req.accessToken.created = now;
  req.accessToken.ttl = 60; /* session timeout in seconds */
  req.accessToken.save(next);
});
// register other middleware, etc.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions