1

I try to parse an URL with a special character returned by AWS Cognito during an auth process.

I can't find a way to retrieve the 'id_token' parameter because NodeJs req doesn't seem to include everything that's after the #

I've tried to use req.query, req.originaURl, all sorts. I may be missing something

Here is the returned link http://localhost:8080/auth#id_token=eyJraWQiOiERubiJ5AwdK9Rzau6BX0lYLQCvFDoGv1boLMnKnRexpires_in=3600&token_type=Bearer

The expected result should return the value of #id_token

3 Answers3

2

The # symbol in an URL is the fragment identifier and it doesn't get transmitted to the server.

Read More about it here

Shivam
  • 3,514
  • 2
  • 13
  • 27
  • Thanks, makes sense. I also found a good answer to my problem here https://stackoverflow.com/questions/17744003/get-url-after-in-express-js-middleware-request/43280710#43280710 – Soufian Aboulfaouz Oct 12 '19 at 04:25
2

The # is only accessible on the client side, so you need to create a request and send the token to the server, e.g:

var tokenParams = window.location.hash.substr(1);
Qiniso
  • 2,587
  • 1
  • 24
  • 30
1

Without seeing your code it's tough to help. Also, without being able to see what's returned from that URL it's tough to test for you.

URL characters included in the value assigned to the hash property are precent-encoded. Take a look at the Node.js documentation for url.hash, which can be used to get and set the fragment portion of the URL.

I believe that should help.

Go to https://nodejs.org/api/url.html and search url.hash.

paoiherpoais
  • 334
  • 1
  • 10