Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Password Flow init() method logs out on refresh #8347

Closed
mtozlu opened this issue Apr 2, 2021 · 4 comments
Closed

Password Flow init() method logs out on refresh #8347

mtozlu opened this issue Apr 2, 2021 · 4 comments

Comments

@mtozlu
Copy link
Contributor

mtozlu commented Apr 2, 2021

@mehmet-erim
There is a bug that logs out the user on page refresh using password flow authentication.

Steps to reproduce:
1- abp new pw-flow-init-test -csf -t app -ui angular -d mongodb --preview
2- Change env.ts to password flow: https://docs.abp.io/en/abp/4.3/UI/Angular/Authorization#resource-owner-password-flow
3- Run the projects
4- Go to http://localhost:4200/account/login (this is the key to bug: navigate to this url directly by clicking this link, do not go to login page by clicking "login" button on home page)
5- Login using admin user and default password.
6- Now that you are logged in and redirected to home page: refresh the page (using F5 or CTRL+R)
7- Observe that you are logged out after page refresh is finished.

I found that this is because rememberMe cookie is not set on direct navigation to /account/login so this condition returns true and password flow strategy's init method logs you out. The code is here:

if (!getCookieValueByName('rememberMe') && localStorage.getItem(this.storageKey)) {

Alternatively you can go to login page and make a refresh so that the first entrypoint to the app is the /account/login page. Now after you login, either you refresh the page or click a link to open in new tab (meaning a new init call will be made) and you will see that it logs you out.

I would like to create a PR however i couldn't see the reason of logging the user out when initializing the strategy. I thought there may be a reason which i'm not aware of. I think even if user didn't choose 'remember me', we should not logout the user on page initialization.

@mtozlu
Copy link
Contributor Author

mtozlu commented Apr 2, 2021

I solved this by adding;
this.setRememberMe(false);
just before the if conditional mentioned above. So now rememberMe cookie is initalized with a non-empty value. If condition doesn't return true on page refresh.
I don't know if initalizing rememberMe cookie with false value will have any side effects?

Also we can use this.cookieKey instead of the 'rememberMe' string literal on line 143.

@mehmet-erim
Copy link
Contributor

Hi,

We will fix the problem as soon as possible.
Thanks for the reporting.

@bnymncoskuner
Copy link
Contributor

bnymncoskuner commented Apr 14, 2021

Thank you for your findings @mtozlu It directed me into the source of the problem which is rememberMe cookie not being written with path=/. This results in that the cookie is written with path /account which cannot be reached from the root path. That's why if you refresh your application at root (localhost:4200), it logs you out since it cannot read the cookie.

You can see it here

@mtozlu
Copy link
Contributor Author

mtozlu commented Apr 14, 2021

Great find and fix. I tried to find the source of problem but i couldn't. Thanks for your efforts.

@mtozlu mtozlu closed this as completed Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants