我们将 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;
}
以防万一其他人来到这里,这种情况发生在我身上,因为我的 URL 路径中有一个 拼写错误。
当我更正我的拼写错误时,一切都对我有用。
迷你上下文:我很困惑,因为我为 API 网关资源使用 Lambda 授权方,而且我什至没有看到任何针对该 Lambda 的 Cloudwatch 日志。
我遇到的问题是粘贴包含换行符或其他不可见字符不匹配的 URL
我在尝试
curl
端点(*)时遇到此错误:
curl -XGET -u user:password <host-url>
问题是我传递了错误的凭据。
(*) 旁注:我尝试搜索 AWS 上托管的 Elasticsearch 集群。
就我而言,我发现 AWS API Gateway 中的 URL 路径区分大小写。
希望这个答案可以帮助像我一样陷入这个问题的人。
我最近也遇到了同样的问题!我配置了一个 Lambda 函数并将其连接到 API 网关中的路由(资源)。但是,由于我的请求有一个名为
"Authorization"
的标头参数,当我尝试访问 API 网关 (api.gateway.UrlExample.com/stage/endpoint) 生成的路由时,我遇到了问题 ("Authorization header requires 'Credential' parameter"
)。
这是我解决的方法: 在 AWS 控制台中,API 网关的资源屏幕中:
等待几分钟,然后再次尝试发出请求!
如果您使用邮递员访问 API 网关端点。您可能会在邮递员中收到此错误。当您尝试传递 id 令牌或访问令牌时,它会特别发生。
因此要解决此问题,您需要使用 AWS-Amplify 签署您的请求。