Home Facebook manual authentication flow with Nodejs
Reply: 0

Facebook manual authentication flow with Nodejs

user1458 Published in July 18, 2018, 10:30 pm

I'm trying to manually implement an authentication flow via FB oauth. Here I call the authorization dialog:

<a href="https://www.facebook.com/dialog/oauth?
>Login FB</a>

Then it redirects back to my app server:


That calls the FB API graph to exchange the code for an access token

function exchangeCodeForAccessToken(code) {
    const options = {
      hostname: 'graph.facebook.com',
      path: 'v2.11/oauth/access_token?client_id=XXXXXXXXXXXXXXXXX&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Flogin%2Fcallback&client_secret=YYYYYYYYYYYYYYYYYYYY&code=' + code,
      method: 'GET'
    const req = https.request(options, (res2) => {
      console.log(`STATUS: ${res2.statusCode}`);
      res2.on('data', (d) => {

But here I always get a 400 with no other indication. No matter what I change. Any advice?

Thank you

edit. As suggested by CBroe I tried to execute the very same request from browser right after the node request (same url, same querystring, same code): node -> 400 browser -> 200 + AccessToken

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309538 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO