Use Facebook account for login trouble

I added using facebook account as a login option.

A problem was that it opened a new browser window and asked me to close it. I do not want this popup window to destroy my UI consistence, how can I do it?

Another problem was to get the facebook user name and add it to my login collection in MongoDB, any solution?

Any sample code to use standard login and login by Facebook, Twitter, .etc. I found some code clips but no one can work right in production quality. (lack of error processing and exception, bad UI, …).