【问题标题】:Authorization header requires 'Credential' parameter授权标头需要“凭据”参数
【发布时间】:2018-07-29 13:52:48
【问题描述】:

我们将 Identity Server4 与 .NET Core 一起使用,并将应用程序部署为 AWS Serverless lambda 函数。当调用令牌端点生成访问令牌时,我们收到以下错误消息:

{
"message": "Authorization header requires 'Credential' parameter. Authorization header requires 'Signature' parameter. Authorization header requires 'SignedHeaders' parameter. Authorization header requires existence of either a 'X-Amz-Date' or a 'Date' header. Authorization=Basic Y2xpZW50OnNlY3JldA=="

}

这是 Identity Server 应用程序中的 ConfigurationServices 方法:

 public void ConfigureServices(IServiceCollection services)
    {
        services.AddSingleton<IConfiguration>(Configuration);

        //connection string
        string connectionString = Configuration.GetConnectionString("IdentityServer");

        var rsaProvider = new RSACryptoServiceProvider(2048);

        SecurityKey key = new RsaSecurityKey(rsaProvider);

        var credentials = new Microsoft.IdentityModel.Tokens.SigningCredentials
              (key, SecurityAlgorithms.RsaSha256Signature);


        var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

        services.AddIdentityServer()
           .AddSigningCredential(credentials)
            // this adds the config data from DB (clients, resources)
            .AddConfigurationStore(options =>
            {
                options.ConfigureDbContext = builder =>
                builder.UseSqlServer(connectionString,
                sql => sql.MigrationsAssembly(migrationsAssembly));
            }) // this adds the operational data from DB (codes, tokens, consents)
            .AddOperationalStore(options =>
            {
                options.ConfigureDbContext = builder =>
                builder.UseSqlServer(connectionString,
            sql => sql.MigrationsAssembly(migrationsAssembly));

                // this enables automatic token cleanup. this is optional.
                 options.EnableTokenCleanup = true;
                 options.TokenCleanupInterval = 30;
            });

        // Add S3 to the ASP.NET Core dependency injection framework.
        services.AddAWSService<Amazon.S3.IAmazonS3>();
    }

这是我们的客户端应用程序,它调用身份服务器的令牌端点来生成令牌:

[HttpGet]
    public async Task<IActionResult> Get(string client, string secret)
    {

        IActionResult result = null;

        //discover endpoints from metadata

        //var disco = await DiscoveryClient.GetAsync("http://localhost:3000/");

        var disco = await DiscoveryClient.GetAsync("hide for security reasons/");

        if (disco.IsError)
        {
            result = NotFound(disco.Error);

            return result;
        }
        //request token

        var tokenClient = new TokenClient(disco.TokenEndpoint, client, secret);

        var tokenResponse = await tokenClient.RequestClientCredentialsAsync(scope: "sup");

        if (tokenResponse.IsError)
        {
            result = NotFound(tokenResponse.Error);
        }

        result = Ok(tokenResponse.Json);

        return result;
    }

【问题讨论】:

  • 您有发送的原始请求的详细信息吗?
  • 嗨@mackie,问题已解决。实际上我将 lambda 函数部署为 GET http 方法,但是当我们调用令牌端点时,它实际上是 POST 请求。因此,当我更改 lambda 函数的 http 方法时,它的工作原理。 :)

标签: c# identityserver4


【解决方案1】:

我遇到的问题是粘贴的 URL 包含换行符或其他一些不可见的字符不匹配

【讨论】:

    【解决方案2】:

    我在尝试curl 一个端点(*)时遇到了这个错误:

    curl -XGET -u user:password <host-url>
    

    问题是我传递了错误的凭据。


    (*) 旁注:我尝试搜索托管在 AWS 上的 Elasticsearch 集群。

    【讨论】:

      【解决方案3】:

      以防万一其他人进入这里,这发生在我身上,因为我的网址路径中有一个错字

      当我纠正我的错字时,一切都对我有用。

      迷你上下文:我很困惑,因为我为我的 API 网关资源使用了 Lambda 授权方,而且我什至没有看到任何针对该 Lambda 的 Cloudwatch 日志。

      【讨论】:

      • 对我来说这是因为我在卷曲之前忘记部署
      • 先生,你真是救世主。
      • 好吧,我也在这里寻找相同的答案。原来是我的 HTTP 动词错误,而不是 URL。以后当我忘记并再次谷歌时对我来说......
      • 希望我能在两个小时前搜索到这个。 AWS 给出了正确的信息:|
      • 我的错误原因:api.example.com/stage/endpoint 不是要使用的 URL。相反,正确的 URL 是 api.example.com/endpoint,因为已在 API 映射中指定了阶段。我的上下文是我正在为我的 api 网关端点使用自定义域名。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 2019-04-30
      • 1970-01-01
      • 2019-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多