8000 Merge branch 'step-4-dev' into step-5-dev · sparkyfen/sdk-node-tutorial@000b02e · GitHub
[go: up one dir, main page]

Skip to content

Commit 000b02e

Browse files
committed
Merge branch 'step-4-dev' into step-5-dev
2 parents a4dd5be + a1250bb commit 000b02e

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

app.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ oauth.initialize(config.key, config.secret);
3030
/* Endpoints */
3131

3232
app.get('/oauth/token', function (req, res) {
33-
var token = oauth.generateStateToken(req);
33+
var token = oauth.generateStateToken(req.session);
3434

3535
res.json({
3636
token: token
@@ -40,8 +40,10 @@ app.get('/oauth/token', function (req, res) {
4040

4141
app.post('/oauth/signin', function (req, res) {
4242
var code = req.body.code;
43-
oauth.auth(code, req)
44-
.then(function (r) {
43+
oauth.auth('google', req.session, {
44+
code: code
45+
})
46+
.then(function (request_object) {
4547
// Here the user is authenticated, and the access token
4648
// for the requested provider is stored in the session.
4749
// Continue the tutorial or checkout the step-4 to get
@@ -56,12 +58,15 @@ app.post('/oauth/signin', function (req, res) {
5658

5759

5860
app.get('/me', function (req, res) {
59-
var request_object = oauth.create('facebook');
60-
// Here we perform a request using the .me() method.
61+
// Here we first build a request object from the session with the auth method.
62+
// Then we perform a request using the .me() method.
6163
// This retrieves a unified object representing the authenticated user.
6264
// You could also use .get('/me') and map the results to fields usable from
6365
// the front-end (which waits for the fields 'name', 'email' and 'avatar').
64-
request_object.me()
66+
OAuth.auth('google', req.session)
67+
.then(function (request_object) {
68+
return request_object.me();
69+
})
6570
.then(function (user_data) {
6671
res.json(user_data);
6772
})

0 commit comments

Comments
 (0)
0