-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
OAuth 2 refresh tokens expire early #11919
Comments
Pinging @rullzer; first of all, from your point of view, is this intended? How long do you expect the refresh token to be valid? |
@Dagefoerde mmm yes I see it from looking at the code. I'll look into the issue. Refresh tokens actually should not expire. It think this is abug. Regarding the refresh token only being valid once. This is expected. |
Perfect, thanks.
Noo, I know! That's not the problem here. In these two attempts the refresh token was never valid. I was just trying to say that the first time there is a token but the check fails. So of course I didn't get a new refresh token here. It's just that the second time we end up in a different check, probably because the first time did some cleanup. I was just adding that because you can debug this only once (per grant) due to the cleanup stuff ;) |
Ah... stupid me replying to soon. 🤦♂️ I'll look into this and get back to you |
Aaah so I actually know what is going on here. The token is indeed expired. (Which makes sense). So it gets cleaned up by the cron job. But if the token is really gone our refresh mechanism can't do anything. Ok let me see how the logic should work here. |
Ah no so I did not have it correct... more digging it seems. |
Ok so it puzzles me a bit why this happens. @Dagefoerde could you enable xdebug on your test system?
That should log a stacktrace where that is called from. |
Hi, thanks for digging. I added it on the test system and will check later what will happen. What do you think how much time elapses until the token is invalid? I think I'll check in bit more than an hour or tomorrow. |
It should show up there yes. I actually don't know why the token gets removed. It should be marked as expired but not removed. |
Maybe here, right after it has been determined to be expired?
(dunno though. I haven't actually tried to figure it out yet.) |
Refresh token wasn't valid anymore, but your additional statement wasn't logged either. Just the following (which always came up before, too, so nothing new here.).
|
Yeah but it should not reach that. If that is reached the token is invalid anyway. Mmmm strange... I would need to dig deeper. I'll try to setup a test env this evneing to debug tomorrow. |
AAAAH! I think I got it! I'll prepare a patch in a little moment... |
Fixes #11919 Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
@Dagefoerde please tests #11964. Especially the first commit |
Yep, seems to resolve this issue. Thanks a lot for dealing with this! |
Fixes nextcloud#11919 Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Fixes #11919 Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Somehow, OAuth2 refresh tokens seem to expire. It's probably fine if they would in the long run, but this is happening within a few hours.
Steps to reproduce
Expected behaviour
Access tokens expire after an hour. In contrast, refresh tokens should be valid for a while; let's say for a week? I am happy to discuss this, though...
Actual behaviour
First of all, I changed
OauthApiController.php
and enumerated theinvalid_request
responses, i.e., the first occurrence isinvalid_request1
, the second isinvalid_request2
, and the third isinvalid_request3
.The response of
/index.php/apps/oauth2/api/v1/token
is a400
with the following content:Subsequent requests with the same refresh token result in
invalid_request1
. This implies that, the first time we end up here:server/apps/oauth2/lib/Controller/OauthApiController.php
Line 140 in a1ea504
Whereas, subsequently, we end up here:
server/apps/oauth2/lib/Controller/OauthApiController.php
Line 107 in a1ea504
Using mitmproxy, I was able to intercept this request:
Server configuration
Operating system:
Ubuntu 16.04.5 LTS
Web server:
Apache/2.4.18 (Ubuntu)
Database:
Postgres 9.5.14
PHP version:
7.0.32-0ubuntu0.16.04.1
Nextcloud version:
14.0.3.0
Updated from an older Nextcloud/ownCloud or fresh install: updated
Where did you install Nextcloud from: nextcloud.com
Are you using external storage, if yes which one: no
Are you using encryption: no
Logs
Nextcloud log (data/nextcloud.log)
Nextcloud log
The text was updated successfully, but these errors were encountered: