0

I have a scenario where I need to read tokens from URL which are appended after a hash. I am using express 4.

Eg URL: http://localhost:3000/callback#access_token=1234-5678-90AB&token_type=bearer&expires_in=100

Can anybody help me to extract the values of access_token, token_type and expires_in.

Ashish Santikari
  • 443
  • 4
  • 19
  • 2
    A fragment identifier (everything after the `#`) is not passed to the server and is intended to be handled client-side only (if at all). – robertklep Sep 18 '17 at 17:38
  • So it means, this can't be handled using server-side code aka express? – Ashish Santikari Sep 19 '17 at 04:55
  • The `#` and everything following it won't even _reach_ the server (the server gets a request for `/callback`). – robertklep Sep 19 '17 at 05:46
  • When I use `app.get('/callback', (req,res){ })` or `app.get(/callback/, (req,res){})`, express is not able to accept the url. How to i capture the url in some specific route? – Ashish Santikari Sep 19 '17 at 07:10
  • It should trigger on `app.get('/callback', ...)`. – robertklep Sep 19 '17 at 07:29
  • Its working now. I was getting https url so I had to change my server config to run on https. – Ashish Santikari Sep 19 '17 at 09:43
  • I'm not sure the client has been properly identified. In the case of the OIDC request example above, the express app likely does a redirect to the OIDC server specifying a callback. The callback would be a route in the express app. In that case, the express app *is* the client. There should be a way to get the values passed back as it is indeed going back to the node app and not the original browser. – Woodsman Dec 21 '20 at 02:54

1 Answers1

1

Working: passed on the request to client and handled the fragmented url in client(Angular).

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Ashish Santikari
  • 443
  • 4
  • 19