Skip to content

Commit f1055a7

Browse files
authored
Merge pull request #54 from dirkcuys/master
Update postgres example
2 parents d498d2d + a5ac62a commit f1055a7

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

examples/postgresql/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
var bodyParser = require('body-parser');
77
var express = require('express');
8-
var oauthServer = require('oauth2-server');
8+
var oauthServer = require('express-oauth-server');
99
var render = require('co-views')('views');
1010
var util = require('util');
1111

@@ -74,7 +74,7 @@ app.post('/login', function(req, res) {
7474
});
7575

7676
// Get secret.
77-
app.get('/secret', app.oauth.authorize(), function(req, res) {
77+
app.get('/secret', app.oauth.authenticate(), function(req, res) {
7878
// Will require a valid access_token.
7979
res.send('Secret area');
8080
});

examples/postgresql/model.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ module.exports.getAccessToken = function(bearerToken) {
1616

1717
return {
1818
accessToken: token.access_token,
19-
clientId: token.client_id,
19+
client: {id: token.client_id},
2020
expires: token.expires,
21-
userId: token.userId
21+
user: {id: token.userId}, // could be any object
2222
};
2323
});
2424
};
@@ -38,7 +38,8 @@ module.exports.getClient = function *(clientId, clientSecret) {
3838

3939
return {
4040
clientId: oAuthClient.client_id,
41-
clientSecret: oAuthClient.client_secret
41+
clientSecret: oAuthClient.client_secret,
42+
grants: ['password'], // the list of OAuth2 grant types that should be allowed
4243
};
4344
});
4445
};
@@ -78,6 +79,6 @@ module.exports.saveAccessToken = function *(token, client, user) {
7879
token.refreshTokenExpiresOn,
7980
user.id
8081
]).then(function(result) {
81-
return result.rowCount ? result.rows[0] : false;
82+
return result.rowCount ? result.rows[0] : false; // TODO return object with client: {id: clientId} and user: {id: userId} defined
8283
});
8384
};

0 commit comments

Comments
 (0)