【发布时间】:2020-04-19 01:20:58
【问题描述】:
我创建了一个针对 Cognito 进行身份验证的 ASP .Net Core 应用程序。
我的身份验证控制器如下所示:
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);
}
}
Startup.ConfigureServices 看起来像:
services.AddAuthentication("Bearer")
.AddJwtBearer(options =>
{
options.Audience = "client key";
options.Authority = "https://cognito-idp.ap-southeast-2.amazonaws.com/ap-southeast-poolid";
});
如果这是我在上面所做的事情,我已将其包含在内。
我的不记名令牌工作正常。我针对 Cognito 进行身份验证并获取我的访问/ID/刷新令牌。 作为 Cognito 和 AWS 的新手并且很好奇,我在 https://jwt.io/ 运行我的令牌,发现它们包含我的 poolId 和 clientId。我的印象是这些东西要以最安全的方式隐藏起来。
这是正常的还是我做过的事情。我觉得也许这不应该那么容易暴露?
【问题讨论】:
标签: amazon-web-services jwt amazon-cognito jwt-auth