问题描述
我正在尝试创建一个Android项目,在该项目中我授权用户,方法是让用户在浏览器中登录Amazon Cognito,然后应重定向回我的应用.不幸的是,当浏览器打开时,没有到达正确的登录页面,而是不断出现此错误:
I am trying to create a Android project where I authorize a user by having him log into Amazon Cognito in a browser, which should then redirect back to my app. Unfortunately, when the browser opens, instead of reaching the proper sign-in page, I keep getting this error:
在我的AuthenticatorActivity.java中:
In my 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中:
In 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>
我无法弄清楚我在做什么错.我错过了一步吗?
I can't figure out what I am doing wrong here. Am I missing a step?
推荐答案
好吧,我在这里留下一个小窍门,以供下一个可能找到它的人使用.我遇到了完全相同的问题,但是作为Cognito和IdP/SSO的新手,我不知道如何解决此问题.这是我为最终解决此问题所做的工作.我们正在与外部服务集成,并且遇到了此错误.在Chrome开发者工具->网络下,我开始记录URL的访问,然后再次尝试SSO集成.列表中显示了一个URL,该URL通过重定向到URL访问了Cognito.该URL必须与Cognito的回调URL"下列出的URL相同.
Ok, I'm leaving a tidbit here for whoever might find it next. I hit this issue exact same issue, but as a newbie to Cognito and IdP/SSO I had no idea how to fix this. Here is what I did to eventually fix this. We were integrating with an external service, and we were getting this error. Under Chrome Developer Tools -> Network, I started to record the URL's visited, then I tried the SSO integration again. There was a URL that showed up in the list which visited Cognito with a redirect to URL. That URL must be the same URL as listed under the Callback URL for Cognito.
希望这可以节省将来的时间.
Hopefully, this saves someone some time in the future.
这篇关于Amazon Cognito:如何停止获取"redirect_mismatch"从浏览器重定向到Android应用时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!