fix(confluence): support scoped API tokens via the api.atlassian.com gateway - #798
Open
hrabal-myo wants to merge 1 commit into
Open
fix(confluence): support scoped API tokens via the api.atlassian.com gateway#798hrabal-myo wants to merge 1 commit into
hrabal-myo wants to merge 1 commit into
Conversation
Scoped Atlassian API tokens only work against the https://api.atlassian.com/ex/confluence/<cloudId>/wiki gateway. Two places in mark break in that setup: 1. FindHomePage uses the v1 space endpoint, which answers 404 for scoped tokens (they lack classic scopes). Fall back to the v2 spaces API and resolve the homepage via its ID. 2. IsCloud() only recognizes *.jira.com and *.atlassian.net, so folder support is rejected as "not Cloud" even though the gateway always fronts a Cloud instance. Recognize api.atlassian.com. Fixes kovetskiy#341 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Confluence client to properly support Atlassian scoped API tokens by working with the api.atlassian.com gateway behavior: it adds a v2 API fallback for resolving a space homepage and broadens Cloud detection to accept the gateway host.
Changes:
- Add a fallback in
FindHomePagefrom the v1 space endpoint to the v2 spaces API and resolve the homepage viaGetPageByID. - Update
IsCloud()to recognizeapi.atlassian.comas a Cloud host (gateway for scoped tokens).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
237
to
+242
| request, err := api.rest.Res( | ||
| "space/"+space, &SpaceInfo{}, | ||
| ).Get(payload) | ||
| if err == nil && request.Raw.StatusCode == http.StatusOK { | ||
| return &request.Response.(*SpaceInfo).Homepage, nil | ||
| } |
Comment on lines
+244
to
+246
| // Confluence Cloud answers 404 on the v1 space endpoint for tokens | ||
| // without classic scopes; fall back to the v2 spaces API. | ||
| v2Result := struct { |
Comment on lines
+965
to
+967
| return strings.HasSuffix(host, "jira.com") || | ||
| strings.HasSuffix(host, "atlassian.net") || | ||
| host == "api.atlassian.com" |
SelfSimon
added a commit
to SelfSimon/netbox-mcp
that referenced
this pull request
Jul 19, 2026
mark's scoped-token/service-account support is stuck behind an unmerged, buggy PR (kovetskiy/mark#798) as of 2026-07-18, which would force paying for a full Atlassian user license. md2conf documents first-class support for the api.atlassian.com scoped-token gateway, so the Confluence bot can run on a free service account instead. OBJECT_COVERAGE.md's mark-style header comments are replaced with md2conf's HTML-comment front matter (title override + a confluence-sync marker the CI workflow greps for).
|
@hrabal-myo this PR seems 3 weeks old with suggestions from GH copilot on it. Do you mind if I take a stab at fixing it? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Atlassian's scoped API tokens only authenticate against the gateway URL
https://api.atlassian.com/ex/confluence/<cloudId>/wiki— used directly against<site>.atlassian.netthey are treated as anonymous. Running mark in that setup currently fails in two places:FindHomePagefails with 404 — the v1 endpointGET /rest/api/space/<key>answers 404 for scoped tokens (they lack the classic scopes), so every run aborts withcan't obtain home page from space(mark cli command showingcan't obtain home page from space TEST1#341 reports this symptom).IsCloud()only recognizes*.jira.com/*.atlassian.net, so with the gateway base URL mark refuses<!-- Folder: -->even though the gateway always fronts a Cloud instance.Fix
FindHomePage: keep the v1 call, but on a non-OK response fall back to the v2 spaces API (GET /api/v2/spaces?keys=<key>) and resolve the homepage viaGetPageByID. Behaviour for classic tokens / Server is unchanged (v1 still wins when it works).IsCloud(): additionally recognize the hostapi.atlassian.com.Testing
go build ./...,go vet,go test ./...all pass.Fixes #341
🤖 Generated with Claude Code