question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet new 401 unauthorized errors

See original GitHub issue

After running with --interactive from a private NuGet feed, the template is installed. I would expect the token to be cached so I don’t have to use --interactive every time. However, reinstalling the same template results in the error below (with telemetry enabled):

Telemetry is: Enabled
[2022-01-20 18:22:16.205] [Debug] [Microsoft.TemplateEngine.Cli.CliTemplateEngineHost] => [Execute]: Execute started
The following template packages will be installed:
   <package>

[2022-01-20 18:22:16.273] [Debug] [Microsoft.TemplateEngine.Edge.Installers.NuGet.NuGetInstaller] => [Execute]: <package> is not a local NuGet package.
[2022-01-20 18:22:16.299] [Debug] [Microsoft.TemplateEngine.Edge.Installers.NuGet.NuGetInstaller] => [Execute]: <package> is identified as the downloadable NuGet package.
[2022-01-20 18:22:16.307] [Debug] [Microsoft.TemplateEngine.Edge.Installers.NuGet.NuGetInstaller] => [Execute]: <package> is not a local NuGet package.
[2022-01-20 18:22:16.307] [Debug] [Microsoft.TemplateEngine.Edge.Installers.NuGet.NuGetInstaller] => [Execute]: <package> is identified as the downloadable NuGet package.
[2022-01-20 18:22:16.348] [Debug] [NuGetLogger] => [Execute]: Searching for <package> in https://api.nuget.org/v3/index.json.
[2022-01-20 18:22:16.441] [Debug] [NuGetLogger] => [Execute]:   GET https://api.nuget.org/v3/registration5-gz-semver2/<package>/index.json
[2022-01-20 18:22:16.542] [Debug] [NuGetLogger] => [Execute]: Searching for <package> in C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\.
[2022-01-20 18:22:16.552] [Debug] [NuGetLogger] => [Execute]: Searching for <package> in https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v3/index.json.
[2022-01-20 18:22:16.554] [Debug] [NuGetLogger] => [Execute]: <package> is not found in NuGet feed C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\.
[2022-01-20 18:22:16.558] [Debug] [NuGetLogger] => [Execute]:   GET https://pkgs.dev.azure.com/<organization>/_packaging/59388b54-2798-4d11-b0d7-a731a1308e1e/nuget/v3/registrations2-semver2/<package>/index.json
[2022-01-20 18:22:17.127] [Debug] [NuGetLogger] => [Execute]:   NotFound https://api.nuget.org/v3/registration5-gz-semver2/<package>/index.json 683ms
[2022-01-20 18:22:17.146] [Debug] [NuGetLogger] => [Execute]: <package> is not found in NuGet feed https://api.nuget.org/v3/index.json.
[NuGet Manager] [DEBUG] Using C:\Users\levim\.nuget\plugins\netcore\CredentialProvider.Microsoft\CredentialProvider.Microsoft.dll as a credential provider plugin.
[NuGet Manager] [Verbose]     [CredentialProvider.182218]Running in plug-in mode
[NuGet Manager] [Verbose]     [CredentialProvider.182218]Command-line v0.1.28+103227dd070f2b048ce0ae9bc259f12d509d85e2: C:\Users\levim\.nuget\plugins\netcore\CredentialProvider.Microsoft\CredentialProvider.Microsoft.dll -Plugin
[NuGet Manager] [Verbose]     [CredentialProvider.182218]Handling 'Request' 'Initialize'. Time elapsed in ms: 5 - Payload: {"ClientVersion":"6.0.0","Culture":"en-US","RequestTimeout":"00:00:05"}
[NuGet Manager] [Verbose]     [CredentialProvider.182218]Sending response: 'Request' 'Initialize'. Time elapsed in ms: 7
[NuGet Manager] [Verbose]     [CredentialProvider.182218]Time elapsed in milliseconds after sending response 'Request' 'Initialize': 10
[NuGet Manager] [Verbose]     [CredentialProvider.182218]Handling 'Request' 'GetOperationClaims'. Time elapsed in ms: 1 - Payload: {}
[NuGet Manager] [Verbose]     [CredentialProvider.182218]Sending response: 'Request' 'GetOperationClaims'. Time elapsed in ms: 12
[NuGet Manager] [Verbose]     [CredentialProvider.182218]Time elapsed in milliseconds after sending response 'Request' 'GetOperationClaims': 28
[NuGet Manager] [Verbose]     [CredentialProvider.182218]Handling 'Request' 'SetLogLevel'. Time elapsed in ms: 6 - Payload: {"LogLevel":"Debug"}
[NuGet Manager] [Verbose]     [CredentialProvider]Sending response: 'Request' 'SetLogLevel'. Time elapsed in ms: 7
[NuGet Manager] [Verbose]     [CredentialProvider]Time elapsed in milliseconds after sending response 'Request' 'SetLogLevel': 23
[NuGet Manager] [Verbose]     [CredentialProvider]Handling 'Request' 'GetAuthenticationCredentials'. Time elapsed in ms: 10 - Payload: {"Uri":"https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v3/index.json","IsRetry":false,"IsNonInteractive":true,"CanShowDialog":false}
[NuGet Manager] [Verbose]     [CredentialProvider]Creating a progress reporter with interval: 00:00:02
[NuGet Manager] [Verbose]     [CredentialProvider]Handling auth request, Uri: https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v3/index.json, IsRetry: False, IsNonInteractive: True, CanShowDialog: False
[NuGet Manager] [Verbose]     [CredentialProvider]URI: https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v3/index.json
[NuGet Manager] [Verbose]     [CredentialProvider]VstsBuildTaskServiceEndpointCredentialProvider - This credential provider must be run under the Team Build tasks for NuGet with external endpoint credentials. Appropriate environment variable needs to be set.
[NuGet Manager] [Verbose]     [CredentialProvider]Skipping NuGetCredentialProvider.CredentialProviders.VstsBuildTaskServiceEndpoint.VstsBuildTaskServiceEndpointCredentialProvider, cannot provide credentials for https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v3/index.json
[NuGet Manager] [Verbose]     [CredentialProvider]VstsBuildTaskCredentialProvider - This credential provider must be run under the Team Build tasks for NuGet. Appropriate environment variables must be set.
[NuGet Manager] [Verbose]     [CredentialProvider]Skipping NuGetCredentialProvider.CredentialProviders.VstsBuildTask.VstsBuildTaskCredentialProvider, cannot provide credentials for https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v3/index.json
[NuGet Manager] [Verbose]     [CredentialProvider]GET https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v3/index.json
[NuGet Manager] [Verbose]     [CredentialProvider]VstsCredentialProvider - Detected a hosted Azure DevOps Service.
[NuGet Manager] [Verbose]     [CredentialProvider]Using NuGetCredentialProvider.CredentialProviders.Vsts.VstsCredentialProvider to try to get credentials for https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v3/index.json.
[NuGet Manager] [Verbose]     [CredentialProvider]IsRetry: False
[NuGet Manager] [Verbose]     [CredentialProvider]Could not find cached SessionToken for https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v3/index.json
[NuGet Manager] [Verbose]     [CredentialProvider]GET https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v3/index.json
[NuGet Manager] [Verbose]     [CredentialProvider]Found AAD Authority from 401 headers: https://login.windows.net/8b3dd73e-4e72-4679-b191-56da1588712b
[NuGet Manager] [Verbose]     [CredentialProvider]VstsCredentialProvider - Using AAD authority: https://login.windows.net/8b3dd73e-4e72-4679-b191-56da1588712b
[NuGet Manager] [Verbose]     [CredentialProvider]VstsCredentialProvider - Attempting to acquire bearer token using provider 'ADAL Cache'
[NuGet Manager] [Verbose]     [CredentialProvider]VstsCredentialProvider - Bearer token provider 'ADAL Cache' didn't acquire a token
[NuGet Manager] [Verbose]     [CredentialProvider]VstsCredentialProvider - Attempting to acquire bearer token using provider 'ADAL Windows Integrated Authentication'
[NuGet Manager] [Warning] The plugin credential provider could not acquire credentials. Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
[2022-01-20 18:22:19.853] [Debug] [NuGetLogger] => [Execute]:   Unauthorized https://pkgs.dev.azure.com/<organization>/_packaging/59388b54-2798-4d11-b0d7-a731a1308e1e/nuget/v3/registrations2-semver2/<package>/index.json 680ms
Error: Failed to read package information from NuGet source https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v3/index.json.
[2022-01-20 18:22:19.884] [Debug] [NuGetLogger] => [Execute]: Details: System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at NuGet.Protocol.HttpSource.<>c__DisplayClass15_0`1.<<GetAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at NuGet.Common.ConcurrencyUtilities.ExecuteWithFileLockedAsync[T](String filePath, Func`2 action, CancellationToken token)
   at NuGet.Common.ConcurrencyUtilities.ExecuteWithFileLockedAsync[T](String filePath, Func`2 action, CancellationToken token)
   at NuGet.Protocol.HttpSource.GetAsync[T](HttpSourceCachedRequest request, Func`2 processAsync, ILogger log, CancellationToken token)
   at NuGet.Protocol.PackageMetadataResourceV3.LoadRegistrationIndexAsync(HttpSource httpSource, Uri registrationUri, String packageId, SourceCacheContext cacheContext, Func`2 processAsync, ILogger log, CancellationToken token)
   at NuGet.Protocol.PackageMetadataResourceV3.GetMetadataAsync(String packageId, Boolean includePrerelease, Boolean includeUnlisted, VersionRange range, SourceCacheContext sourceCacheContext, ILogger log, CancellationToken token)
   at NuGet.Protocol.PackageMetadataResourceV3.GetMetadataAsync(String packageId, Boolean includePrerelease, Boolean includeUnlisted, SourceCacheContext sourceCacheContext, ILogger log, CancellationToken token)
   at Microsoft.TemplateEngine.Edge.Installers.NuGet.NuGetApiPackageManager.GetPackageMetadataAsync(PackageSource source, String packageIdentifier, Boolean includePrerelease, CancellationToken cancellationToken).
[NuGet Manager] [Verbose]     [CredentialProvider]VstsCredentialProvider - Bearer token provider 'ADAL Windows Integrated Authentication' didn't acquire a token
[NuGet Manager] [Verbose]     [CredentialProvider]VstsCredentialProvider - Not running bearer token provider 'ADAL UI'
[NuGet Manager] [Verbose]     [CredentialProvider]VstsCredentialProvider - Not running bearer token provider 'ADAL Device Code'
Warning: <package> is not found in NuGet feeds https://api.nuget.org/v3/index.json, C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\, https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v3/index.json.
[NuGet Manager] [Verbose]     [CredentialProvider]VstsCredentialProvider - Could not obtain credentials for https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v3/index.json
[NuGet Manager] [Verbose]     [CredentialProvider]Unable to acquire credentials.
[NuGet Manager] [Verbose]     [CredentialProvider]Sending response: 'Request' 'GetAuthenticationCredentials'. Time elapsed in ms: 1553
[NuGet Manager] [Verbose]     [CredentialProvider]Time elapsed in milliseconds after sending response 'Request' 'GetAuthenticationCredentials': 1559
<package> could not be installed, the package does not exist.
[2022-01-20 18:22:19.924] [Debug] [Microsoft.TemplateEngine.Cli.CliTemplateEngineHost] => [Execute]: Execute finished, took 3724 ms

dotnet info:

.NET SDK (reflecting any global.json):
 Version:   6.0.101
 Commit:    ef49f6213a

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22000
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.101\

Host (useful for support):
  Version: 6.0.1
  Commit:  3a25a7f1cc

.NET SDKs installed:
  6.0.100 [C:\Program Files\dotnet\sdk]
  6.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
DavidKarlascommented, Mar 23, 2022

Sorry this slipped my mind, I will try to open PR against Provider this week…

1reaction
DavidKarlascommented, Apr 7, 2022

Just quick update, didn’t slip my mind this time… 😃 Here is the problem: NuGet/docs.microsoft.com-nuget#2715

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authorization in ASP.NET Core. Always 401 Unauthorized ...
I fixes mine by changing the UseAuthentication() and order of UseAuthentication() and UseRouting() in the Configure method on Startup class.
Read more >
Dotnet tool install 401 Unauthorized - Microsoft Q&A
I'm trying to install the "dotnet-reportgenerator-globaltool" tool via .Net Core custom task. Custom Command: tool Arguments: install ...
Read more >
Microsoft.AspNetCore.Authorization throws 401 ...
The Microsoft.AspNetCore.Authorization throws a 401 un authorized error when calling Http Put Method in the API. This works for HTTP Get. Error.
Read more >
dotnet new -i failes with 401 (unauthorized) when using ...
This was caused by an old Nuget.Config lying around in my c:\users folder. dotnet restore on other projects didn't pick this up so...
Read more >
401 Unauthorized: Consuming web api with JWT ...
When the request with the JWT is sent from the client to the server (Web Api), I then get the error message 401....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found