Skip to content

POST /v1/users/me/access-tokens returns a zero-byte 401, indistinguishable from sending no credential #1057

Description

@sergeiest

Summary

POST /v1/users/me/access-tokens rejects with an empty body and no JSON error envelope. A bogus rt_, and no Authorization header at all, produce byte-identical responses (HTTP 401, 0 bytes). Every other route in the API returns the standard envelope.

The result: an integrator cannot distinguish "my refresh token is invalid" from "this route is broken."

Repro

# bogus refresh token
curl -sS -o /dev/null -w '%{http_code} bytes=%{size_download}\n' \
  -X POST https://cloud-api.near.ai/v1/users/me/access-tokens \
  -H 'Authorization: Bearer rt_bogus000000000000'
# -> 401 bytes=0

# no Authorization header at all
curl -sS -o /dev/null -w '%{http_code} bytes=%{size_download}\n' \
  -X POST https://cloud-api.near.ai/v1/users/me/access-tokens
# -> 401 bytes=0   (identical)

Compare with any other route, which returns 102 bytes of {"error":{"message":"Invalid or expired access token","type":"unauthorized",...}}.

Why it matters

A customer team tried to mint an access token from outside the dashboard so a service could hold a long-lived credential. They tried rt_ in the Authorization header (as the reference specifies), in the body as refresh_token / token / refreshToken, and as a cookie — all empty 401s — and reasonably concluded the refresh flow was broken.

Because the response carries no diagnostic signal, we cannot tell from the outside whether their refresh token was ever valid. That turned a possibly-simple credential problem into an unresolvable one, and it is the last remaining path to a service-holdable usage credential (see linked issue).

Path inconsistency

access-tokens (hyphen) is the deployed route. access_tokens (underscore) appears in doc prose — including the Authorizations note on the endpoint's own reference page and on GET /v1/users/me ("Create via POST /users/me/access_tokens") — and returns 404:

curl -sS -o /dev/null -w '%{http_code}\n' -X POST \
  https://cloud-api.near.ai/v1/users/me/access_tokens \
  -H 'Authorization: Bearer rt_bogus000000000000'
# -> 404

Previously closed #104 used the underscore path, which may be worth a second look given the route has since been renamed.

Ask

  1. Return the standard JSON error envelope from this route.
  2. Distinguish a missing credential (401 + message) from an invalid/expired refresh token, so the flow is debuggable from the outside.
  3. Fix the access_tokens references in the spec descriptions.

Related: #1056 (no service-holdable credential can read usage; this route is the last remaining path to one).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions