Skip to content

Commit

Permalink
Change signature of access_token event and return grant_date.
Browse files Browse the repository at this point in the history
Provide the access token grant date so implementations can decide when
to expire tokens if required.

Closes #5
  • Loading branch information
ammmir committed Dec 9, 2011
1 parent 189e344 commit 724bef4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 10 additions & 3 deletions examples/simple.js
Expand Up @@ -68,9 +68,16 @@ myOAP.on('create_access_token', function(user_id, client_id, next) {
});

// an access token was received in a URL query string parameter or HTTP header
myOAP.on('access_token', function(req, user_id, client_id, data, next) {
req.session.user = user_id;
req.session.data = data;
myOAP.on('access_token', function(req, token, next) {
var TOKEN_TTL = 10 * 60 * 1000; // 10 minutes

if(token.grant_date.getTime() + TOKEN_TTL > Date.now()) {
req.session.user = token.user_id;
req.session.data = token.extra_data;
} else {
console.warn('access token for user %s has expired', token.user_id);
}

next();
});

Expand Down
9 changes: 7 additions & 2 deletions index.js
Expand Up @@ -43,14 +43,19 @@ OAuth2Provider.prototype.login = function() {
data = self.serializer.parse(atok);
user_id = data[0];
client_id = data[1];
grant_date = data[2];
grant_date = new Date(data[2]);
extra_data = data[3];
} catch(e) {
res.writeHead(400);
return res.end(e.message);
}

self.emit('access_token', req, user_id, client_id, extra_data, next);
self.emit('access_token', req, {
user_id: user_id,
client_id: client_id,
extra_data: extra_data,
grant_date: grant_date
}, next);
};
};

Expand Down

0 comments on commit 724bef4

Please sign in to comment.