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

Cookie doesn't get removed if using topLevelDomain #66

Open
louiszuckerman opened this issue Jul 26, 2017 · 2 comments · May be fixed by #67
Open

Cookie doesn't get removed if using topLevelDomain #66

louiszuckerman opened this issue Jul 26, 2017 · 2 comments · May be fixed by #67

Comments

@louiszuckerman
Copy link

louiszuckerman commented Jul 26, 2017

Looks like $cookies.remove() needs to be called with the domain when a domain is used on $cookies.put().

Using angular 1.5.11 and angular-jwt-auth 4.0.13.

Tested on chrome & firefox, latest versions, on MacOS Sierra.

After logging out the cookie hangs around until it expires. Even when logging in as a new user, the old cookie remains until it expires and gets refreshed.

louiszuckerman added a commit to louiszuckerman/angular-jwt-auth that referenced this issue Jul 26, 2017
add tests to fail removing cookie with domain
louiszuckerman added a commit to louiszuckerman/angular-jwt-auth that referenced this issue Jul 26, 2017
add code to properly remove cookie with domain, making tests pass
@louiszuckerman louiszuckerman linked a pull request Jul 26, 2017 that will close this issue
@louiszuckerman
Copy link
Author

louiszuckerman commented Jul 28, 2017

Found another issue with cookie management using top level domain: the cookie doesn't get refreshed.

When first saving the cookie, with top level domain, we try saving it with domain name parts, adding from right to left. So, the first attempt to save the cookie uses domain com, which fails the while condition, then another attempt is made with the next domain part, example.com, which succeeds because this matches the domain of the browser document. All is well so far.

The problem happens when we try to refresh the cookie. We go through the do block, but we try again with com in the cookie domain, so the browser refuses to save this cookie. Then we check to see if the cookie exists, by name only, which is true, because we saved a cookie before with the same name -- but this is not our new refreshed cookie.

As a result, a new cookie won't be stored until the existing cookie expires, when there's no longer a cookie by that name.

louiszuckerman added a commit to louiszuckerman/angular-jwt-auth that referenced this issue Jul 28, 2017
fix saving new cookie after token refresh
update readme
@louiszuckerman
Copy link
Author

louiszuckerman commented Jul 28, 2017

I added a commit to the PR to remember the discovered top level domain. One known limitation with this approach is that if the SPA is reloaded then the remembered value will be lost, and we won't be able to save the cookie until it expires, like before.

Considering a fix for this by checking if cookie is enabled && no cookie exists (by name) in the refresh timer check, if the condition is true then trigger a token refresh.

louiszuckerman added a commit to louiszuckerman/angular-jwt-auth that referenced this issue Jul 28, 2017
refresh token if cookie is enabled but missing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant