Skip to content

Conversation

bhazen
Copy link
Contributor

@bhazen bhazen commented Sep 19, 2025

What issue does this PR address?
Adds a new constructor to DiscoveryCache to allow the use of the BaseAddress from an HttpClient as the authority. This also required making the _authority member nullable and adding the conditional to find the appropriate value.

@bhazen bhazen added this to the im-8.0.0 milestone Sep 19, 2025
@bhazen bhazen self-assigned this Sep 19, 2025
@bhazen bhazen added the area/foss/identity-model Issues related to Identity Model label Sep 19, 2025
@Copilot Copilot AI review requested due to automatic review settings September 19, 2025 17:58
@bhazen bhazen requested a review from a team as a code owner September 19, 2025 17:58
@bhazen bhazen added the impact/non-breaking The fix or change will not be a breaking one label Sep 19, 2025
@bhazen bhazen force-pushed the beh/disco-cache-with-httpclient-baseaddress branch from 56c6100 to bd5add4 Compare September 19, 2025 17:58
Copy link
Contributor

@Copilot 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

Adds support for creating a DiscoveryCache without an explicit authority by falling back to the HttpClient.BaseAddress, plus tests for success and failure scenarios.

  • Adds a new constructor that omits authority and makes _authority nullable.
  • Updates GetResponseAsync to resolve the effective address from either the provided authority or the HttpClient BaseAddress.
  • Adds tests for both valid BaseAddress usage and the null-address failure case.

Reviewed Changes

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

File Description
identity-model/src/IdentityModel/Client/DiscoveryCache.cs Adds nullable authority support, new constructor, and updated logic to determine discovery address.
identity-model/test/IdentityModel.Tests/DiscoveryCacheTests.cs Adds tests for new constructor behavior and error condition when neither authority nor BaseAddress is provided.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

{
var result = await _getHttpClient().GetDiscoveryDocumentAsync(new DiscoveryDocumentRequest
var client = _getHttpClient();
var httpClient = client as HttpClient;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was not thrilled with needing to do this, but the alternative I saw was changing the type of _getHttpClient to be Func<HttpClient> which would be a breaking change. What do others think?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe to be defensive we should detect if the cast fails and throw an exception to say that you have to either use an http client or set the authority?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's probably better than relying on exception from HttpClientDiscoveryExtensions. Updated to throw that slightly below this line if we can't get the authority from either expected place.

@bhazen bhazen force-pushed the beh/disco-cache-with-httpclient-baseaddress branch 2 times, most recently from ce5243e to c76e3be Compare September 20, 2025 22:45
@bhazen bhazen force-pushed the beh/disco-cache-with-httpclient-baseaddress branch from c76e3be to cd0c9e4 Compare September 22, 2025 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/foss/identity-model Issues related to Identity Model impact/non-breaking The fix or change will not be a breaking one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support in DiscoveryCache to HttpClients with BaseAddress specified
2 participants