Skip to content

Feature: Refresh access token before it times out #763

Closed as not planned
Closed as not planned

Description

@nicokaiser

Every few minutes there are log entries on the server:

{"level":"error","service":"proxy","error":"failed to verify access token: token has invalid claims: token is expired","authenticator":"oidc","path":"/graph/v1.0/me/drives","user_agent":"Mozilla/5.0 (Macintosh) mirall/3.0.3.2073 (OpenCloud, macos-25.1.0 ClientArchitecture: arm64 OsArchitecture: arm64)","client.address":"2001:0db8:...","network.peer.address":"","network.peer.port":"","time":"2025-12-15T20:50:29Z","message":"failed to authenticate the request"}

This is basically a mirror of opencloud-eu/opencloud#919 – but since this probably needs to also be addressed in the desktop client, I'll create this issue.

Like discussed in opencloud-eu/opencloud#919 (comment) the client knows the expiration time of the token at all times (except when tokens are revoked), so requests with an expired token can be avoided.

I do not know the architecture of the apps; however with JS OAuth clients, the token's expiration time (which is always sent along with the token as expires_in) can be checked whenever the token is used, and if necessary the token must be refreshed (the desktop and mobile app request offline_access scope and thus should have a refresh token) and the new token must be used instead. (Note: avoid race conditions where the token might be requested multiple times while it is being refreshed, these need to be synchronized and queued)

Activity

  1. TheOneRing commented on Dec 16, 2025

    @TheOneRing
    Contributor

    If not needed, I'd rather not change the client behaviour.
    And if the only problem is a long message...

  2. changed the title [-]Expired token is used[/-] [+]Feature: Refresh access token before it times out[/+] on Dec 16, 2025
  3. nicokaiser commented on Dec 16, 2025

    @nicokaiser
    Author

    My problem is not the log messages but rather many many unnecessary requests. And since the client already knows if a token is valid or not, it can refresh it right away instead of doing it after a 401.

  4. TheOneRing commented on Dec 16, 2025

    @TheOneRing
    Contributor

    Just increase the access token lifetime ;)

    I don't think the 401 request have a major impact. Changes to the authentication code often have unintended side effects.

  5. nicokaiser commented on Dec 28, 2025

    @nicokaiser
    Author

    I consider this to be a very questionable approach: I am aware that the expires_in date is optional in OAuth, but IMO if it is there, it should be tried to consider. Spamming the server (and logs) with unnecessary 401 requests is not very sustainable and makes finding real errors much harder.

    I am also aware that any changes to critical components like the auth code are risky... But on the other hand I'd really like to help fixing some obvious authentication problems in OpenCloud like this one, #767, and also issues like opencloud-eu/opencloud#1595 (and related) which cause usability problems.

  6. github-actions commented on Jan 28, 2026

    @github-actions

    This issue was marked stale because it has been open for 30 days with no activity. Remove the stale label or comment or this will be closed in 7 days.

  7. github-actions commented on Feb 4, 2026

    @github-actions

    The issue was marked as stale for 7 days and closed automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions