Search code examples
pythondjangofacebookbotsfacebook-messenger

Messenger account linking authentication flow in Django


How can I complete the authentication flow of the account linking in Django?

I send the login template to user. When the user clicks on it, she is redirect to https://example.ngork.io/authenticate with the parameters account_linking_token and redirect_uri.

Now, when I perform the redirection I have this error:

Page not found (404)

Request URL: http://example.ngrok.io/[redirect_uri]

  1. ^admin/
  2. ^$ [name='index']
  3. ^messengerhook [name='messengerhook']
  4. ^authenticate [name='authenticate']

The current URL didn't march any of these.

EDIT:

the url of the server is generated by ngork since I run it in local.

https://a0505537.ngrok.io

The redirect uri is the one provided by facebook for linking account flow:

https://www.facebook.com/messenger_platform/account_linking
      ?account_linking_token=ACCOUNT_LINKING_TOKEN
      &authorization_code=AUTHORIZATION_CODE

About the views, in the question there are the urls written in my urls.py setting file.

Basically, the authenticate view is a login button and when the user is logged I run window.location.replace(["redirect_uri"])

RESOLVED:

The url wasn't decoded, so I add:

var url = decodeURIComponent(params["redirect_uri"]);

Solution

  • I resolved the issue. Details are in the question after the tag RESOLVED