Amazon Cognito:从浏览器重定向到Android应用程序时,如何停止获取“ redirect_mismatch”错误

时间:2018-06-19 20:52:10

标签: android redirect oauth httprequest amazon-cognito

我正在尝试创建一个Android项目,在该项目中,我让用户在浏览器中登录Amazon Cognito,从而授权该用户,然后应重定向回我的应用。不幸的是,当浏览器打开时,没有到达正确的登录页面,而是不断出现此错误:

enter image description here

在我的AuthenticatorActivity.java中:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_authenticator);

    Uri authzUrl = Uri.parse("https://<myDomain>.auth.us-west-2.amazoncognito.com/login?response_type=token&client_id=<myClientId>&redirect_uri=myapp://mainAct");
    Intent launchBrowser = new Intent(Intent.ACTION_VIEW, authzUrl);
    startActivity(launchBrowser);
}

在AndroidManifest中:

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:host="mainAct" android:scheme="myapp"></data>
    </intent-filter>
</activity>

我无法弄清楚我在做什么错。我错过了一步吗?

11 个答案:

答案 0 :(得分:3)

请检查您的回调URL并注销URL。 corect格式为:

app_client_name:https://www.myapp.com/

enter image description here

答案 1 :(得分:3)

好吧,我在这里留下一个小消息,供以后可能会发现它的人使用。我遇到了完全相同的问题,但是作为Cognito和IdP / SSO的新手,我不知道如何解决此问题。这是我为最终解决此问题所做的工作。我们正在与外部服务集成,并且遇到了此错误。在Chrome开发者工具->网络下,我开始记录该URL的访问,然后再次尝试SSO集成。列表中显示了一个URL,该URL通过重定向到URL访问了Cognito。该URL必须与Cognito的“回调URL”下列出的URL相同。

希望这可以节省将来的时间。

答案 2 :(得分:2)

我正在使用带有Cognito的Amplify并遇到此错误。通过固定。在aws-export.ts中,有一个redirecSingIn url,它必须与cognito / app集成/ app客户端设置/回调URL中的URL完全相同。

答案 3 :(得分:1)

对于我来说,该错误是由于CloudFront提供了旧文件所致。

解决;您可以通过AWS控制台使CloudFront文件无效。 ps。可以使用/*使所有文件无效 https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html

答案 4 :(得分:1)

我通过记住在前端的callbackUrl中包含http://来解决了这个问题。

const redirect_url=`${window.location.origin}`;

这可能不是一个普遍的原因,但这就是我的破产的原因。

答案 5 :(得分:1)

我犯了另一个愚蠢的错误,花了我几个小时才弄清楚,这是一个事实,即redirectSignInaws-exports.js的值是完全错误的。当您通过Amplify CLI多次修改此配置的值时,它会附加一个逗号,将该值视为一个列表,为您提供类似的信息

 "redirectSignIn": "http://localhost:3000/,http://localhost:3000/,http://localhost:3000/,http://localhost:3000/",

不幸的是,使用HostedUI时,该值被视为字符串。

答案 6 :(得分:1)

扩展 Dimitris https://stackoverflow.com/a/60456018/6883773

的答案

如果您为负载均衡器指定了DNS route53。您可以在回调URL中指定相同的内容。

https://www.example.com/oauth2/idpresponse

参考:https://aws.amazon.com/premiumsupport/knowledge-center/elb-configure-alb-authentication-idp/

答案 7 :(得分:0)

假设您的网站位于应用程序负载平衡器(ALB)的后面,并且您有一个使用Cognito用户池的侦听器规则,并且IF规则语句中的路径为* ,则应配置0Auth客户端应用回调网址,例如:

https://<your-ALB-DNS>/oauth2/idpresponse

这使得它至少对我有用,而没有其他精美的配置。

请记住,这只会在ALB后面的内容之上提供一层。如果其中包含其他身份验证方法,则还必须对其进行配置。

答案 8 :(得分:0)

如果您要申请范围,则绝对需要确保选中了这些项目,否则将获得kubectl get ingress --all-namespaces -o=yaml | grep influx (无用的错误名称)。

enter image description here

使用here教程中的以下配置

kubectl get cm --all-namespaces -o=yaml | grep influx
kubectl get deploy --all-namespaces -o=yaml | grep influx
kubectl get ds --all-namespaces -o=yaml | grep influx
kubectl get sts --all-namespaces -o=yaml | grep influx

答案 9 :(得分:0)

这是因为redirectSignIn或redirectSignOut的URL不匹配。请同时检查aws控制台中的设置和代码aws_config,并使其一致。

aws console redirect uri configuration

答案 10 :(得分:-2)

我关注了这个视频“使用 AWS Amplify 为 Web 应用程序添加 Facebook 登录”:https://dev.to/aws/adding-facebook-sign-in-for-web-applications-with-aws-amplify-2fc8

它部署到 localhost,所以我然后将它部署到 Amplify URL ...我有同样的重定向错误广告,结果我没有更新 src 目录中的 aws-exports.js。