Skip to content

[FEATURE]: Azure AI Foundry Microsoft Entra (OAuth) authentication #21658

Open

Description

@NoTuxNoBux

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

It appears Microsoft Entra authentication with the Azure AI Foundry is not supported yet (or I can't find anything about it 😉).

A customer of ours deployed Anthropic models in an Azure AI Foundry with a custom base URL and provided instructions only for Anthropic CLI. The existing provider relies on an API key, but the customer expressly does not want to provide one to strengthen security and enforces Entra authentication using the Azure CLI instead.

These are the steps they document (not using OpenCode):

  1. export ANTHROPIC_FOUNDRY_BASE_URL=https://their-custom-domain.azure-api.net/ai/anthropic
  2. export CLAUDE_CODE_USE_FOUNDRY="1"
  3. az login to sign in to Azure using Entra Authentication (OAuth).
  4. claude run

Steps 1, 2 and 4 appear already possible with OpenCode (#4474 (comment)), but for 3 an API key is expected by OpenCode instead.

They also mention the Azure CLI session can expire every so often (10 hours in their case), in which case az logout followed by az login is required - mentioning it as reauthenticating might be relevant for OpenCode also.

Activity

  1. added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Apr 9, 2026
  2. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 9, 2026
  3. removed
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  4. OpeOginni commented on Jun 16, 2026

    @OpeOginni
    Contributor

    Got this PR ready to go, adds OAuth through the az cli #31351

  5. github-actions commented on Aug 16, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

  6. mkemmerz commented on Aug 16, 2026

    @mkemmerz

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

    Please reopen - great feature

  7. OpeOginni commented on Aug 28, 2026

    @OpeOginni
    Contributor

    Should work after new release!

  8. NoTuxNoBux commented on Aug 31, 2026

    @NoTuxNoBux
    Author

    I'm testing out the new functionality, but still not entirely sure how to configure it for my scenario in the OP. This is the flow I'm seeing now:

    1. Open OpenCode TUI.
    2. Connect provider.
    3. Select Azure.
    4. Select Entra ID.
    5. It uses the Azure CLI to look for my credentials, that works.
    6. It presents me a list of resource names. I select the Foundry.
    7. I get the model selection, I select a model that I know should work.
    8. I ask a test question and get PermissionDenied without further details.

    The customer I'm working for has a bit of a special setup:

    1. They have a custom Azure API Management service hosted at https://their-custom-domain.azure-api.net/ that seems to forward all calls (so /ai/*) to https://their-actual-foundry-swedencentral-001.cognitiveservices.azure.com (so e.g. Claude CLI uses https://their-custom-domain.azure-api.net/ai/anthropic).
    2. On this API forwarding rule, they have a rule validate-azure-ad-token set.

    In other words they don't seem to support directly using the Foundry URL in question and Entra-authenticated calls need to go through a custom URL/domain instead. Is there any way to configure opencode.jsonc to use the new Entra authentication instead of an API key? The main problem seems to be that I need to be able to enter a fully custom URL (as opposed to just a resource name).

  9. OpeOginni commented on Aug 31, 2026

    @OpeOginni
    Contributor

    @NoTuxNoBux are you making use of the Opencode v2?

  10. NoTuxNoBux commented on Aug 31, 2026

    @NoTuxNoBux
    Author

    Thanks for the response. I'm not sure what you mean by v2, is that a new in-progress version on the main branch? I'm currently on 1.18.25.

  11. OpeOginni commented on Aug 31, 2026

    @OpeOginni
    Contributor

    No v2 is the new version of clone code coming soon, you can download it here try that an see if it works, it's still wip and should be official in some weeks https://opencode.ai/v2/docs

  12. neriousy commented on Sep 1, 2026

    @neriousy
    Member

    Yeah, the custom URL stuff probably needs to be set through config. I'll take a look at it later today!

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

Metadata

Metadata

Assignees

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