I'm trying to develop a facebook connect with node and passport. But I'm having this error in my browser console:
Refused to display 'https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri=http%…te_event%2Cuser_birthday%2Cemail&client_id=632348833449996&type=web_server' in a frame because it set 'X-Frame-Options' to 'DENY'. about:blank:1
This is part of the code:
passport.use(new FacebookStrategy({
clientID: "XXX",
clientSecret: "XXX",
callbackURL: "`http://localhost:3000/auth/facebook/callback`"
},
function(accessToken, refreshToken, profile, done) {
var fullname = profile._json.first_name + ' ' + profile._json.last_name;
// Web services all for user persistence
}
));
// configure Express
app.configure(function() {
app.use(express.logger());
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.session({ secret: 'keyboard cat' }));
// Initialize Passport! Also use passport.session() middleware, to support
// persistent login sessions (recommended).
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
});
app.all('/auth/facebook', passport.authenticate('facebook', { scope: ['read_stream', 'publish_actions','user_interests','read_friendlists','create_event','user_birthday','email' ]}));
app.all('/auth/facebook/callback', passport.authenticate('facebook',{ successRedirect: '/',failureRedirect: '/login' }));
app.listen(3000);
On my facebook app configuration I've set the App On Facebook configuration with the following URL: http://localhost:3000/auth/facebook/
What I'm doing wrong?
Related
I can't data insert in the database showing this error "Proxy error: Could not proxy request /auth/login from localhost:3000 to http://127.0.0.1:8000 (ECONNREFUSED).". I have installed "http-proxy-middleware" in my client folder...
setUpProxy.js
const { createProxyMiddleware } = require("http-proxy-middleware");
module.exports = function (app) {
app.use(
createProxyMiddleware("/auth/register", { target: "http://127.0.0.1:8000/api" })
);
};
const express = require('express');
const app = express();
const nodemailer = require('nodemailer');
//Middleware
app.use(express.static('frontend'));
app.use(express.json());
app.get('/',(req,res)=>{
res.sendFile(__dirname + '/frontend/index.html');
});
app.post('/', (req,res)=>{
console.log(req.body);
const transporter1 = nodemailer.createTransport({
service:"gmail",
host: "smtp.gmail.com", // hostname
secure: false, // use SSL
port: 587, // port for secure SMTP
auth: {
user: "my email id",
pass: "mypassword"
},
tls: {
ciphers: "SSLv3",
rejectUnauthorized: false,
},
});
const mailOptions = {
from:req.body.email,
to: 'prahlad.hsrao#gmail.com',
cc: '24septanjali#gmail.com',
subject: 'Form Information',
text:"firstName: "+ req.body.fname+"\n" + "lastName"+req.body.lname+"email" + req.body.email+"phone"+req.body.phone+"message"+req.body.message,
}
transporter1.sendMail(mailOptions,(error,info)=>{
if(error){
console.log(error);
res.send('error');
transporter1.close();
}
else{
console.log('Email sent' + info.response);
res.send('success');
res.redirect('/');
transporter1.close();
}
})
})
app.listen(3000,()=>console.log('Server started...'));
firstly it was working perfectly, I send the email successfully 5-6 time, then while trying to send the mail, it is giving following error.
Error: Connection closed unexpectedly
at SMTPConnection._onClose (D:\official\SendEmailProject\nodeContactForm\node_modules\nodemailer\lib\smtp-connection\index.js:827:34)
at TLSSocket.SMTPConnection._onSocketClose (D:\official\SendEmailProject\nodeContactForm\node_modules\nodemailer\lib\smtp-connection\index.js:193:42)
at Object.onceWrapper (node:events:628:26)
at TLSSocket.emit (node:events:525:35)
at node:net:757:14
at TCP.done (node:_tls_wrap:584:7) {
code: 'ECONNECTION',
command: 'CONN'
I also got this error. After searching I guess it's a problem with the email server. I got about 5% of all my auto emails to fail. Maybe we can try to change one.
I'm currently working on my sessions for my app. Whenever i use the link
TAKE NOTE OF MY LINKS
as you can see on my localhost:3000/login after logging in my cookies and sessions are being set successfully.
This are my cookies after logging in successfully.
HOWEVER, when i wanted to access my app on the built server and after logging in.
My sessions are not able to persists on the cookies tab.
This is my code on setting the session for users
app.use(
cors({
// Change the origin to
// 192.168.254.100
//DEPENDS ON YOUR LOCAL NETWORK OR
// localhost
//origin: ["http://localhost:3000"],
origin: ["http://192.168.254.100:3000"],
methods: ["GET", "POST", "PUT", "DELETE"],
credentials: true,
optionSuccessStatus: 200,
})
);
app.use(
session({
key: "userId",
secret: "subscribe",
resave: false,
saveUninitialized: false,
cookie: {
maxAge: 24 * 60 * 60 * 1000,
},
})
);
this is my routes on setting the session:
app.get("/login", (req, res) => {
if (req.session.user) {
res.send({ loggedIn: true, user: req.session.user });
} else {
res.send({ loggedIn: false });
}
});
I am getting null sessionId in my expressjs application
here is app.js file
var session = require('express-session');
var app = express();
app.use(cookieParser());
app.use('/loginaction',loginaction);
//session handling
app.set('trust proxy', 1) // trust first proxy
app.use(session({
secret: 'hellokitty',
resave: false,
saveUninitialized: true,
cookie: { secure: true }
}));
In my loginaction.js file which is located in routes folder.
router.post('/', function(req, res, next) {
console.log("Session id"+req.sessionID);
//test session
req.session.test= 'something';
});
But i will get session id as undefined
also req.session.test through another error cannot resolved test
Your getting an unidentified on req.sessionid because you are never sending the sessionid to the client. You are requesting information the request doesn't have. Should try sending the sessionid in the initial login response. It should then remain persistent in the request after that (not sure on it's persistence tho, I use a different framework that keeps it persistent)
I am using express.js , express-mysql-session and passport.js. The express session middleware is creating session for the static file requests such as login page which is creating another entry in the session table.
I have moved the static middleware before the express session middleware. But when I make a login request after moving the static middleware before the session middleware the passport throws an error "passport.initialize middlware not in use".
I guessing that this might be happening because there is no "connect.sid" cookie in the request!
That's how my configure function looks like
app.configure(function () {
app.set('mode', process.argv[2] || 'local');
app.set('port', config.port || 8080);
app.use(express.favicon(__dirname + '/public/favicon.ico'));
app.use(express.logger('dev'));
app.use(express.methodOverride());
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.cookieParser());
app.use(express.json());
app.use(express.urlencoded());
// this is a route handler for serving public file incase user doesn't have session
app.get("/*", policies.publicRoute.handleRoute());
app.use(busboy({
limits: {
fileSize: maxFileSize,
files : 1
}
}));
//create session store
var sessionStore = new SessionStore({}, connection);
// required for passport
app.use(express.session({
secret: 'mySecret',
cookie: { maxAge : myNumber },
store: sessionStore,
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
});