dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Dioxus router removes hash segments

Open ealmloff opened this issue 11 months ago • 3 comments

Problem

The dioxus router removes any hash segments when parsing the route.

Steps To Reproduce

Steps to reproduce the behavior:

  • Navigate to https://dioxuslabs.com/learn/0.4/getting_started#setup-guides
  • See the url change to https://dioxuslabs.com/learn/0.4/getting_started

Expected behavior

The hash segment should remain

Environment:

  • Dioxus version: master
  • Rust version: nightly
  • OS info: Linux
  • App platform: web

Questionnaire

  • [ ] I'm interested in fixing this myself but don't know where to start
  • [ ] I would like to fix and I have a solution
  • [ ] I don't have time to fix this right now, but maybe later

ealmloff avatar Feb 29 '24 23:02 ealmloff

URL fragments might have query-string format.

here is an example URL from google oauth docs -https://oauth2.example.com/callback#access_token=4/P7q7W91&token_type=Bearer&expires_in=3600 How this should be parsed?

I image route definition similar to this:

#[route("/callback#:fragment")]

and then fragment should be something that implements FromQuery? Right?

SET001 avatar Mar 01 '24 13:03 SET001

URL fragments might have query-string format.

here is an example URL from google oauth docs -https://oauth2.example.com/callback#access_token=4/P7q7W91&token_type=Bearer&expires_in=3600 How this should be parsed?

I image route definition similar to this:

#[route("/callback#:fragment")]

and then fragment should be something that implements FromQuery? Right?

That route definition looks correct. Fragments may look like a query, but we don't want to force them to look like a traditional query segment (name=bla&surname=bla). We can use a trait with an identical signature to FromQuery called FromFragment or just accept T: FromStr<Err = core::convert::Infallible> instead of FromQuery and FromFragment

ealmloff avatar Mar 01 '24 14:03 ealmloff

Just a note: this bug prevents the use of the OAuth2 Implicit Grant flow with some providers. That includes Google as @SET001 mentioned, and also AWS: https://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html.

Implicit grant flow returns tokens in the fragment; auth code flow returns them in the query string. I tried this workaround in the hope that the first render would take place before the fragment was removed by Dioxus, but no luck:

    use web_sys::window;
    let hash = window().unwrap().location().hash().unwrap();
    let params_parsed: HashMap<String, String> = serde_urlencoded::from_str(&hash).unwrap();

kalzoo avatar Mar 27 '24 06:03 kalzoo