我正在使用AWS Cognito进行身份验证,并为移动(Xamarin.Forms)和Web(Blazor Webassembly)构建了相同的服务。
当我尝试注册已经注册的用户时,它应该抛出AliasExistsException
或UsernameExistsException
,它可以在Xamarin和小型Win32-ConsoleApp中进行测试,但是在Blazor上会发生无法捕获的Http-400例外。
这是我的代码:
public async Task Register()
{
// here the variables are defined, omitted for brevity
try
{
var signUpRequest = new SignUpRequest()
{
Username = username,
Password = password,
ClientId = clientId,
UserAttributes = CognitoAuthHelper.CreateAttributeList(userAttributes),
ValidationData = null,
SecretHash = CognitoAuthHelper.GetUserPoolSecretHash(username, clientId, clientSecret)
};
var signUpResponse = await client.SignUpAsync(signUpRequest).ConfigureAwait(false);
}
catch (AliasExistsException)
{
CognitoResult = new CognitoResult(CognitoResultType.UserNameAlreadyUsed);
}
catch (UsernameExistsException)
{
CognitoResult = new CognitoResult(CognitoResultType.EmailAlreadyUsed);
}
catch (Exception exc)
{
Console.WriteLine(exc);
}
}
Chrome控制台会打印以下内容:
mono.js:1 Fetch finished loading: OPTIONS "https://cognito-idp.eu-central-1.amazonaws.com/".
_mono_wasm_invoke_js_with_args @ mono.js:1
(anonymous)
...
(anonymous)
Module._mono_wasm_invoke_method @ mono.js:1
callMethod @ blazor.webassembly.js:1
beginInvokeDotNetFromJS @ blazor.webassembly.js:1
u @ blazor.webassembly.js:1
e.invokeMethodAsync @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
t.dispatchEvent @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
e.onGlobalEvent @ blazor.webassembly.js:1
Show 99 more frames
cognito-idp.eu-central-1.amazonaws.com/:1 POST https://cognito-idp.eu-central-1.amazonaws.com/ 400
有什么建议吗?也许这也是一个mono.js
问题?