larksuite / larksuite/node-sdk
UserAccessToken.get ignores a custom namespace when persisting refreshed tokens
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 294
- Forks
- 54
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 4
Description
Summary
UserAccessToken.get(key, { namespace }) reads an expired token from the requested namespace, but a successful refresh is written back without that namespace. The refreshed token therefore lands under the app-ID namespace while the requested namespace remains expired.
Affected version
@larksuiteoapi/node-sdk1.73.0mainatf54b49f3566c52b54c598194b7ed3015e3e24224
Reproduction
- Initialize an expired entry for
user-1under a custom namespace, for exampletenant-a. - Mock
authen.oidcRefreshAccessToken.createto return a successful refreshed access token. - Call
client.userAccessToken.get('user-1', { namespace: 'tenant-a' })twice.
The first call returns the refreshed token, but the second call refreshes again. Inspecting the cache shows the refreshed entry under the default app-ID namespace, while the tenant-a entry is still expired.
In a local memory-cache reproduction, two consecutive reads produced two refresh requests (new-1, then new-2) and the default namespace contained new-2.
Expected behavior
The successful refresh should update the same cache namespace from which the token was read. A second read from that namespace should use the refreshed cached token.
Actual behavior
Both successful update paths in client/user-access-token.ts call this.update(...) without forwarding options?.namespace. update consequently falls back to this.client.appId.
This is distinct from #103: that issue fixed a literal key property by changing it to [key]; the custom namespace is still dropped.
Impact
Applications that isolate user tokens with custom namespaces repeatedly call the OAuth refresh endpoint and retain stale entries in the intended namespace. The unexpected write to the app namespace can also break cache isolation assumptions.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in client/user-access-token.ts and trace UserAccessToken.get and its two successful refresh update paths, paying attention to the namespace option. Reproduce the issue with a custom namespace and consecutive reads using the described mock, then verify that the refreshed token is reused from that namespace and no longer triggers another refresh.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, typescript
- Domain
- authentication, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 85/100