Skip to content

Comments

Added withFmi method for cca app#876

Open
4gust wants to merge 2 commits intodevfrom
4gust/with-fmi
Open

Added withFmi method for cca app#876
4gust wants to merge 2 commits intodevfrom
4gust/with-fmi

Conversation

@4gust
Copy link
Contributor

@4gust 4gust commented Feb 20, 2026

Add acquire_token_for_client_with_fmi_path() for FMI support

Adds a new method to ConfidentialClientApplication for acquiring tokens with a Federated Managed Identity (FMI) path. It wraps acquire_token_for_client(), injecting fmi_path into the request body while preserving all existing caching, telemetry, and regional endpoint behavior.

Usage

import msal

app = msal.ConfidentialClientApplication(
    "your-client-id",
    client_credential={"private_key_pfx_path": "/path/to/cert.pfx", "public_certificate": True},
    authority="https://login.microsoftonline.com/your-tenant-id",
)

result = app.acquire_token_for_client_with_fmi_path(
    scopes=["api://resource/.default"],
    fmi_path="SomeFmiPath/FmiCredentialPath",
)

E2E test

Added E2E test to msid client

@4gust 4gust requested a review from a team as a code owner February 20, 2026 11:38
- an error response would contain "error" and usually "error_description".
"""
data = kwargs.pop("data", {})
data["fmi_path"] = fmi_path
Copy link
Member

Choose a reason for hiding this comment

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

Are the tokens cached like in MSAL .NET and MSAL GO? I don't think they are.

I see a PR here that look at proper caching #759 but I am not sure it is compliant with the rest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a cache enhancement so now we create a hash key for some data keyvalues

self.token_cache.remove_at(at)
# acquire_token_for_client() obtains no RTs, so we have no RT to remove

def acquire_token_for_client_with_fmi_path(self, scopes, fmi_path, claims_challenge=None, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Should we have FMI path as one of the kwargs instead? Creating an entire new API seems pretty heavy.

Copy link
Member

Choose a reason for hiding this comment

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

This comment still stands. Should we "an overload" of AcquireTokenForClient existing API?

# Included fields (examples — anything NOT in this set is included):
# - "fmi_path" : Federated Managed Identity credential path
# - any future extra body parameter that should isolate cache entries
_EXT_CACHE_KEY_EXCLUDED_FIELDS = frozenset({
Copy link
Member

Choose a reason for hiding this comment

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

Pls add a comment that these fields are already taken care of separately.

"key_id",
"token_type",
"req_cnf",
"claims",
Copy link
Member

@bgavrilMS bgavrilMS Feb 23, 2026

Choose a reason for hiding this comment

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

I think you are missing a few things:

  • client_assertion and client_assertion_type and client_secret
  • grant_type
  • force_refresh

We probably need to enhance existing tests to assert that no "unknown" key is used.

logger = logging.getLogger(__name__)
_GRANT_TYPE_BROKER = "broker"

# Fields in the request data dict that should NOT be included in the extended
Copy link
Member

Choose a reason for hiding this comment

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

The .NET spec mentioned using "atext" in the cache key. Maybe we are missing a test that attempts to load a token from a file.

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.

2 participants