-
-
Save frostbytten/1021439 to your computer and use it in GitHub Desktop.
| // Example taken from https://github.com/ciaranj/connect-auth/issues/45 | |
| var fbId= "xxxxxxxxxxxxx"; | |
| var fbSecret= "xxxxxxxxxxxxxx"; | |
| var fbCallbackAddress= "http://localhost:3000/auth/facebook_callback" | |
| var cookieSecret = "node"; // enter a random hash for security | |
| var express= require('express'); | |
| var auth = require('connect-auth') | |
| var app = express.createServer(); | |
| app.configure(function(){ | |
| app.use(express.bodyParser()); | |
| app.use(express.methodOverride()); | |
| app.use(express.cookieParser()); | |
| app.use(express.session({secret: cookieSecret})); | |
| app.use(auth([ | |
| auth.Facebook({ | |
| appId : fbId, | |
| appSecret: fbSecret, | |
| callback: fbCallbackAddress, | |
| scope: 'email', | |
| failedUri: '/noauth' | |
| }) | |
| ])); | |
| app.use(app.router); | |
| }); | |
| app.get('/auth/facebook', function(req, res) { | |
| req.authenticate("facebook", function(error, authenticated) { | |
| if (authenticated) { | |
| res.redirect("/great"); | |
| } | |
| }); | |
| }); | |
| app.get('/noauth', function(req, res) { | |
| console.log('Authentication Failed'); | |
| res.send('Authentication Failed'); | |
| }); | |
| app.get('/great', function( req, res) { | |
| res.send('Supercoolstuff'); | |
| }); | |
| app.listen(3000); |
I will check into this. Maybe OAuth library changed something. Which line is your res.redirect failing on?
I would believe it is on line 35. I simply am not redirected to "/great" but some facebook graph api url that displays the json error. Could the absolute URI specification has been implemented after this gist? Or maybe I have something not configured properly in my facebook app settings, but it does seem good.
Here is the url im redirected to: https://graph.facebook.com/oauth/authorize?redirect_uri=%2Flogin&scope=email&client_id=127045304052872&type=web_server
Hello, may I know if there's any updates to this gist?
I am receiving errors where no data is returned.
This was a proof-of-concept for a bug fix which has now been released. Please see the example application from https://github.com/ciaranj/connect-auth. Everything should be working according to the example middleware in the app.js
The exemple kinda lacks explanation. What does req.authenticate([req.param('method')] in the line req.authenticate([req.param('method')], function(error, authenticated) does? How do you configure properly? I read the facebook doc, but I still cant figure out how to get connect-auth working, authentication failed all the time...?
I tried this code, when I try to access "res.redirect("/myurl");" I keep getting the following error from facebook has a response in my browser:
{
"error": {
"type": "OAuthException",
"message": "redirect_uri isn't an absolute URI. Check RFC 3986."
}
}
The uri isnt absolute, the error makes sense, but why would it work in your code?
Thank you.