decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

GitLab GraphQL requests do not refresh expired PKCE tokens

Open jackspiece opened this issue 4 months ago • 1 comments

Describe the bug

The PKCE refresh path added in #7854 only runs through API.requestFunction. With use_graphql: true, Apollo HTTP Link calls fetch directly. If the first API call after the OAuth access token expires is a GraphQL query, it fails with a 401 and the stored refresh token is never used.

GitLab documents invalid GraphQL authentication as an HTTP 401 with {"errors":[{"message":"Invalid token"}]}, while the current REST refresh path recognizes the OAuth {"error":"invalid_token"} shape.

I reproduced this on current main with a focused test. It returns a GraphQL 401 for Bearer EXPIRED_TOKEN, expects the request to refresh and retry with Bearer NEW_TOKEN, and currently fails on the first response with Network error: Response not successful: Received status code 401.

To Reproduce

  1. Configure the GitLab backend with PKCE and use_graphql: true.
  2. Sign in and let the two-hour OAuth access token expire.
  3. Make a collection request that uses the GraphQL path before any REST request refreshes the token.
  4. The request fails with a 401 instead of refreshing.

Expected behavior

GraphQL should use the same behavior as REST: refresh the PKCE token pair, persist the rotated credentials, and retry the failed request once. Concurrent failures should continue sharing the existing refresh promise.

Screenshots

Not applicable.

Applicable Versions:

  • Decap CMS version: current main at e50c1b16; the affected path is also present in releases containing #7854
  • Git provider: GitLab
  • OS: any
  • Browser version: any
  • Node.JS version: 22.22.1 for the regression test

CMS configuration

backend:
  name: gitlab
  auth_type: pkce
  app_id: your-app-id
  use_graphql: true

Additional context

GitLab GraphQL authentication docs: https://docs.gitlab.com/api/graphql/#authentication

The smallest fix I see is to route Apollo HTTP Link through the backend request function and recognize GitLab GraphQL invalid-token responses there. That would keep refresh coalescing and credential persistence in one place. I can send the regression test and patch if this direction looks right.

jackspiece avatar Jul 30 '26 10:07 jackspiece

Closing as resolved by #7932, merged on September 1. I checked that the merged change routes Apollo GraphQL requests through the existing refresh/retry path and includes the regression for an expired GraphQL token, rotated credentials, and retry with the new token. The fix is also present in current main at a35d0fd. The remaining GraphQL coverage work is tracked separately in #7975.

jackspiece avatar Sep 06 '26 18:09 jackspiece