macOS: GSSAPI operation failed on Nuget restore

When restoring packages from a remote on-prem Nuget repository on macOS, you may run into either one of the following error messages:

GSSAPI operation failed with error - An unsupported mechanism was requested
Unable to load the service index for source https://tfs.partner.com/DefaultCollection/_packaging/Nuget/nuget/v3/index.json

As covered in this old, but unresolved ticket, the problem usually stems from incorrect auth handling when downgrading the mode of authentication (e.g from Kerberos to Basic).

To work around the issue you need to:

  1. generate a personal acess token (PAT) that gives you rights to the given service;
  2. configure your Nuget.config to use the PAT for authentication using Basic auth:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <packageSources>
            <add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
            <add key="Partner" value="https://tfs.partner.com/DefaultCollection/_packaging/Nuget/nuget/v3/index.json" />
        </packageSources>
        <packageSourceCredentials>
            <Partner> 
                <add key="Username" value="USERNAME" />
                <add key="ClearTextPassword" value="PATSTRING" />
                <add key="ValidAuthenticationTypes" value="basic" /> 
            </Partner>
        </packageSourceCredentials>
    </configuration>
    
  3. clear the cache and restore the packages using the old HTTP client:

    cd repo
    nuget locals -clear all && export DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0 && nuget restore