0
votes

I followed this guide to setup athorization to my nuget-server: http://blog.fermium.io/nuget-server-with-basic-authentication/

For the full authorization solution that I am using you can find it here: https://github.com/devbridge/AzurePowerTools/tree/master/Devbridge.BasicAuthentication

It works fine and when surfing to my nuget-server I get promted to login and it works fine so far. I can also access my existing nuget packages by enter username/password in visual studio.

The problem comes when trying to push a nuget-package from visual studio which worked fine before authorization was added to the nuget-server.

nuget.config (%AppData%\NuGet\NuGet.config)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
    <add key="mynuget" value="http://mynuget.azurewebsites.net/nuget" />
  </packageSources>
    <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
  <packageSourceCredentials>
    <mynuget>
      <add key="Username" value="mynugetUsername" />
      <add key="ClearTextPassword" value="mynugetPassword" />
    </mynuget>
  </packageSourceCredentials>
</configuration>

nuget push c:\temp\Packages*.nupkg -s http://mynuget.azurewebsites.net/ apikey -Verbosity detail

Please provide credentials for: http://mynuget.azurewebsites.net/

System.InvalidOperationException: Cannot prompt for input in non-interactive mode.

How can I solve this?

2
Did you set "requireApiKey" to "flase" in the web.config file?Eddie Chen - MSFT
No on the nuget-server in web.config I have requireApiKey set to true and that is working just fine. (And the apiKey is passed along when pushing)Sgedda

2 Answers

1
votes

When I run the same push command in Visual Studio Package Manager Console window, I get the same error. Because the Package Manager Console window is non-interactive mode window, which we could not type any parameters when it running command.

So I suggest you push package with Command Prompt window and run the nuget push command.

0
votes

I have not found an optimal solution to this but I have made one workaround that might be of help to someone. Still looking for a cleaner and better solution though. I ended up allowing PUT commands without authorization since it still needs the ApiKey to push packages. (see below)

    public void AuthenticateUser(Object source, EventArgs e)
    {
        var context = ((HttpApplication)source).Context;
        if (context.Request.HttpMethod != "PUT")
        {
            string authorizationHeader = context.Request.Headers[HttpAuthorizationHeader];

            // Extract the basic authentication credentials from the request
            string userName = null;
            string password = null;
            if (!this.ExtractBasicCredentials(authorizationHeader, ref userName, ref password))
            {
                return;
            }

            // Validate the user credentials
            if (!this.ValidateCredentials(userName, password))
            {
                return;
            }
        }

        // check whether cookie is set and send it to client if needed
        var authCookie = context.Request.Cookies.Get(AuthenticationCookieName);
        if (authCookie == null)
        {
            authCookie = new HttpCookie(AuthenticationCookieName, "1") { Expires = DateTime.Now.AddHours(1) };
            context.Response.Cookies.Add(authCookie);
        }
    }

From this: https://github.com/devbridge/AzurePowerTools/tree/master/Devbridge.BasicAuthentication