Skip to content
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

NuGet should automatically send credentials after the first request with a HTTP 401 response #93871

Closed
zivkan opened this issue Oct 23, 2023 · 2 comments

Comments

@zivkan
Copy link
Member

zivkan commented Oct 23, 2023

Description

see:

After NuGet experiences one HTTP 401 response from a server, sending more unauthenticated requests just increases latency and increases the server workload processing these requests.

Reproduction Steps

restore, where at least 1 package needs to be downloaded, or open PM UI in VS, and go to the browse tab

Expected behavior

There should only be 1 unauthenticated HTTP request sent. NuGet should then either use credentials provided in the nuget.config file, or ask a credential provider for credentials.

Actual behavior

Every URL is requested twice, first unauthenticated, and then again with an Authorization header.

Regression?

We previously tried HttpClientHandler.PreAuthenticate, but there's a bug in the .NET runtime:

Known Workarounds

No response

Configuration

No response

Other information

In HttpSourceAuthenticationHandler, when a response is a HTTP 401, NuGet needs to check if the WWW-Authenticate header exists, and if so, when it responds with the Basic scheme, NuGet needs to explicitly set the Authorization header on all future requests. If a future 401 response is received, credentials should be re-requested, in case the customer interactively provided a credential and made a typo, or if a cred provider returned a time-limited token that needs to be refreshed.

Since we're going to have to handle Basic authentication ourselves, it would be great to also handle Bearer, since that will enable OAuth2 (including OIDC) credential providers. It should be effectively zero cost to add once Basic is handled.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 23, 2023
@ghost
Copy link

ghost commented Oct 23, 2023

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

see:

After NuGet experiences one HTTP 401 response from a server, sending more unauthenticated requests just increases latency and increases the server workload processing these requests.

Reproduction Steps

restore, where at least 1 package needs to be downloaded, or open PM UI in VS, and go to the browse tab

Expected behavior

There should only be 1 unauthenticated HTTP request sent. NuGet should then either use credentials provided in the nuget.config file, or ask a credential provider for credentials.

Actual behavior

Every URL is requested twice, first unauthenticated, and then again with an Authorization header.

Regression?

We previously tried HttpClientHandler.PreAuthenticate, but there's a bug in the .NET runtime:

Known Workarounds

No response

Configuration

No response

Other information

In HttpSourceAuthenticationHandler, when a response is a HTTP 401, NuGet needs to check if the WWW-Authenticate header exists, and if so, when it responds with the Basic scheme, NuGet needs to explicitly set the Authorization header on all future requests. If a future 401 response is received, credentials should be re-requested, in case the customer interactively provided a credential and made a typo, or if a cred provider returned a time-limited token that needs to be refreshed.

Since we're going to have to handle Basic authentication ourselves, it would be great to also handle Bearer, since that will enable OAuth2 (including OIDC) credential providers. It should be effectively zero cost to add once Basic is handled.

Author: zivkan
Assignees: -
Labels:

area-System.Net.Http

Milestone: -

@zivkan
Copy link
Member Author

zivkan commented Oct 23, 2023

oops, wrong repo :( I was wondering why the bug template seemed different.

@zivkan zivkan closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Oct 23, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Nov 22, 2023
@karelz karelz added this to the 9.0.0 milestone May 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants