Skip to content

Support oauth2#9

Open
BatoWa wants to merge 27 commits into
mainfrom
support-oauth2
Open

Support oauth2#9
BatoWa wants to merge 27 commits into
mainfrom
support-oauth2

Conversation

@BatoWa

@BatoWa BatoWa commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds OAuth2 (3LO) authentication support for Jira Cloud to the Defect Service,
alongside the existing basic, token, and oauth1 strategies. Because
OAuth2 (and Cloud scoped API tokens) only work through the Atlassian API
gateway, this branch also introduces the gateway connection path and fixes the
URL-generation issues that come with it.

Motivation

Jira Cloud is moving toward OAuth2 / scoped API tokens, which are not accepted
by the direct site URL — they must go through api.atlassian.com/ex/jira/{cloudId}.
The service needed a first-class OAuth2 flow (token lifecycle, refresh, setup
wizard) and had to keep user-facing URLs pointing at the configured Jira site
rather than the internal gateway host.

What changed

OAuth2 authentication

  • New auth_type = "oauth2" in JiraDefectClientConfig, with oauth2_client_id,
    oauth2_client_secret, and oauth2_refresh_token (env-var overridable, e.g.
    JIRA_OAUTH2_CLIENT_ID). Validated in validate_config.
  • New clients/jira/jira_oauth.py: module-level token store persisted to
    tmp/oauth2_tokens.toml, refreshed against auth.atlassian.com/oauth/token,
    and injected per-request via a session send patch.
  • Setup wizard flow to retrieve and authorize an initial OAuth2 token.

Gateway connection path

  • _connect_via_gateway connects through api.atlassian.com/ex/jira/{cloudId},
    resolving the cloud ID from the public /_edge/tenant_info endpoint.
  • Session-level patching transparently routes site-URL requests to the gateway
    and injects the bearer token, so callers stay gateway-agnostic.

Correct user-facing URLs under the gateway (permalinks & attachments)

  • create_defect_from_issue / create_extended_defect_from_issue /
    _extract_references now accept a site_url (the configured server_url)
    and build permalinks and attachment URLs against the Jira site instead of the
    gateway host. Previously references pointed at api.atlassian.com/ex/jira/….
  • Fixed an UnboundLocalError in _extract_references for issues with no
    attachments.

Docs & tests

  • Updated docs/clients/jira-client.md, docs/cli.md, and migration docs.
  • Added unit tests: test_jira_oauth.py, plus TestExtractReferences and
    site_url coverage in test_utils.py.

Notes for reviewers

  • Attachment URLs are currently hardcoded to the /rest/api/2/… REST base;
    tracking the actual API version is intentionally deferred.
  • No real tokens/secrets are committed; tmp/oauth2_tokens.toml and
    config.toml remain local-only working artifacts.

BatoWa and others added 27 commits May 29, 2026 08:37
* Enhance control field value extraction to handle various object types and improve robustness

* Enhance fetch_project_issue_fields method to handle JIRAError and fallback to createmeta endpoint for improved reliability

* Enhance handle_jira_error to include detailed error message from JIRAError for improved debugging

* Add troubleshooting tips for Jira synchronization issues related to permissions

* Enhance JiraClient to support connection via Atlassian API gateway for scoped API tokens and improve connection verification methods

* Add documentation for Jira scoped API token scopes required for Jira Cloud integration
…, update token handling, and improve documentation for conversion commands
…, improve refresh token handling, and add setup wizard for OAuth2 token retrieval
…r to preserve HTTP status codes and improve error messaging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant