-
Notifications
You must be signed in to change notification settings - Fork 44
Description
How to use GitHub
- Please use the 👍 reaction to show that you are affected by the same issue.
- Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
- Subscribe to receive notifications on status change and new comments.
Steps to reproduce
- Configure OIDC with refresh tokens to extend the session. Set a short access token validity to trigger the issue faster
- Login with OIDC and leave a tab open with the Nextcloud web UI
- After some time of inactivity return to the tab and try to browse around.
Expected behaviour
The session should continue uninterrupted
Actual behaviour
After the access token is expired, any access of Nextcloud in an already open tab will cause a logout event.
Diggin into the logs it appears to be because a request is sent to /ocs/v2.php/apps/notifications/api/v2/notifications and slightly later /ocs/v2.php/apps/user_status/api/v1/heartbeat?format=json. This causes both of these to run in parallel, and the first request will use the stored refresh token to refresh the session, then the second request will attempt to refresh the session. This causes a failure since it appears to use the refresh token that was read before the other request used it, so it's now expired.
Not sure what the best solution here is but it would seem that either some database locking would be needed to ensure that the token is not modified by parallel requests.
Nextcloud log
2025-08-17 00:22:35.577 user=-- url=/ocs/v2.php/apps/user_status/api/v1/heartbeat?format=json message=[TokenService] reauthenticate
2025-08-17 00:22:35.577 user=albgus url=/ocs/v2.php/apps/user_status/api/v1/heartbeat?format=json message=[TokenService] checkLoginToken: token is still expired -> reauthenticate
2025-08-17 00:22:35.577 user=albgus url=/ocs/v2.php/apps/user_status/api/v1/heartbeat?format=json message=[TokenService] Failed to refresh token
2025-08-17 00:22:35.577 user=albgus url=/ocs/v2.php/apps/notifications/api/v2/notifications message=[TokenService] Store token in the session
2025-08-17 00:22:35.577 user=albgus url=/ocs/v2.php/apps/notifications/api/v2/notifications message=[TokenService] ---- Refresh token success
2025-08-17 00:22:35.577 user=albgus url=/ocs/v2.php/apps/notifications/api/v2/notifications message=[TokenService] Token refresh request params
2025-08-17 00:22:35.577 user=albgus url=/ocs/v2.php/apps/user_status/api/v1/heartbeat?format=json message=[TokenService] Refreshing the token: https://login.example.com/application/o/token/
2025-08-17 00:22:35.576 user=albgus url=/ocs/v2.php/apps/user_status/api/v1/heartbeat?format=json message=[TokenService] getToken: token is expired and refresh token is still valid, refresh expires in 0
2025-08-17 00:22:35.576 user=albgus url=/ocs/v2.php/apps/user_status/api/v1/heartbeat?format=json message=[TokenService] Get token from the session
2025-08-17 00:22:35.576 user=albgus url=/ocs/v2.php/apps/notifications/api/v2/notifications message=[TokenService] Refreshing the token: https://login.example.com/application/o/token/
2025-08-17 00:22:35.576 user=albgus url=/ocs/v2.php/apps/notifications/api/v2/notifications message=[TokenService] getToken: token is expired and refresh token is still valid, refresh expires in 0
2025-08-17 00:22:35.576 user=albgus url=/ocs/v2.php/apps/notifications/api/v2/notifications message=[TokenService] Get token from the session
Error response from the token service
Client error: `POST https://login.example.com/application/o/token/` resulted in a `400 Bad Request` response:
{"error": "invalid_grant", "error_description": "The provided authorization grant or refresh token is invalid, expired, (truncated...)
Server configuration
Web server: Nginx
Database: PostgreSQL
PHP version: 8.1/8.2/8.3
Nextcloud version: 31.0.8.1
List of activated apps
If you have access to your command line run e.g.:
sudo -u www-data php occ app:list
from within your Nextcloud installation folder
Nextcloud configuration
If you have access to your command line run e.g.:
sudo -u www-data php occ config:list system
from within your Nextcloud installation folder
Browser
Browser name: Edge
Browser version: 139.0.3405.86
Operating system: Windows 11