0

I am implementing google login on my site.
Problem is that when google redirect me back to my site (after confirmation) I can't get access token from query string.
This is URL:

http://localhost/mysite/west/Default.aspx#state=/profile&access_token=ya29.qQDrtcVtgOEbS86Bg10puFG3dksJz74BlrEGulHldlJW2o5qQ6g7ilF17zQsm8iMLG0C82PQyp2Z-g&token_type=Bearer&expires_in=3600

I suspect that this #state=/profile make some issue but can't handle it.
Am I missing something?

1110
  • 7,829
  • 55
  • 176
  • 334

2 Answers2

1

You could use

document.URL to get the url.

Then split the url by #state=/profile&

Then the second part of the array split by &.

Then each section split by first =

There may be a more elegant solution but this should work.

stf
  • 31
  • 2
1

If URL is like this , note that there is # after Default.aspx , it is not ?, then there is no direct way to get get querystring ( they are known as URL fragments not querystring), they are meant to be parse at client side and server side don't have access to URL Fragments.

http://localhost/mysite/west/Default.aspx#state=/profile&access_token=ya29.qQDrtcVtgOEbS86Bg10puFG3dksJz74BlrEGulHldlJW2o5qQ6g7ilF17zQsm8iMLG0C82PQyp2Z-g&token_type=Bearer&expires_in=3600

Link contains # ,means an anchor, a position, on a webpage. The browser sends a GET request to the server containing only the address of the entire page, with no anchor, fragment or whatever. When the server returns the page, the browser knows where to position it so the location of the anchor is visible. In clientside or Javascript it is possible as it has access to the anchor.

Read this - How to get Url Hash (#) from server side

Community
  • 1
  • 1
Arindam Nayak
  • 7,346
  • 4
  • 32
  • 48
  • I inspect url in javascript and if it contains # I remove it and submit form via js again and then I can get querystring. So i did find workaround but why google rerurn me url like this? Do I have to make this double dorm submita? – 1110 Oct 26 '14 at 09:44
  • @1110 ,yes you are right, you have to do double post , to get querystring, ( which were `url fragments` ). You need to check with `Google` , may be there you have some setup that points to client side handling, and `Google` applied logic to send you as `URL fragments`, that will be helpful for clientside handling. – Arindam Nayak Oct 26 '14 at 09:46