授权标头需要“ Credential”参数

Rak*_*mar 3 identityserver4

我们将Identity Server4与.NET Core结合使用,并将该应用程序部署为AWS无服务器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=="
Run Code Online (Sandbox Code Playgroud)

}

这是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>();
    }
Run Code Online (Sandbox Code Playgroud)

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

[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;
    }
Run Code Online (Sandbox Code Playgroud)

Hey*_*his 5

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

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

小型上下文:我很困惑,因为我为我的API网关资源使用了Lambda授权者,而我什至看不到任何东西可以到达该Lambda的Cloudwatch日志。

  • 先生,您简直就是救世主。 (4认同)
  • 对我来说,这是因为我忘记在卷曲之前部署 (2认同)
  • 好吧,我也在这里寻找相同的答案。结果是我的 HTTP 动词错误,而不是 URL。对我来说,当我忘记并再次谷歌时...... (2认同)
  • 希望我两小时前就搜索到了这个。AWS 给出了正确的信息就这么多了:| (2认同)
  • 我的错误原因:`api.example.com/stage/endpoint` 不是要使用的 URL。相反,正确的 URL 是“api.example.com/endpoint”,因为该阶段已在 API 映射中指定。我的上下文是我正在为我的 api 网关端点使用自定义域名。 (2认同)
  • 我也是!错过了基本路径的一部分。嘿 AWS,下次简单的 404 怎么样,smh。 (2认同)