Skip to content

feat(azure.ai.agents): add full OAuth2 fields and connector-name support#8358

Merged
Nathandrake229 merged 5 commits into
mainfrom
naman/azd-connection-oauth2-fields
May 26, 2026
Merged

feat(azure.ai.agents): add full OAuth2 fields and connector-name support#8358
Nathandrake229 merged 5 commits into
mainfrom
naman/azd-connection-oauth2-fields

Conversation

@Nathandrake229
Copy link
Copy Markdown
Contributor

Summary

Fixes #8355

Adds missing OAuth2 connection fields (--authorization-url, --token-url, --refresh-url, --scopes, --connector-name) and implements either/or validation for managed connector vs BYO OAuth2 flows.

Problem

The ARM Go SDK ConnectionOAuth2 struct only exposes AuthURL, ClientID, and ClientSecret. It does not model tokenUrl, refreshUrl, scopes, or connectorName — all top-level ARM connection properties required for full OAuth2 support.

Changes

OAuth2 moved to raw REST path

  • OAuth2 connections now use the same raw REST pipeline as identity auth types
  • Bypasses SDK struct limitations — all fields serialize directly to the ARM wire format
  • buildConnectionBody rejects OAuth2 with a clear error if accidentally called

New flags

Flag Description
--authorization-url OAuth2 authorization endpoint
--token-url OAuth2 token endpoint
--refresh-url OAuth2 token refresh endpoint
--scopes OAuth2 scopes (space-separated)
--connector-name Managed connector name (e.g., github, slack)

Either/or validation

Two mutually exclusive modes for --auth-type oauth2:

  1. Managed connector: --connector-name alone
  2. BYO OAuth2: all of --authorization-url, --token-url, --refresh-url, --scopes, --client-id, --client-secret

Partial combinations are rejected with a clear error listing exactly which flags are missing.

Tests

  • 33 tests passing
  • Added: connector-name-only body serialization test
  • Added: OAuth2 full fields raw REST marshaling test

Files changed

  • connection.go — moved OAuth2 to raw REST switch, added flags, either/or validation
  • raw_connection.go — added OAuth2 fields, rawCredentials struct
  • connection_test.go — updated/added OAuth2 tests

Naman Tyagi and others added 2 commits May 25, 2026 19:56
Fixes #8355

Move OAuth2 from typed ARM SDK path to raw REST to support fields
not modeled in the ARM Go SDK: authorizationUrl, tokenUrl, refreshUrl,
scopes, and connectorName.

New flags for connection create:
  --authorization-url   OAuth2 authorization endpoint
  --token-url           OAuth2 token endpoint
  --refresh-url         OAuth2 refresh endpoint
  --scopes              OAuth2 scopes (space-separated)
  --connector-name      Managed connector name

OAuth2 credentials (--client-id/--client-secret) now sent as nested
credentials object in the raw REST body.

Update path also routes oauth2 through raw REST for consistency.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
OAuth2 auth now supports two mutually exclusive modes:
- --connector-name alone (managed connector flow)
- All of --authorization-url, --token-url, --refresh-url, --scopes,
  --client-id, --client-secret together (BYO OAuth2)

Partial combinations are rejected with a clear error listing missing flags.
Added test for connector-name-only body serialization.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the ext-agents azure.ai.{agents,connections,inspector,projects,routines,skills,toolboxes} extensions label May 25, 2026
Comment thread cli/azd/extensions/azure.ai.agents/internal/connections/cmd/connection.go Outdated
Comment thread cli/azd/extensions/azure.ai.agents/internal/connections/cmd/connection.go Outdated
…separated

Address Linda's review comments:
- --audience now also valid with --auth-type project-managed-identity
- --scopes help text updated to comma-separated (was space-separated)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Nathandrake229 Nathandrake229 marked this pull request as ready for review May 26, 2026 14:50
Copilot AI review requested due to automatic review settings May 26, 2026 14:50
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 26, 2026

📋 Prioritization Note

Thanks for the contribution! The linked issue isn't in the current milestone yet.
Review may take a bit longer — reach out to @rajeshkamal5050 or @kristenwomack if you'd like to discuss prioritization.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the azure.ai.agents extension’s connection create support for OAuth2 by adding missing OAuth2 fields (authorization/token/refresh URLs, scopes, connector name) and routing OAuth2 connection creation through the raw ARM REST path to bypass ARM SDK struct limitations.

Changes:

  • Added new OAuth2 CLI flags (--authorization-url, --token-url, --refresh-url, --scopes, --connector-name) and implemented either/or validation for managed connector vs BYO OAuth2.
  • Moved OAuth2 connection creation to the raw REST pipeline (shared with identity-based auth types) and made the typed SDK path reject OAuth2.
  • Added/updated tests around raw OAuth2 body marshaling and auth-type normalization.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
cli/azd/extensions/azure.ai.agents/internal/connections/cmd/raw_connection.go Extends raw ARM connection body to include OAuth2 fields and credentials.
cli/azd/extensions/azure.ai.agents/internal/connections/cmd/connection.go Adds new OAuth2 flags, validation, and routes OAuth2 through raw REST for create/update.
cli/azd/extensions/azure.ai.agents/internal/connections/cmd/connection_test.go Updates tests for OAuth2 handling (typed path rejection + raw body marshal assertions).
Comments suppressed due to low confidence (1)

cli/azd/extensions/azure.ai.agents/internal/connections/cmd/connection.go:570

  • connection update now routes OAuth2 (and identity auth types) through rawCreateConnection, but the body built here only includes authType, category, target, and metadata. Since rawCreateConnection does an ARM PUT, omitting OAuth2/identity-specific properties (e.g., connectorName, authorizationUrl/tokenUrl/scopes, audience, credentials) will likely clear them or cause the service to reject the request. Consider either (1) fetching the full current resource via raw REST and merging preserved fields into the PUT body, or (2) explicitly disallowing connection update for these auth types until preservation is implemented.
	// Route to raw REST or typed SDK based on auth type
	switch normalizedAuth {
	case "oauth2", "user-entra-token", "project-managed-identity", "agentic-identity":
		// Auth types that lack full ARM SDK support — update via raw REST
		err = rawCreateConnection(
			ctx, connCtx,
			a.flags.name,
			rawConnectionProperties{
				AuthType: normalizeAuthTypeToARM(normalizedAuth),
				Category: kindStr,
				Target:   newTarget,
				Metadata: parseKVMap(metaPairs),
			},
		)

Comment thread cli/azd/extensions/azure.ai.agents/internal/connections/cmd/raw_connection.go Outdated
…lidation tests

- Change Scopes from string to []string to match schema wire format
- Switch --scopes flag to StringSliceVar (repeatable/comma-separated)
- Make --refresh-url and --scopes optional in BYO OAuth2 validation
- Fix test: remove ConnectorName from BYO test (mutually exclusive)
- Add TestOAuth2Validation with 7 subtests covering all branches

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ions

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Nathandrake229 Nathandrake229 enabled auto-merge (squash) May 26, 2026 16:15
@trangevi
Copy link
Copy Markdown
Member

/check-enforcer override

@Nathandrake229 Nathandrake229 merged commit 6f2867c into main May 26, 2026
31 of 33 checks passed
hund030 added a commit that referenced this pull request May 27, 2026
Address PR #8357 review feedback from trangevi:

- Move internal/connections/cmd/ -> internal/cmd/ so commands live at
  the same depth as every other extension. Connection-context glue
  renamed connection_context.go to avoid colliding with the existing
  generic context.go verb. The RegisterCommands helper is inlined into
  internal/cmd/root.go (5 AddCommand calls; no helper package needed
  now that everything is in the same package).
- Move internal/connections/pkg/connections/ -> internal/pkg/connections/
  to match the convention used by other extensions.

Also ports the connection-side changes from PR #8358 (OAuth2 fields
and connector-name support) into the migrated copy. The plain
`git merge origin/main` dropped them because rename-detection didn't
follow our cross-directory migration; replayed by taking main's
connection.go / connection_test.go / raw_connection.go from the agents
copy and rewriting imports + example strings for the connections
extension.

Updates:

- internal/cmd/root.go: drop the connectioncmd helper-package import;
  inline the 5 CRUD AddCommand calls.
- internal/cmd/connection.go: imports azure.ai.connections/internal/exterrors
  (was the now-removed nested exterrors path); example strings use
  `azd ai connection` (was `azd ai agent connection`).
- AGENTS.md: package-layout description and one-way import contract
  updated to reference internal/cmd/ + internal/pkg/ (was
  internal/connections/cmd/ + internal/connections/pkg/).
- cspell.yaml: drop unused `connectioncmd` (the helper-package alias
  no longer exists).

Verified by running the local e2e smoke test
(Test_CLI_Connection_Smoke) end-to-end against a live Foundry project:
build, pack, publish, install, create, list, show, show --show-credentials,
update, post-update show, delete, post-delete show (expected 404) all
pass.
trangevi added a commit that referenced this pull request May 27, 2026
….agents (#8357)

* feat(azure.ai.connections): migrate connection commands from azure.ai.agents

Move the connection CRUD commands (list / show / create / update / delete)
from azure.ai.agents into the new azure.ai.connections extension so users
invoke them as `azd ai connection <verb>` instead of
`azd ai agent connection <verb>`.

Key adjustments vs source:

- Module path `azure.ai.connections`.
- Project endpoint resolution moved into `internal/foundry/projectctx`,
  mirroring the `azure.ai.toolboxes` package layout (same one-way import
  contract documented in AGENTS.md). The cascade and `Validate` rules
  are inherited unchanged.
- `internal/exterrors` promoted to the extension top level so
  `internal/foundry/` does not depend on connection-cmd-specific code.
- Update examples and persistent `-p / --project-endpoint` flag rewired
  to the new extension root.

Agents extension is cleaned up in the same change:

- Drops the `azd ai agent connection` command tree
  (`internal/connections/cmd` and `internal/connections/exterrors`).
- Retains `internal/connections/pkg/connections` because
  `connection_credentials.go` still needs the data-plane client to
  resolve `${{connections.<name>.credentials.<key>}}` placeholders at
  agent-run time.

Tests:

- All migrated tests pass under the new module path.
- 18 new unit tests added for the `projectctx` package (validator,
  resolver cascade with stubbed hosted-sources seam, persisted
  config-key constant).
- `.golangci.yaml` added to match sibling extensions; lint clean.

* chore(azure.ai.connections): add cspell words for projectctx/exterrors/connectioncmd/tavily/tvly

* fix(azure.ai.connections): derive data-plane user-agent from build-injected version

The data-plane client hard-coded its user-agent as
`azd-ext-azure-ai-connection/0.1.0` (singular, frozen literal). Every
release would have shipped that same string regardless of the
extension version, defeating the point of having a user-agent in
the first place.

Mirror the azure.ai.agents wiring so the user-agent comes from a
`-ldflags`-injected constant:

- Add `internal/version` package (Version / Commit / BuildDate),
  matching `azure.ai.agents/internal/version`.
- Point `build.sh` and `build.ps1` at the new package (was
  `internal/cmd`, which only `version.go` read).
- Have `data_client.go` build the user-agent from `version.Version`
  and fix the name to plural `azd-ext-azure-ai-connections`. Pipeline
  label likewise pluralized for consistency.
- Drop the redundant `Version/Commit/BuildDate` vars from
  `internal/cmd/version.go`; the `version` command now reads from
  the new package too, keeping a single source of truth.

Resolves Copilot review feedback on PR #8357.

* refactor(azure.ai.connections): flatten package layout + port #8358

Address PR #8357 review feedback from trangevi:

- Move internal/connections/cmd/ -> internal/cmd/ so commands live at
  the same depth as every other extension. Connection-context glue
  renamed connection_context.go to avoid colliding with the existing
  generic context.go verb. The RegisterCommands helper is inlined into
  internal/cmd/root.go (5 AddCommand calls; no helper package needed
  now that everything is in the same package).
- Move internal/connections/pkg/connections/ -> internal/pkg/connections/
  to match the convention used by other extensions.

Also ports the connection-side changes from PR #8358 (OAuth2 fields
and connector-name support) into the migrated copy. The plain
`git merge origin/main` dropped them because rename-detection didn't
follow our cross-directory migration; replayed by taking main's
connection.go / connection_test.go / raw_connection.go from the agents
copy and rewriting imports + example strings for the connections
extension.

Updates:

- internal/cmd/root.go: drop the connectioncmd helper-package import;
  inline the 5 CRUD AddCommand calls.
- internal/cmd/connection.go: imports azure.ai.connections/internal/exterrors
  (was the now-removed nested exterrors path); example strings use
  `azd ai connection` (was `azd ai agent connection`).
- AGENTS.md: package-layout description and one-way import contract
  updated to reference internal/cmd/ + internal/pkg/ (was
  internal/connections/cmd/ + internal/connections/pkg/).
- cspell.yaml: drop unused `connectioncmd` (the helper-package alias
  no longer exists).

Verified by running the local e2e smoke test
(Test_CLI_Connection_Smoke) end-to-end against a live Foundry project:
build, pack, publish, install, create, list, show, show --show-credentials,
update, post-update show, delete, post-delete show (expected 404) all
pass.

* fix(connections): use build-time version in data client pipeline

Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext-agents azure.ai.{agents,connections,inspector,projects,routines,skills,toolboxes} extensions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azd connection for oauth2 auth type doesn't support auth url, token url, and refresh url

4 participants