Repository navigation
Inspect tokens for external API clients - #1065
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Clarify CLI OAuth token inspection expiry Does GET /v2/access-token always include expires_at, and is it non-null for every access token issued to the Buildkite CLI OAuth application, including replacements issued by refresh? If the field can be absent or null, what does each case mean? A proposed bk auth token --json mode calls this endpoint through the CLI's existing renewal transport and returns the bearer token from the final response request with that response's expiry. A caller can use the timestamp to decide when to obtain another token. The Go SDK decodes both an absent field and null as nil, so the command cannot distinguish those cases. The REST documentation shows expires_at but does not define those cases 1. The device-authorization documentation says expires_in is present for applications with an expiry configured, including the lifetime used when refresh is enabled 2. The GraphQL APIAccessToken.expiresAt field defines null as no expiry 3. |
bk auth token reads the selected stored credential, or BUILDKITE_API_TOKEN when set, and prints it without making an API request. If the stored OAuth access token has expired, this command does not trigger renewal, so another API client receives the expired token. Add bk auth token --json to inspect the selected token through GET /v2/access-token, which returns details about the token used to authenticate the request [1]. The existing transport can renew stored OAuth credentials after a 401 and retry the inspection. The JSON output pairs the bearer token from the final response request with that response's expiry and the selected organization. Reading the token from that request keeps the values together if the shared token source changes while the response is pending. A successful inspection returns the token even when little lifetime remains. The result uses null when no expiry timestamp is available and does not classify the credential from that absence. The --timeout flag sets a 30-second default deadline for the inspection and any renewal requests; credential-store operations can outlast it. Raw bk auth token retains its current behavior. [1]: https://buildkite.com/docs/apis/rest-api/access-token
95e3ba8 to
8dd652e
Compare
|
@tamird thanks for this PR! To answer your follow-up questions, I checked the server implementation: |
|
Thanks for confirming the expiry behavior. Could you include this in the next CLI release? Our build client is ready to use it; v3.66.0 doesn't have |
|
@tamird yep, this has just been released in v3.67.0. |
bk auth token reads the selected stored credential, or BUILDKITE_API_TOKEN when set, and prints it without making an API request. If the stored OAuth access token has expired, this command does not trigger renewal, so another API client receives the expired token.
Add bk auth token --json to inspect the selected token through GET /v2/access-token, which returns details about the token used to authenticate the request 1. The existing transport can renew stored OAuth credentials after a 401 and retry the inspection. The JSON output pairs the bearer token from the final response request with that response's expiry and the selected organization. Reading the token from that request keeps the values together if the shared token source changes while the response is pending.
A successful inspection returns the token even when little lifetime remains. The result uses null when no expiry timestamp is available and does not classify the credential from that absence. The --timeout flag sets a 30-second default deadline for the inspection and any renewal requests; credential-store operations can outlast it. Raw bk auth token retains its current behavior.