Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oauth callback comes with empty object {} #26

Closed
ijxsid opened this issue Jul 26, 2015 · 3 comments
Closed

Oauth callback comes with empty object {} #26

ijxsid opened this issue Jul 26, 2015 · 3 comments

Comments

@ijxsid
Copy link

ijxsid commented Jul 26, 2015

I am a bit new to Hapi, and may be its just a config issue but I am not able to set up google auth in my service with grant.

Config

var grantconfig = {
  'server': {
    'protocol': 'http',
    'host': 'localhost:3333',
    'callback': '/callback',
    'transport': 'session',
    'state': true
  },
  'google': {
    'key': GOOGLE_CLIENT_ID,
    'secret': GOOGLE_CLIENT_SECRET,
    'scope': ['email', 'profile' ],
    'state': 'secret122',
    'callback': '/handle_google_callback'
  },
};

Server.js

var Hapi = require('hapi');
var Good = require('good');
var Path = require('path');
var yar = require('yar');
var grantconfig = require('./grantconfig');
var Grant = require('grant-hapi');
var grant = new Grant();
var server = new Hapi.Server();


server.connection({
  host: 'localhost',
  port: 3333
});


server.route({
  method: 'GET',
  path: '/handle_google_callback',
  handler: function (request, reply) {

    reply(JSON.stringify(request.query));
  }
});


server.register([
  {
    register: grant,
    options: grantconfig
  },
  {
    register: yar,
    options: {cookieOptions: {password: 'grant', isSecure: false}} 
  },
  {
    register: Good,
    options: {
      reporters: [{
        reporter: require('good-console'),
        events: {
          response: '*',
          log: '*'
        }
      }]
    }
  }  
], function(err){
  if(err){
    throw err; // something bad happened loading the plugin.
  }


  server.start(function(){
    console.log('Server running at:', server.info.uri);
  });
});

And This is response in the server.

150726/185255.451, [response], http://localhost:3333: get /connect/google/callback {"code":"5d09c0185472d78fa55a","state":"secret122"} 302 (1733ms) 
150726/185257.188, [response], http://localhost:3333: get /handle_google_callback {} 200 (2ms) 

As you can see, /handle_google_callback is not getting anything in response.
Can you please spot the issue?

@ijxsid
Copy link
Author

ijxsid commented Jul 26, 2015

But the thing is the /connect/google/callback is getting data and /handle_google_callback is not getting the data is little wierd.

@ijxsid
Copy link
Author

ijxsid commented Jul 26, 2015

Oh. I Got it. It was silly,

I was using "transport": "session" in my grantconfig, but I was checking for access_token in queryString.

So TIL,
If "transport" : "session" , then access_token is availale in request.session,
and if "transport": "queryString", then access_token is available in request.query.

@ijxsid ijxsid closed this as completed Jul 26, 2015
@simov
Copy link
Owner

simov commented Jul 26, 2015

Yes, I'm mentioning that in the Response Data section. Using session is generally better because the credentials are not printed in the server's logs that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants