[英]Amazon Cognito with iOS: Access to Identity Forbidden
我在这里先向您的帮助表示感谢!
我在让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
}
当您尝试获取经过身份验证的ID的凭据而不提供任何链接到它的提供者令牌时,可能会抛出该异常。 Cognito要求至少提供一个。
您可以在失败的GetCredentialsForIdentity调用期间检查是否包含Facebook令牌吗? 如果没有,我想这就是你的问题。
编辑:
由于您使用的是AWSCognito.defaultCognito(),因此遵循此文档页面上的示例可能有助于确保同步客户端使用正确的凭证提供程序:
let configuration = AWSServiceConfiguration(region: AWSRegionType.USEast1, credentialsProvider: credentialsProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
最终弄清楚了答案-当我第一次设置AWS并遵循Amazon的一些指南时,我已经在应用程序的App Delegate中放置了代码以创建新的certificateProvider。 我忘记了它,然后稍后尝试初始化另一个凭据提供程序。 这种混乱造成了问题,而在App Delegate中删除初始化解决了身份验证问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.