-
Notifications
You must be signed in to change notification settings - Fork 34
Allow Using HttpClient BaseAddres for Authority in DiscoveryCache #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
56c6100
to
bd5add4
Compare
There was a problem hiding this 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
ce5243e
to
c76e3be
Compare
c76e3be
to
cd0c9e4
Compare
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.