【发布时间】:2016-04-14 12:24:23
【问题描述】:
提前感谢您的帮助!
我无法让 Amazon Cognito 正确存储/同步数据。
在 dataset.synchronize() 行(不将数据存储在 Cognito 中)上,我收到一个大的输出错误(ID 已加星标),例如:
AWSCredentialsProvider.m line:429 | __73-[AWSCognitoCredentialsProvider
getCredentialsWithCognito:authenticated:]_block_invoke | GetCredentialsForIdentity
failed. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain
Code=10 "(null)" UserInfo={__type=NotAuthorizedException, message=Access to
Identity '*****' is forbidden.}]
cognitoID 不是 nil,并且正确返回(并且与我可以在线阅读的值匹配)
例如,在通过 Facebook 进行身份验证后,我执行以下操作:
if (FBSDKAccessToken.currentAccessToken() != nil)
{
let fbCognitoToken = FBSDKAccessToken.currentAccessToken().tokenString
credentialsProvider.logins = [AWSCognitoLoginProviderKey.Facebook.rawValue: fbCognitoToken]
// Retrieve your Amazon Cognito ID
credentialsProvider.getIdentityId().continueWithBlock { (task: AWSTask!) -> AnyObject! in
if (task.error != nil) {
print("Error: " + task.error!.localizedDescription)
}
else {
// the task result will contain the identity id
let cognitoId = task.result
//checking if cognito was successful, if true, sets success condition to true to prepare for segue into app
if cognitoId != nil{
print (cognitoId)
cognitoSuccess = true
let syncClient = AWSCognito.defaultCognito()
let dataset = syncClient.openOrCreateDataset("User_Data")
dataset.setString("test@test.com", forKey:"Email")
// credentialsProvider.refresh()
dataset.synchronize()
} }return nil}}
我可以正确地从 Facebook 读取数据,并且据我所知,所有身份验证都正确进行。我怀疑这里的根源很简单,但是花了几天时间后,我想不通!在 AWS 门户中使用 IAM 检查器会返回 Cognito 函数的所有“绿色检查”,因此我确信这也不是服务器端的权限问题。
再次感谢您提供的任何见解!
编辑: 在上面的代码块之前,我调用:
let credentialsProvider = self.initializeCognito()
哪个运行(身份池 ID 已加星标):
func initializeCognito () -> AWSCognitoCredentialsProvider
{
let credentialsProvider = AWSCognitoCredentialsProvider(
regionType: AWSRegionType.USEast1, identityPoolId: "******")
let defaultServiceConfiguration = AWSServiceConfiguration(
region: AWSRegionType.USEast1, credentialsProvider: credentialsProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = defaultServiceConfiguration
return credentialsProvider
}
【问题讨论】:
标签: ios swift amazon-cognito