我正在尝试在asp.net Core 2上登录用户服务器端
我已注册用户并通过验证链接确认,但现在我很难将该用户签入我的应用程序。令人遗憾的是,c#的文档太差了!
用户池配置:
App Client :为基于服务器的身份验证启用登录API(ADMIN_NO_SRP_AUTH) - 已选中
以下是代码:
public async Task<bool> SignInUserAsync(CognitoUser user)
{
var provider = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(),
RegionEndpoint.GetBySystemName("eu-west-2"));
try
{
var authReq = new AdminInitiateAuthRequest
{
AuthFlow = AuthFlowType.ADMIN_NO_SRP_AUTH,
UserPoolId = _poolId,
ClientId = _clientId
};
authReq.AuthParameters.Add("USERNAME", user.Email);
authReq.AuthParameters.Add("PASSWORD", user.Password);
AdminInitiateAuthResponse authResp = await provider.AdminInitiateAuthAsync(authReq);
return true;
}
catch
{
return false;
}
}
返回的错误是Missing Authentication Token
,但我无法确定需要设置令牌的位置。
是否符合我的AmazonCognitoIdentityProviderClient
设置或
AWS > User Pools > App Intergration > App Client Settings
?
答案 0 :(得分:0)
AdminInitiateAuth API旨在从后端调用,可以访问开发人员IAM凭据。由于您尝试使用AnonymousAWSCredentials
进行调用,因此出现Missing Authentication Token
错误。
Cognito用户池尚未对C#提供原生支持。您应该使用hosted auth pages而不是本机API调用在您的C#应用中集成Cognito用户池。
答案 1 :(得分:0)
尝试将您的提供者更改为:
var provider = new AmazonCognitoIdentityProviderClient();