Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Added an extra event for folks who want to save the access tokens in their database (bis) #10

wants to merge 3 commits into from

3 participants

Luc Castera Tim Oxley Amir Malik
Luc Castera

Ignore previous pull request as it still had querystring in package.json from previous pull request.

Amir Malik ammmir closed this pull request from a commit
Amir Malik Add save_access_token event to allow saving the access token.
For some reason, people might want to save the generated access token in
a database, so the save_access_token event is now emitted. It is

Closes #10
Amir Malik ammmir closed this in 7acc5ed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 2, 2012
  1. Luc Castera
  2. Luc Castera

    Added an event called 'save_access_token' in case one wants to save t…

    dambalah authored
    …he access_tokens somewhere in his implementation
  3. Luc Castera
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 1 deletion.
  1. +11 −0 examples/simple.js
  2. +3 −1 index.js
11 examples/simple.js
@@ -12,6 +12,9 @@ var myClients = {
// temporary grant storage
var myGrants = {};
+// temporary token storage
+var myTokens = {};
var myOAP = new OAuth2Provider('encryption secret', 'signing secret');
// before showing authorization page, make sure the user is logged in
@@ -67,6 +70,14 @@ myOAP.on('create_access_token', function(user_id, client_id, next) {
+// if you want to keep track of your access tokens, you can save them somewhere here
+myOAP.on('save_access_token', function(user_id, client_id, token) {
+ tokens[token] = {
+ user_id: user_id,
+ client_id: client_id
+ }
// an access token was received in a URL query string parameter or HTTP header
myOAP.on('access_token', function(req, token, next) {
var TOKEN_TTL = 10 * 60 * 1000; // 10 minutes
4 index.js
@@ -161,7 +161,9 @@ OAuth2Provider.prototype.oauth = function() {
res.writeHead(200, {'Content-type': 'application/json'});
self.emit('create_access_token', user_id, client_id, function(extra_data) {
- res.end(JSON.stringify(self.generateAccessToken(user_id, client_id, extra_data)));
+ var token = self.generateAccessToken(user_id, client_id, extra_data);
+ self.emit('save_access_token', user_id, client_id, token);
+ res.end(JSON.stringify(token));
self.emit('remove_grant', user_id, client_id, code);
Something went wrong with that request. Please try again.