8000 Merge branch 'step-7-dev' into step-8-dev · sparkyfen/sdk-node-tutorial@fc97695 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc97695

Browse files
committed
Merge branch 'step-7-dev' into step-8-dev
2 parents ac3f82d + 6b30da6 commit fc97695

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
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
})

public/src/script.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ function retrieve_token(callback) {
1515
}
1616

1717
function authenticate(token, callback) {
18-
OAuth.popup('facebook', {
19-
state: token
18+
OAuth.popup('google', {
19+
state: token,
20+
// Google requires the following field
21+
// to get a refresh token
22+
authorize: {
23+
approval_prompt: 'force'
24+
}
2025
})
2126
.done(function(r) {
2227
$.ajax({

0 commit comments

Comments
 (0)
0