amazon-web-services - 如何在不使用托管 UI 的情况下将 Cognito 用作 OAuth Flow?
问题描述
我以前在这里看到过一些类似的问题,但我一个都听不懂。如何在不使用 Cognito 中的托管 UI 的情况下从 OAuth 2 身份验证流程中获取代码?
我看到托管调用了一个 javascript 函数,但我不明白它是如何工作的并返回代码。
有什么方法可以调用 API 直接传递用户凭据并生成此代码?
解决方案
文档对此非常不利 - 但我使用 customProvider 作为属性让它工作
Auth.federatedSignIn({customProvider: "YOUR_CUSTOM_PROVIDER"})
根据: https ://github.com/aws-amplify/amplify-js/blob/a047ce73/packages/auth/src/types/Auth.ts#L74
基于 AWS 教程的整个函数将是:
Auth.federatedSignIn(
{customProvider: "YOUR_CUSTOM_PROVIDER"}
).then(cred => {
// If success, you will get the AWS credentials
console.log(cred);
this.setState({
isAuthorized:true
})
this.login()
}).then(user => {
// If success, the user object you passed in Auth.federatedSignIn
console.log(user);
}).catch(e => {
console.log(e)
});
}
推荐阅读
- javascript - 日期构造函数的不同行为
- google-sheets - 日历,鼠标悬停在当天 >> 显示包含该日期的行中的内容
- javascript - 如何在嵌套的json对象数组中获取子ID的直接父ID?
- java - 如何使用 Aspose Words for Androd 获取内联词的超链接边界?
- deep-learning - 层归一化会延迟训练吗?
- swift - UIStackView 中差异元素的大小(宽度/高度)约束覆盖彼此的约束
- azure - 使用 azure java sdk 对 Azure 进行身份验证
- google-colaboratory - 如何在 google colab 中生成代码单元?
- python - 可以在python的discord api中使用相对路径吗?
- c# - 使用带有 Selenium 的 specflow 只运行一次 BeforeTestRun 和 AfterTestRun