microsoft / artifacts-credprovider

The Azure Artifacts Credential Provider enables dotnet, NuGet.exe, and MSBuild to interactively acquire credentials for Azure Artifacts feeds.
MIT License
747 stars 709 forks source link

Credential provider is not working on new laptop #483

Closed vyruz1986 closed 4 months ago

vyruz1986 commented 4 months ago

I've been using this credential provider with various devices and Azure DevOps organisations/projects, never had problems with it.

Today I want to start using a new laptop, and went through the installation procedure for the credential provider as I've done several times, the installation was confirmed with a success message.

However, when I try to run dotnet restore --interactive in a repository which has a nuget.config file pointing to a private nuget feed from a devops project I"m a member of, the following happens:

  1. I get the message asking me to login through a device code
  2. I perform the login using the given device code, web page tells me I've authenticated successfully and browser can be closed
  3. Observation: Compared to other working scenarios, I DO NOT get an email telling me that a personal access token was added to my account
  4. nuget restore fails with 401 error for each package from the private feed.

I also observed that the $env:UserProfile\AppData\Local\MicrosoftCredentialProvider folder is NOT created.

What are the troubleshooting steps here, as I'm quite stuck with this :-(

embetten commented 4 months ago

Hi @vyruz1986 can you re-run the command with the --verbosity detailed and set the env varaibles: NUGET_PLUGIN_ENABLE_LOG, NUGET_CREDENTIALPROVIDER_LOG_PATH, NUGET_PLUGIN_LOG_DIRECTORY_PATH (see our readme and nuget docs for more info on these env variables) and send us the resulting logs so we can investigate further. Make sure to remove any PII data including tokens, ADO org/project /feed names. If there is an activity Id in the logs, please share that as well.

It is interesting that the cred provider is falling through to device code flow on a windows machine. Can you provide any context on the device or environment you are running the cred provider?

A couple troubleshooting steps to try in the meantime:

  1. triple check your permissions to the feed.
  2. Make sure you have navigated to the Azure Artifacts UI in the Azure DevOps portal for the org/project of the feed you are trying to authenticate to prior to running the cred provider. Azure DevOps requires this step.
vyruz1986 commented 4 months ago
  1. Make sure you have navigated to the Azure Artifacts UI in the Azure DevOps portal for the org/project of the feed you are trying to authenticate to prior to running the cred provider. Azure DevOps requires this step.

I didn't do this yesterday when I created this issue, I did afterwards for some reason but didn't think to try again after that. While I was going through the steps to get the requested debug logs, it just worked, and I realised that was my problem yesterday. So my problem is fixed, thanks!

It is interesting that the cred provider is falling through to device code flow on a windows machine. Can you provide any context on the device or environment you are running the cred provider?

I find this comment interesting, I've been using DevOps and this credential provider on Windows for years, and I've always had to use the device code method to authenticate myself, you're saying it's not supposed to do this? As opposed to directly initiating a browser login session?

I did notice that when authenticating against the same artifact repository using NPM (with the help of vsts-npm-auth) it did directly pop up a browser window and took me to through the login flow instead of using a device code.

embetten commented 4 months ago

Glad to hear that worked!

For the device code flow: ah you are running from dotnet - try setting the NUGET_CREDENTIALPROVIDER_FORCE_CANSHOWDIALOG_TO to true and see if that allows the browser authentication. That is assuming you prefer the browser to device code flow. More info on why dotnet and nuget have this as false even on interactive in a comment previous issue.

embetten commented 4 months ago

Closing. Since navigating to the Azure Artifacts Ui resolved the login issue.