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

Authentication fixes #92

Merged
merged 2 commits into from
Oct 20, 2021
Merged

Authentication fixes #92

merged 2 commits into from
Oct 20, 2021

Conversation

javfg
Copy link
Contributor

@javfg javfg commented Oct 15, 2021

Hi ownClouders! 👋

While working in integrating ownCloud in Indico via the file-picker, I found some problems with the authentication.

Everything was working fine as long as the access token was kept valid. But if I let the token expire and then tried to open the file-picker again, it froze in the loading spinner. Turns out it was not trying to issue a renewal after loading the user, and so, no valid token is available to authenticate.

To solve this, I added an expiry check and token renewal when the user is loaded.

While at it, I also moved the token storage to localStorage instead of sessionStorage. This enables persistence even if the user closes the browser. To mitigate possible stale tokens, I increased the frequency of stale entry cleanup (whenever an error occurs).

Let me know if you see any problems in that. Also, feel free to ask me to split the PR if you think it's worth it.

Cheers!

* Use constant for storage field prefix
* Use localStorage instead of sessionStorage so the token is persisted
  through browser sessions
* Clean stale state entries more often
* Perform silent renew if the token is already expired on user load
Comment on lines +90 to +99
mgr.signinSilent().then((_, reject) => {
if (reject) {
mgr.clearStaleState(store, 0)
return null
}
return user.access_token
})
} else {
return user.access_token
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, let me know if you want me to switch this to use await.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be nice 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind this would require a couple more functions to become async, including initApp, are you sure the added complexity is worth it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably something for a different PR 😅

@pascalwengerter
Copy link
Contributor

Thanks for taking care! Please also add a changelog item in changelog/unreleased/ :)

@kulmann kulmann merged commit 7df5438 into owncloud:master Oct 20, 2021
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 this pull request may close these issues.

3 participants