gpt4 book ai didi

c# - 授权 header 需要 'Credential'参数

转载 作者:行者123 更新时间:2023-12-04 06:55:30 27 4
gpt4 key购买 nike

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

{
"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>();
}

这是我们的客户端应用程序,它调用身份服务器的 token 端点来生成 token :
[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日志。

关于c# - 授权 header 需要 'Credential'参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48864306/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com