![](/img/trans.png)
[英]AWS Cognito rules can't match the drop-in auth UI using aws amplify (Android)
[英]AWS Amplify Cognito Auth error in Android app
我正在關注 Amplify 文檔以向我的 Android 應用程序添加身份驗證。 我在這條線上得到了一個AuthException
:
Amplify.addPlugin(AWSCognitoAuthPlugin())
我確實創建了一個用戶池。 我需要以某種方式附加它嗎? 我猜AWSMobileClient
有一些問題。
這是我的Application
class:
class AppUtils : Application() {
override fun onCreate() {
super.onCreate()
try {
Amplify.addPlugin(AWSCognitoAuthPlugin())
Amplify.configure(applicationContext)
Log.d(TAG, "Initialized Amplify")
} catch (error: AmplifyException) {
Log.e(TAG, "Could not initialize Amplify", error)
}
}
}
這是顯示在 logcat 中的錯誤:
AuthException{message=無法實例化 AWSMobileClient,原因=java.lang.RuntimeException:未使用 Cognito Identity 或 Cognito UserPool。 必須至少存在一個才能使用 AWSMobileClient。,recoverySuggestion=有關更多詳細信息,請參閱附加的例外}
該錯誤表明在您的配置文件中沒有找到 Identity 或 UserPool。
首先確保您已完成以下步驟:
完成后,您的app/src/main/res/raw
目錄中應該有一個amplifyconfiguration.json
和一個awsconfiguration.json
。
您的amplifyconfiguration.json
應如下所示:
{
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"Region": "us-east-1"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "us-east-1_xxxxxxxxx",
"AppClientId": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
"AppClientSecret":
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Region": "us-east-1"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH"
}
}
}
}
}
}
您的awsconfiguration.json
應如下所示:
{
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"Region": "us-east-1"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "us-east-1_xxxxxxxxx",
"AppClientId": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
"AppClientSecret":
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Region": "us-east-1"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH"
}
}
}
如果您剛剛添加了 Cognito,請運行
amplify update api
使用 Cognito 作為身份驗證模式。
然后運行
amplify push
幾天來我也面臨同樣的錯誤,您剛剛向項目添加了基本文件,現在您需要為 Amplify 定義用戶池以向兩個配置文件添加更多數據。 您需要運行這些命令才能解決此問題。
amplify init // It will make sure you have basic setup added
amplify add auth // It will add auth data and user pools to config files
amplify push // It will push all the setup to amplify cloud
希望它能解決你的問題:)
我有同樣的問題。問題是我在終端中配置登錄方法時。
有 3 種受支持的登錄方法:
對於 (1),您需要選擇“默認配置”。 完成后,運行放大推送。 此時,您應該期望在您的放大配置中沒有 OAuth object.json。 對於 (2) 或 (3),您需要選擇“使用 Social Provider (Federation) 的默認配置”。 誠然,措辭可能有點令人困惑,因為 (2) 不是社交提供者。 此時,您應該期望在您的放大配置中有一個 OAuth object。json
要更新此用途:
sudo amplify update auth
選擇正確的登錄方式並
sudo amplify push
如果在使用登錄方法2時出現此錯誤: Can't fill in URI in "amplify add auth"
使用這個uri:( https://www.amazon.com/或 http://localhost:3000/)
或者
輸入gettingstarted://
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.