【问题标题】:Fail to push nuget package. "nuget push" command not working after authorization added to nuget server推送 nuget 包失败。将授权添加到 nuget 服务器后,“nuget push”命令不起作用
【发布时间】:2016-12-07 15:06:31
【问题描述】:

我按照本指南为我的 nuget-server 设置了授权: http://blog.fermium.io/nuget-server-with-basic-authentication/

对于我正在使用的完整授权解决方案,您可以在此处找到它: https://github.com/devbridge/AzurePowerTools/tree/master/Devbridge.BasicAuthentication

它工作正常,当我浏览到我的 nuget 服务器时,我会被提示登录,到目前为止它工作正常。我还可以通过在 Visual Studio 中输入用户名/密码来访问我现有的 nuget 包。

在尝试从 Visual Studio 推送 nuget 包时出现问题,该包在将授权添加到 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 -详细信息

请提供以下凭据:http://mynuget.azurewebsites.net/

System.InvalidOperationException:无法在非交互模式下提示输入。

我该如何解决这个问题?

【问题讨论】:

  • 你是否在 web.config 文件中将“requireApiKey”设置为“flase”?
  • 在 web.config 中的 nuget-server 上没有,我将 requireApiKey 设置为 true,并且工作正常。 (并且推送时会传递apiKey)

标签: visual-studio-2015 authorization nuget nuget-package nuget-server


【解决方案1】:

当我在 Visual Studio 包管理器控制台窗口中运行相同的推送命令时,我得到了同样的错误。因为 Package Manager Console 窗口是非交互模式窗口,在它运行命令时我们不能输入任何参数。

所以我建议你使用命令提示符窗口推送包并运行 nuget push 命令。

【讨论】:

  • 谢谢!我仍然认为我会在下面使用我的解决方案,直到找到更容易的方法。我喜欢在 Visual Studio 中使用复制粘贴(推送/打包)命令来执行此操作。 (包管理器控制台)
【解决方案2】:

我还没有找到最佳解决方案,但我提出了一种可能对某人有所帮助的解决方法。尽管如此,仍在寻找更清洁和更好的解决方案。我最终允许未经授权的 PUT 命令,因为它仍然需要 ApiKey 来推送包。 (见下文)

    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);
        }
    }

从这里: https://github.com/devbridge/AzurePowerTools/tree/master/Devbridge.BasicAuthentication

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-04
    • 2015-09-13
    相关资源
    最近更新 更多