gardner / react-oauth2-pkce

React auth provider that works with AWS cognito PKCE🛡️🔒
49 stars 57 forks source link

Random # in code variable on initial authentication #36

Open Gambitboy opened 2 years ago

Gambitboy commented 2 years ago

Hi, I'm using your package and noticed something weird. It might be an issue I'm producing somewhere but I've not yet been able to find it and was wondering if I'd pick someone's brain about it.

How I'm using your package is I have a RubyOnRails backend which is setup with omniauth to azure. From my React frontend, I use this package to authenticate with azure through my backend. But I'm getting a weird bug on the first clean login.

If I login when my azure is logged out it will open the azure page and I will go through my login process. When it comes to the part where my server sends a redirect with the code to my frontend I see that happening with the correct code. But when it hits the part of your code where you decode the location to pull the query params, there is a random '#' at the end of the code which causes my login to fail. But if I then click login again and now azure is already logged, no hash tag is generated at the end of the code and it works.

I know the hashtag is meant to navigate the page to a specific part of the page, but not sure at which point this is happening.

I've tried to debug in your code but it seems to be coming directly from window.location. Any ideas? At the moment I injected a small bit of code change to fix it temporarily, return decodeURIComponent(value.replace('#', '') || '');