@@ -30,7 +30,7 @@ oauth.initialize(config.key, config.secret);
30
30
/* Endpoints */
31
31
32
32
app . get ( '/oauth/token' , function ( req , res ) {
33
- var token = oauth . generateStateToken ( req ) ;
33
+ var token = oauth . generateStateToken ( req . session ) ;
34
34
35
35
res . json ( {
36
36
token : token
@@ -40,8 +40,10 @@ app.get('/oauth/token', function (req, res) {
40
40
41
41
app . post ( '/oauth/signin' , function ( req , res ) {
42
42
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 ) {
45
47
// Here the user is authenticated, and the access token
46
48
// for the requested provider is stored in the session.
47
49
// Continue the tutorial or checkout the step-4 to get
@@ -56,12 +58,15 @@ app.post('/oauth/signin', function (req, res) {
56
58
57
59
58
60
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.
61
63
// This retrieves a unified object representing the authenticated user.
62
64
// You could also use .get('/me') and map the results to fields usable from
63
65
// 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
+ } )
65
70
. then ( function ( user_data ) {
66
71
res . json ( user_data ) ;
67
72
} )
0 commit comments