Certificate authentication retry clears in-memory credentials and hides the original error
Maintainers usually reply within 2 days
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- csharp
- Domain
- authentication, backend-api-design, testing
Research direction
Read CredentialsProvider.NotifyCertificateAction and DefaultCredentialsLoader.ResetCredentials, then trace retry credential loading and how IDW10109 preserves exceptions. Add network-free regression coverage for certificate recovery, exception chains, shared descriptions, custom loaders and warning-level logging. Done means failed authentication leaves caller-owned certificates usable, the original service exception is retained, and the reported regression cases pass.
Written by the indexing model from the issue text.
Description
Issue details
Microsoft.Identity.Web Library
Microsoft.Identity.Web.TokenAcquisition and Microsoft.Identity.Web.Certificate
Microsoft.Identity.Web version
Reproduced from master at 432c6daa on .NET 8 using network-free tests. A released-package reproduction has not been run.
Web app
Not Applicable
Web API
Not Applicable (app-only token acquisition)
Token cache serialization
In-memory caches; the credential mutation is independent of the cache provider.
Description
A certificate-related token-endpoint rejection can permanently disable a caller-supplied in-memory certificate credential.
The bounded retry reports unsuccessful certificate usage. CredentialsProvider.NotifyCertificateAction clears both CredentialDescription.Certificate and CachedValue. For CredentialSource.Certificate, the default credentials loader cannot reconstruct the certificate. Later acquisitions then fail locally with IDW10109, even if the token endpoint would accept the certificate.
The original MsalServiceException is also lost when retry preparation fails: IDW10109 only retains exceptions raised by credential loaders. Clearing the certificate changes its credential ID, which is included in the confidential-client application cache key, and affects consumers sharing the description.
Reproduction steps
- Supply an in-memory certificate using the configuration below.
- Use a fake
IMsalHttpClientFactorywhose token endpoint returns HTTP 401 with{"error":"invalid_client","error_description":"AADSTS700027: Invalid certificate","error_codes":[700027]}for the first request and accepts subsequent requests. - Acquire an app token repeatedly using the same credential description.
Error message
IDW10109: No credential could be loaded.
The retry can produce empty loading details and no inner exception. Later calls fail without another token-endpoint request.
Id Web logs
The certificate-retry message and IDW10501 credential/build failure currently use an Information-level logging helper, so Warning-only logging can miss the triggering failure.
Relevant code snippets
options.ClientCredentials =
[
new CredentialDescription
{
SourceType = CredentialSource.Certificate,
Certificate = certificate,
},
];
Regression
The first affected release has not been established.
Expected behavior
- Failed authentication must not erase a caller-owned certificate or permanently prevent later acquisitions.
- Keep bounded retries and existing custom loader/observer extensibility.
- If retry credential loading fails, preserve the original token-endpoint exception along with any credential-loading exception.
- Surface certificate-recovery and credential/build failures at Warning level without changing unrelated authentication logging.
Proposed fix
Align deselection with DefaultCredentialsLoader.ResetCredentials: always clear CachedValue, but preserve Certificate for CredentialSource.Certificate. Preserve the original service exception when credential loading fails during a retry. Add network-free recovery, exception-chain, cache/shared-description, custom-loader and logging regression tests.
The initial regression run against unfixed master produced 16 failures and 3 passing controls across 19 cases. After the fix, the final 21-case regression set passed on .NET 8, 9 and 10.
- Dominant language
- C#
- Stars
- 787
- Forks
- 277
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 12
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from AzureAD/microsoft-identity-web
-
Sidecar: “overrides not allowed” warning names the wrong Sidecar:AllowOverrides keyMay be free again @iNinja claimed this 45 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
AzureAD/microsoft-identity-web#4099 · 1 comment · 1 assignee ·
Maintainers usually reply within 2 days
-
sectionName parameter ignored by `AddMicrosoftIdentityMessageHandler`Possibly taken @bgavrilMS claimed this 38 days ago. Openbug P2
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
AzureAD/microsoft-identity-web#4029 · 2 comments · 1 reaction · 2 assignees ·
Maintainers usually reply within 2 days
-
bug P1 work-around-available
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
AzureAD/microsoft-identity-web#3791 · 9 comments · 6 reactions ·
Maintainers usually reply within 2 days
-
[Feature Request] Setting to disable MSAL instance discovery (DisableInstanceDiscovery)Possibly taken @jesperkarlshoj claimed this 2 days ago. Openenhancement feature request needs attention untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
AzureAD/microsoft-identity-web#4158 ·
Maintainers usually reply within 2 days
-
OBO fails with authority_type_mismatch when the web API is configured with Authority (PreserveAuthority) and the user token has a tid claimPossibly taken @iarekk claimed this 7 days ago. Openbug work-around-available
Difficulty 4/5 3-5 days Newbie friendliness 32/100
AzureAD/microsoft-identity-web#4148 · 2 comments · 1 assignee ·
Maintainers usually reply within 2 days
All issues in AzureAD/microsoft-identity-web
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Night clock (AOD) overflows the screen in portraitPossibly taken @ersinkoc claimed this today. Open
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
nkdAgility/azure-devops-migration-tools#3431 ·
Maintainers usually reply within 1 day
-
Python example: list a model's scenes and their camerasPossibly taken @rudraparmar76 claimed this today. Opendocumentation good first issue python
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
iamahsanmehmood/openskp#796 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
marcosdosea/eventos#985 ·
Maintainers usually reply within 2 days