0

I made a project, but in it you need to get a special token from the VK social network. I made the token pass along with the link. She looks like this:

http://127.0.0.1:8000/vk/auth#access_token=7138dcd74f5da5e557943b955bbfbd9a62811da7874067e5fa0edef1ca8680216755be16&expires_in=86400&user_id=397697636

But the problem is that the django cannot see this link. I tried to look at it in a post request, get request, but everything is empty there. I tried to make it come not as a request but as a link, it is like this:

http://127.0.0.1:8000/vk/auth #access_token=7138dcd74f5da5e557943b955bbfbd9a62811da7874067e5fa0edef1ca8680216755be16&expires_in=86400&user_id=397697636

But the django does not want to read the space. Who can help

  • 1
    some code would help - but surely this is a query parameter, not a hash fragment, and therefore your `#` in the first URL should be a `?`? – Robin Zigmond Jun 08 '20 at 20:12
  • the server sends this fragment: #access_token=7138dcd74f5da5e557943b955bbfbd9a62811da7874067e5fa0edef1ca8680216755be16&expires_in=86400&user_id=397697636 at the end of the link that I indicate: http://127.0.0.1:8000/vk/auth –  Jun 08 '20 at 20:15
  • If it is, then this is a link to the page where it is described how to get a token: https://vk.com/dev/implicit_flow_user –  Jun 08 '20 at 20:25

1 Answers1

0

I think there is a confusion between a query string (get params) that follows a ? and a fragment (the text, that follows a #)

What follows the # is not sent to the server (and thus not received by Django) it is only useful to the web browser and to the javascript that is executed on the browser , which can use it to update parts of the screen. use it as virtual urls / bookmarks for one page web applications. The javascript can of course also trigger AJAX requests using that data, but that's up to the javascript

If you write however http://127.0.0.1:8000/vk/auth?access_token=7138dcd74f5da5e557943b955bbfbd9a62811da7874067e5fa0edef1ca8680216755be16&expires_in=86400&user_id=397697636 (you replace # with ?)

Then you can receive the information in your django view with

request.GET["access_token"], request.GET["expires_in"] and request.GET["user_id"]

If it is really a #, then your javascript should parse whatever follows the # and make the according AJAX requests to the server to send / validate the token.

For another question about fragments, refer for example to Is the URL fragment identifier sent to the server?

gelonida
  • 5,327
  • 2
  • 23
  • 41