首页 > 解决方案 > 如何在不使用托管 UI 的情况下将 Cognito 用作 OAuth Flow?

问题描述

我以前在这里看到过一些类似的问题,但我一个都听不懂。如何在不使用 Cognito 中的托管 UI 的情况下从 OAuth 2 身份验证流程中获取代码?

我看到托管调用了一个 javascript 函数,但我不明白它是如何工作的并返回代码。

有什么方法可以调用 API 直接传递用户凭据并生成此代码?

标签: amazon-web-servicesamazon-cognito

解决方案


文档对此非常不利 - 但我使用 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)
    });
    }


推荐阅读