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

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"?>
            <add key="NuGet official package source" value="" />
            <add key="Partner" value="" />
                <add key="Username" value="USERNAME" />
                <add key="ClearTextPassword" value="PATSTRING" />
                <add key="ValidAuthenticationTypes" value="basic" /> 
  3. clear the cache and restore the packages using the old HTTP client:

    cd repo
    nuget locals -clear all
    nuget restore