- 创建了一个 .net 核心 AWS 无服务器应用程序。
- Cognito 用于进行身份验证。
- 已配置用户和应用程序客户端。
- 当我在本地运行解决方案时,它运行良好(记住它是 http)。
当我使用发布向导发布并使用
邮递员(https://myendpoint/Prod)点击新网址时,我立即得到:{“消息”:“禁止”}
我只能猜测这与这里的http / https有关。
身份验证控制器:
public class AuthenticationController : Controller
{
[HttpPost]
[Route("api/signin")]
public async Task<ActionResult<string>> SignIn(User user)
{
var cognito = new AmazonCognitoIdentityProviderClient(RegionEndpoint.APSoutheast2);
var request = new AdminInitiateAuthRequest
{
UserPoolId = "ap-southeast-2_MYPOOLID",
ClientId = "MYCLIENTID",
AuthFlow = AuthFlowType.ADMIN_USER_PASSWORD_AUTH
};
request.AuthParameters.Add("USERNAME", user.Username);
request.AuthParameters.Add("PASSWORD", user.Password);
var response = await cognito.AdminInitiateAuthAsync(request);
return Ok(response.AuthenticationResult);
}
}
启动.ConfigureServices
services.AddSingleton<IAuthorizationHandler, CognitoGroupAuthorisationHandler>();
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidIssuer = "https://cognito-idp.ap-southeast-2.amazonaws.com/ap-southeast-2_MYPOOL",
ValidateIssuerSigningKey = true,
ValidateIssuer = true,
ValidateLifetime = true,
ValidAudience = "MYKEY",
ValidateAudience = true
};
});
编辑#1 看来我解决了禁止的味精,但现在出现 500 错误。
邮递员产生:500 内部服务器错误
使用 API Gateway 进行测试(Api Gateway->Resources-> /{proxy+}->Any->Test->Post)
方法:POST Proxy 设置为:/api/signin 请求正文:
{
"username": "xxx",
"password":"yyy"
}
产量:
{"Strict-Transport-Security":"max-age=2592000","ErrorType":"AmazonCognitoIdentityProviderException","X-Amzn-Trace-Id":"Root=xxxxx;Sampled=0","Content-Type":""}