Skip to content
Browse files

Change signature of access_token event and return grant_date.

Provide the access token grant date so implementations can decide when
to expire tokens if required.

Closes #5
  • Loading branch information...
1 parent 189e344 commit 724bef4fe3d9c83558bd1b03d3ddc02595c0034a @ammmir committed Dec 9, 2011
Showing with 17 additions and 5 deletions.
  1. +10 −3 examples/simple.js
  2. +7 −2 index.js
View
13 examples/simple.js
@@ -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();
});
View
9 index.js
@@ -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);
};
};

0 comments on commit 724bef4

Please sign in to comment.
Something went wrong with that request. Please try again.