authentication - .NET Core Web 应用程序的 Cognito 身份验证
问题描述
我对使用 AWS Cognito 有点陌生,但我在这里找到了一个非常方便的教程,用于将用户身份验证到 .NET Core Web 应用程序
但是....我的要求之一是使用自定义登录屏幕,而不是托管的。
由于这个非常有用的页面,我尝试使用 AWS Amplify JS 库并取得了一些成功(即我可以连接它并进行身份验证):
https://arcoirislabs.medium.com/aws-amplify-in-vanilla-javascript-6c4d8b3f29b0
问题是我在尝试合并这两个解决方案时遇到问题。我相信托管方法(第一个链接)设置 cookie 以启用身份验证,因为它使用以下内容:
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(options =>
{
options.ResponseType = Configuration["Authentication:Cognito:ResponseType"];
options.MetadataAddress = Configuration["Authentication:Cognito:MetadataAddress"];
options.ClientId = Configuration["Authentication:Cognito:ClientId"];
options.SaveTokens = true;
});
我想弄清楚的是如何使用 Amplify 库来设置正确的 cookie,以便上述授权配置与我的 .NET 项目正常工作。
以下是调用 Amplify 库进行登录的相关代码:
function signIn() {
var email = document.getElementById("email").value;
var pass = document.getElementById("pwd").value;
try {
const user = aws_amplify.Amplify.Auth.signIn(
email, pass
);
console.log(user);
alert("Signed In. Check Console")
} catch (error) {
console.log('error signing in', error);
alert("Error signing in. Check Console")
}
}
我认为这应该很简单,但不幸的是,我简单的大脑在这里没有看到解决方案。如果有人能提供答案,我将永远感激不尽。
谢谢
蒂姆
解决方案
推荐阅读
- amazon-web-services - 将 CodeBuild 工件文件获取到根文件夹,同时保留子文件夹树
- javascript - React hook stale 关闭:setState 仅在订阅的回调函数中触发两次
- node.js - 如何将 DNS 响应发送回客户端
- business-objects - 如何通过 REST API 使用 SAP BO Web 智能导出完整数据 CSV?
- integration-testing - 如何将 go 的 TestMain 与 terratest 一起使用?
- postgresql - PostgreSQL 触发函数来捕获更新的字段
- android - 无法将分隔符视图膨胀到 Radiogroup 中
- jenkins - 将变量传递给jenkins yaml podTemplate
- spring-boot - Spring Security 5 和 OAuth2 - 避免 HTTP 调用
- python-3.x - 如何加密pyaes包中的纯文本?