NuGet's "Force Authentication" with Virtual Repositories and Anonymous Access Enabled: Explained

Products
Frog_Artifactory
Content Type
Administration_Platform
AuthorFullName__c
Jeremy Leopold
articleNumber
000006509
FirstPublishedDate
2025-07-08T13:34:33Z
lastModifiedDate
2025-07-08

NuGet's "Force Authentication" with Virtual Repositories and Anonymous Access Enabled: Explained

Introduction

This article clarifies the resolution behavior of NuGet clients when interacting with Artifactory's virtual repositories, specifically focusing on the "Force Authentication" option. While this setting aims to ensure authenticated access, its interaction with client behavior and anonymous permissions has specific nuances that are important to understand for consistent results. We illustrate this behavior using direct NuGet client examples and demonstrate its consistency with other tools, such as the NuGet Restore Task in Azure DevOps Pipelines.

Understanding NuGet Client Behavior

To illustrate the expected behavior, we set up a local NuGet client and test it against an Artifactory instance.
  • Artifactory is configured with anonymous access enabled, granting the anonymous user permissions to "Any Remote."

    User-added image 
  • A virtual repository, jl-nuget, is created. This virtual repository aggregates jl-nuget-local and jl-nuget-remote. At this initial stage, the "Force Authentication" option is not enabled on jl-nuget.

    User-added image 
  • The NuGet client is then configured to use this virtual repository without providing credentials. A nuget install command for Newtonsoft.Json successfully runs. This shows that anonymous access to the remote repository (via the virtual repository) functions correctly:
 
 
cat ~/.config/NuGet/NuGet.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="Artifactory" value="http://localhost:8081/artifactory/api/nuget/v3/jl-nuget/index.json" allowInsecureConnections="True" />
  </packageSources>
</configuration>

nuget install Newtonsoft.Json
bash: warning: setlocale: LC_ALL: cannot change locale (he_IL.UTF-8)
Feeds used:
  http://localhost:8081/artifactory/api/nuget/v3/jl-nuget/index.json

Installing package 'Newtonsoft.Json' to '/home/jeremyl/simpleInstall'.
  GET http://<JFROG_HOST>:8082/artifactory/api/nuget/v3/jl-nuget/registration-semver2/newtonsoft.json/index.json
  OK http://<JFROG_HOST>:8082/artifactory/api/nuget/v3/jl-nuget/registration-semver2/newtonsoft.json/index.json 808ms
  GET http://<JFROG_HOST>:8082/artifactory/api/nuget/v3/jl-nuget/registration-semver2/newtonsoft.json/page/3.5.8/12.0.1-beta2.json
  OK http://<JFROG_HOST>:8082/artifactory/api/nuget/v3/jl-nuget/registration-semver2/newtonsoft.json/page/3.5.8/12.0.1-beta2.json 54ms
  GET http://<JFROG_HOST>:8082/artifactory/api/nuget/v3/jl-nuget/registration-semver2/newtonsoft.json/page/12.0.1/13.0.3.json
  OK http://<JFROG_HOST>:8082/artifactory/api/nuget/v3/jl-nuget/registration-semver2/newtonsoft.json/page/12.0.1/13.0.3.json 37ms

Attempting to gather dependency information for package 'Newtonsoft.Json.13.0.3' with respect to project '/home/jeremyl/simpleInstall', targeting 'Any,Version=v0.0'
Gathering dependency information took 24 ms
Attempting to resolve dependencies for package 'Newtonsoft.Json.13.0.3' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'Newtonsoft.Json.13.0.3'
Resolved actions to install package 'Newtonsoft.Json.13.0.3'
Retrieving package 'Newtonsoft.Json 13.0.3' from 'Artifactory'.
  GET http://<JFROG_HOST>:8082/artifactory/api/nuget/v3/jl-nuget/registration-semver2/Download/newtonsoft.json/13.0.3
  OK http://<JFROG_HOST>:8082/artifactory/api/nuget/v3/jl-nuget/registration-semver2/Download/newtonsoft.json/13.0.3 720ms
Installed Newtonsoft.Json 13.0.3 from http://localhost:8081/artifactory/api/nuget/v3/jl-nuget/index.json to /home/jeremyl/.nuget/packages/newtonsoft.json/13.0.3 with content hash HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==.
Adding package 'Newtonsoft.Json.13.0.3' to folder '/home/jeremyl/simpleInstall'
Added package 'Newtonsoft.Json.13.0.3' to folder '/home/jeremyl/simpleInstall'
Successfully installed 'Newtonsoft.Json 13.0.3' to /home/jeremyl/simpleInstall
Executing nuget actions took 1.39 sec
 
  • Next, we want to illustrate what happens when authentication is required. The NuGet cache is cleared, and "Force Authentication" is enabled on the virtual repository. When nuget install Newtonsoft.Json runs again, NuGet correctly prompts for credentials, indicating that the authentication challenge is presented and enforcement works when no credentials are initially provided:
 
 
nuget install Newtonsoft.Json
bash: warning: setlocale: LC_ALL: cannot change locale (he_IL.UTF-8)
Feeds used:
  http://localhost:8081/artifactory/api/nuget/v3/jl-nuget/index.json

Installing package 'Newtonsoft.Json' to '/home/jeremyl/simpleInstall'.
MSBuild auto-detection: using msbuild version '' from '/usr/bin'.
The remote server indicated that the previous request was forbidden. Please provide credentials for: http://localhost:8081/artifactory/api/nuget/v3/jl-nuget/index.json
UserName: 
The Core Principle: Client Interaction with "Force Authentication"

The key to understanding "Force Authentication" on a virtual repository that also allows anonymous access lies in how the client interacts with Artifactory's challenge mechanisms.
  • When a user accesses Artifactory via the WebUI, the session operates with that specific user's defined permissions (whether they are a logged-in user or the 'anonymous' user). This setup inherently provides a context for authorization.
  • In a CI/CD pipeline, NuGet (by default) first attempts to resolve packages anonymously if the virtual repository allows anonymous access. If it receives a successful anonymous response for the package metadata, it proceeds without attempting to send credentials. "Force Authentication" is designed to present an authentication challenge to the client. The disconnect arises because NuGet, by default, first attempts to resolve packages anonymously. If it successfully retrieves package metadata anonymously, it then proceeds without attempting to send credentials.
     
To further demonstrate this interaction, an additional test is performed:
  • "Force Authentication" is disabled on the virtual repository.
  • The contents of the remote cache are copied to a local repository (jl-nuget-local), making Newtonsoft.Json available there.
  • The remote repository is then taken offline.
  • "Force Authentication" is enabled only on jl-nuget-local (the local repository itself).
  • When the install runs again, the package is not found. This occurs because, even though the package is in the local repository, the anonymous user lacks permissions to access jl-nugwet-local. The NuGet client does not receive an authentication challenge against the virtual repository (because "Force Authentication" is off on the virtual repo), so it proceeds with an anonymous request, which then fails due to insufficient permissions at the local repository level:
 
nuget install Newtonsoft.Json
bash: warning: setlocale: LC_ALL: cannot change locale (he_IL.UTF-8)
Feeds used:
  http://localhost:8081/artifactory/api/nuget/v3/jl-nuget/index.json

Installing package 'Newtonsoft.Json' to '/home/jeremyl/simpleInstall'.
  GET http://<JFROG_HOST>:8082/artifactory/api/nuget/v3/jl-nuget/registration-semver2/newtonsoft.json/index.json
  NotFound http://<JFROG_HOST>:8082/artifactory/api/nuget/v3/jl-nuget/registration-semver2/newtonsoft.json/index.json 27ms
Unable to find package 'Newtonsoft.Json'

artifactory-request.log
2025-06-10T10:19:23.667Z|71053b0fa76109e0|<IP>|anonymous|GET|/api/nuget/v3/jl-nuget/registration-semver2/newtonsoft.json/index.json|404|-1|69|23|NuGet Command Line/6.14.0 (LINUX)


Conversely, when "Force Authentication" is enabled on the virtual repository, and NuGet is configured with credentials, the following behavior is observed: 
cat ~/.config/NuGet/NuGet.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="ArtiAuth" value="http://localhost:8081/artifactory/api/nuget/v3/jl-nuget/index.json" allowInsecureConnections="True" />
  </packageSources>
  <packageSourceCredentials>
    <ArtiAuth>
      <add key="Username" value="admin" />
      <add key="Password" value="<ref-token>" />
    </ArtiAuth>
  </packageSourceCredentials>
</configuration>
 
    • NuGet first sends an anonymous request, which is met with a 401 (unauthorized) response from the virtual repository:
2025-06-10T16:52:04.986Z|5f57c1b452d9ca30|<IP>|anonymous|GET|/api/nuget/v3/jl-nuget/registration-semver2/newtonsoft.json/index.json|401|-1|77|9|NuGet Command Line/6.14.0 (LINUX)
 
    • NuGet then automatically sends a subsequent request with credentials, and the user is successfully authenticated against the virtual repository, allowing resolution:
2025-06-10T16:52:05.110Z|5775ed26ac400592|<IP>|admin|GET|/api/nuget/v3/jl-nuget/registration-semver2/newtonsoft.json/index.json|200|-1|308|121|NuGet Command Line/6.14.0 (LINUX)
    • It's important to note that NuGet's requests go to the virtual repository. During artifact resolution, Artifactory determines which underlying repositories the user has authorization to access, based on the configured permissions.
       
Consistency Across Tools: The Azure DevOps Pipeline Example
The behavior observed with the NuGet CLI is consistent across various tools used to access the virtual repository. For example, the NuGet Restore task within Azure DevOps Pipelines demonstrates this same interaction.
  • Below is an ADO(Azure DevOps) Pipeline snippet illustrating a request to the virtual repository when the Service Connection is configured with an authenticated user, but "Force Authentication" is not enabled on the virtual repository (which allows anonymous user access):
Starting: JFrogNuGet
==============================================================================
Task         : JFrog Nuget
Description  : Restore and push NuGet packages from and to Artifactory while allowing to collect build-info. The collected build-info can be later published to Artifactory by the "JFrog Publish Build Info" task.
Version      : 1.11.0
Author       : JFrog
Help         : [More Information](https://github.com/jfrog/jfrog-azure-devops-extension#JFrog-Nuget-and-NET-Core-Task)
==============================================================================
Found tool in cache: jf 2.76.1 x64
Running jfrog-cli from C:\Users\***\Desktop\agent\_work\_tool\jf\2.76.1\x64\jf.exe
JFrog CLI version: 2.76.1
Executing JFrog CLI Command:
C:\Users\***\Desktop\agent\_work\_tool\jf\2.76.1\x64\jf.exe c add "***-972.nuget-test-project_20250611.4_nuget_resolver_1749675436755" --artifactory-url="https://localhost/artifactory" --interactive=false --user="***" --basic-auth-only --password-stdin
Executing JFrog CLI Command:
C:\Users\***\Desktop\agent\_work\_tool\jf\2.76.1\x64\jf.exe c use "***-972.nuget-test-project_20250611.4_nuget_resolver_1749675436755"
20:57:17 [Info] Using server ID '***-972.nuget-test-project_20250611.4_nuget_resolver_1749675436755' (https://localhost/artifactory/)
Executing JFrog CLI Command:
C:\Users\***\Desktop\agent\_work\_tool\jf\2.76.1\x64\jf.exe nugetc --server-id-resolve="***-972.nuget-test-project_20250611.4_nuget_resolver_1749675436755" --repo-resolve="***-nuget"
20:57:17 [Info] nuget build config successfully created.
Executing JFrog CLI Command:
C:\Users\***\Desktop\agent\_work\_tool\jf\2.76.1\x64\jf.exe nuget restore -NoCache -PackagesDirectory "C:\\Users\\***\\Desktop\\agent\\_work\\1\\s" -Verbosity "Detailed"
20:57:17 [Info] Running nuget...
NoCache is deprecated and has been renamed to NoHttpCache. Please use NoHttpCache instead.
NuGet Version: 6.14.0.116
Restoring NuGet packages for solution C:\Users\***\Desktop\agent\_work\1\s\MySolution.sln.
MSBuild auto-detection: using msbuild version '17.14.10.27608' from 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
MSBuild P2P timeout [ms]: 120000
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\msbuild.exe "C:\Users\***\AppData\Local\Temp\NuGetScratch\2u3btp13.3bo.nugetinputs.targets" /t:GenerateRestoreGraphFile /nologo /nr:false /v:q /p:NuGetPropsFile="C:\Users\***\AppData\Local\Temp\NuGetScratch\hwkcq3ua.m1b.nugetrestore.props" /p:NuGetRestoreTargets="C:\Users\***\AppData\Local\Temp\NuGetScratch\uhsjg3ov.yb1.nugetrestore.targets" /p:RestoreUseCustomAfterTargets="True" /p:DisableCheckingDuplicateNuGetItems="True" /p:RestoreTaskAssemblyFile="C:\Nuget\nuget.exe" /p:RestoreSolutionDirectory="C:\Users\***\Desktop\agent\_work\1\s\\" /p:RestoreConfigFile="C:\Users\***\AppData\Local\Temp\jfrog.cli.temp.-1749675437-2851209394\jfrog.cli.nuget.3634930605" /p:RestorePackagesPath="C:\\Users\\***\\Desktop\\agent\\_work\\1\\s" /p:SolutionDir="C:\Users\***\Desktop\agent\_work\1\s\\" /p:SolutionName="MySolution"

Running restore with 4 concurrent jobs.
Reading project file C:\Users\***\Desktop\agent\_work\1\s\MyProject\MyProject.csproj.
The restore inputs for 'MyProject' have changed. Continuing restore.
Restoring packages for C:\Users\***\Desktop\agent\_work\1\s\MyProject\MyProject.csproj...
  GET https://localhost/artifactory/api/nuget/v3/***-nuget/registration-semver2/newtonsoft.json/index.json
  OK https://localhost/artifactory/api/nuget/v3/***-nuget/registration-semver2/newtonsoft.json/index.json 139ms
  GET https://localhost/artifactory/api/nuget/v3/***-nuget/registration-semver2/newtonsoft.json/page/3.5.8/12.0.1-beta2.json
  GET https://localhost/artifactory/api/nuget/v3/***-nuget/registration-semver2/newtonsoft.json/page/12.0.1/13.0.3.json
  OK https://localhost/artifactory/api/nuget/v3/***-nuget/registration-semver2/newtonsoft.json/page/3.5.8/12.0.1-beta2.json 67ms
  OK https://localhost/artifactory/api/nuget/v3/***-nuget/registration-semver2/newtonsoft.json/page/12.0.1/13.0.3.json 95ms
  GET https://localhost/artifactory/api/nuget/v3/***-nuget/registration-semver2/Download/newtonsoft.json/13.0.3
  OK https://localhost/artifactory/api/nuget/v3/***-nuget/registration-semver2/Download/newtonsoft.json/13.0.3 50ms
Acquiring lock for the installation of Newtonsoft.Json 13.0.3
Acquired lock for the installation of Newtonsoft.Json 13.0.3
PackageSignatureVerificationLog: PackageIdentity: Newtonsoft.Json.13.0.3 Source: https://localhost/artifactory/api/nuget/v3/***-nuget/index.json PackageSignatureValidity: True
Installed Newtonsoft.Json 13.0.3 from https://localhost/artifactory/api/nuget/v3/***-nuget/index.json to C:\Users\***\Desktop\agent\_work\1\s\newtonsoft.json\13.0.3 with content hash HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==.
All packages and projects are compatible with net9.0.
Committing restore...
Generating MSBuild file C:\Users\***\Desktop\agent\_work\1\s\MyProject\obj\MyProject.csproj.nuget.g.props.
Writing assets file to disk. Path: C:\Users\***\Desktop\agent\_work\1\s\MyProject\obj\project.assets.json
Writing cache file to disk. Path: C:\Users\***\Desktop\agent\_work\1\s\MyProject\obj\project.nuget.cache
Persisting dg to C:\Users\***\Desktop\agent\_work\1\s\MyProject\obj\MyProject.csproj.nuget.dgspec.json
Restored C:\Users\***\Desktop\agent\_work\1\s\MyProject\MyProject.csproj (in 3.07 sec).

NuGet Config files used:
    C:\Users\***\AppData\Local\Temp\jfrog.cli.temp.-1749675437-2851209394\jfrog.cli.nuget.3634930605

Feeds used:
    https://localhost/artifactory/api/nuget/v3/***-nuget/index.json

Installed:
    1 package(s) to C:\Users\***\Desktop\agent\_work\1\s\MyProject\MyProject.csproj
20:57:24 [Info] nuget finished successfully.
Executing JFrog CLI Command:
C:\Users\***\Desktop\agent\_work\_tool\jf\2.76.1\x64\jf.exe c remove "***-972.nuget-test-project_20250611.4_nuget_resolver_1749675436755" --quiet
Finishing: JFrogNuGet
Despite the configured user in the Service Connection, the initial request for Newtonsoft.Json is made by the anonymous user. Behind the scenes, the package is resolved successfully from the remote-cache repository, because there is no authentication check on the virtual and the anonymous user is authorized for the remote-cache:
2025-06-11T20:57:22.338Z|6a6105d9c44fb4372c2118e7721a20b4|<IP>|anonymous|GET|/api/nuget/v3/jeremyl-nuget/registration-semver2/newtonsoft.json/index.json|200|-1|589|42|NuGet Command Line/6.14.0 (WINDOWS)
 
  • If "Force Authentication" is enabled on the virtual repository, NuGet sends the first request against the virtual, which is met by the authentication challenge (returning a 401). A second attempt is then made with the user credentials configured in the Service Connection, leading to successful resolution:
2025-06-11T21:14:21.049Z|b965bafbf074c3cfe285b672d85b3bbb|<IP>|non_authenticated_user|GET|/api/nuget/v3/jeremyl-nuget/registration-semver2/newtonsoft.json/index.json|401|-1|0|1|NuGet Command Line/6.14.0 (WINDOWS)

2025-06-11T21:14:21.190Z|c480bc05db2bb332988dd300c8a30e04|<IP>|jeremyl|GET|/api/nuget/v3/jeremyl-nuget/registration-semver2/newtonsoft.json/index.json|200|-1|589|120|NuGet Command Line/6.14.0 (WINDOWS)
 
  • Ultimately, any attempts to the virtual repository by an anonymous user will be denied if "Force Authentication" is enabled.

     
Conclusion

Based on the above, when "Force Authentication" is enabled on a virtual repository, direct anonymous access to that virtual is denied; the client must provide credentials. Conversely, if "Force Authentication" is not enabled on the virtual repository, and the virtual permits anonymous access, an unauthenticated client request will not receive an authentication challenge from the virtual itself. Therefore, any underlying aggregated local repositories that require authentication cannot be accessed through such a virtual via an unauthenticated request. Authentication for such underlying repositories must be managed by enabling "Force Authentication" on the virtual, which then prompts the client for credentials to satisfy the access requirements.

Our official recommendation is to:
  • Maintain two virtual repositories: one with "Force Authentication" enabled for authenticated builds and internal workflows, and another without "Force Authentication" for anonymous access where appropriate.
This approach ensures clear separation and consistent behavior based on your access requirements.