Amazon Cognito iOS SDK V2使用Facebook和Google+提供者身份validation问题

我目前无法授权使用AWS iOS SDK V2的用户使用Facebook和Google+作为提供者。

我不确定是否在AWS开发者控制台上设置了我的设置,或者是否在代码中。

这是身份池的angular色策略:

{ "Version": "2012-10-17", "Statement": [{ "Action": [ "mobileanalytics:PutEvents", "cognito-sync:*" ], "Effect": "Allow", "Resource": ["*"] }] 

我确实收到未经授权的Cognito ID,但是当我尝试使用Facebook或Google+提供者身份validation时,它不起作用。

未经身份验证的用户确认

一旦Facebooklogin返回,我可以成功地使用用户属性来提取个人资料图片,姓名和电子邮件地址。 然后,我从Facebook会话中获取令牌(是的,这是一个非常长的string),并在deviceID类中使用它:

 - (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user { //Populate viewcontoller with Facebook data self.profilePictureView.profileID = user.id; NSRange range = [user.name rangeOfString:@" "]; self.firstName.text = [user.name substringToIndex:range.location]; self.lastName.text = [user.name substringFromIndex:range.location+1]; self.emailAddress.text = [user objectForKey:@"email"]; //Get Facebook token, set then get Cognito device ID - in DeviceId class NSString *token = FBSession.activeSession.accessTokenData.accessToken; DeviceId *myDeviceId = [DeviceId sharedInstance]; cognitoDeviceId = [myDeviceId setFacebookToken:token]; 

}

DeviceID类的实现如下所示:

 #import "DeviceId.h" #import <AWSiOSSDKv2/AWSCore.h> #import <AWSCognitoSync/Cognito.h> @implementation DeviceId static NSString *cognitoId; static DeviceId *_sharedInstance; static AWSCognitoCredentialsProvider *credentialsProvider; static AWSServiceConfiguration *configuration; + (DeviceId *) sharedInstance { if (!_sharedInstance) { _sharedInstance = [[DeviceId alloc] init]; } return _sharedInstance; } - (NSString *) getDeviceId { return cognitoId; } - (void) setDeviceId { /* * AWS Cognito */ credentialsProvider = [AWSCognitoCredentialsProvider credentialsWithRegionType:AWSRegionUSEast1 accountId:@"(accountID" identityPoolId:@"(identityPool)" unauthRoleArn:@"arn:aws:iam::(accountID):role/Cognito_(app)UsersUnauth_DefaultRole" authRoleArn:@"arn:aws:iam::(accountID):role/Cognito_(app)UsersAuth_DefaultRole"]; configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider]; [AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration; // Retrieve the cognito ID. cognitoId = credentialsProvider.identityId; if (!cognitoId) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Identification Error" message:@"Error on User Account." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } } -(NSString *)setFacebookToken:(NSString*)token { credentialsProvider.logins = @{ @(AWSCognitoLoginProviderKeyFacebook): token }; [self setDeviceId]; return cognitoId; } -(NSString *)setGooglePlusToken:(NSString*)token { credentialsProvider.logins = @{ @(AWSCognitoLoginProviderKeyGoogle): token }; [self setDeviceId]; return cognitoId; } @end 

我没有收到任何错误消息,上面的仪表板从不显示经过身份validation的用户。 CognitoID永远不会改变它的价值。 有人能告诉我问题在哪里吗?

编辑:根据注释更新DeviceId.m仍然返回nil为cognitoId

编辑2:更新DeviceId.mreplacewhile循环检查,如果BFTask完成螺栓方法waitUntilFinished。

 #import "DeviceId.h" #import <AWSiOSSDKv2/AWSCore.h> #import <AWSCognitoSync/Cognito.h> @implementation DeviceId { __block NSString *tempCognitoId; } static NSString *cognitoId; static DeviceId *_sharedInstance; static AWSCognitoCredentialsProvider *credentialsProvider; static AWSServiceConfiguration *configuration; + (DeviceId *) sharedInstance { if (!_sharedInstance) { _sharedInstance = [[DeviceId alloc] init]; } return _sharedInstance; } - (NSString *) getDeviceId { return cognitoId; } - (void) setDeviceId { /* * AWS Cognito */ credentialsProvider = [AWSCognitoCredentialsProvider credentialsWithRegionType:AWSRegionUSEast1 identityPoolId:@"Identity Pool ID"]; configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider]; [AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration; BFTask *taskIdentity = [[credentialsProvider refresh] continueWithBlock:^id(BFTask *task){ if (task.error == nil) { tempCognitoId = credentialsProvider.identityId; NSLog(@"cognitoId: %@", cognitoId); } else { NSLog(@"Error : %@", task.error); } return nil; }]; [taskIdentity waitUntilFinished]; cognitoId = tempCognitoId; } -(NSString *)setFacebookToken:(NSString*)token { credentialsProvider.logins = @{ @(AWSCognitoLoginProviderKeyFacebook): token }; BFTask *taskIdentity = [[credentialsProvider refresh] continueWithBlock:^id(BFTask *task){ if (task.error == nil) { tempCognitoId = credentialsProvider.identityId; NSLog(@"cognitoId: %@", tempCognitoId); } else { NSLog(@"Error : %@", task.error); } return nil; }]; [taskIdentity waitUntilFinished]; cognitoId = tempCognitoId; return cognitoId; } -(NSString *)setGooglePlusToken:(NSString*)token { credentialsProvider.logins = @{ @(AWSCognitoLoginProviderKeyGoogle): token }; BFTask *taskIdentity = [[credentialsProvider getIdentityId] continueWithBlock:^id(BFTask *task){ if (task.error == nil) { tempCognitoId = credentialsProvider.identityId; NSLog(@"cognitoId: %@", tempCognitoId); } else { NSLog(@"Error : %@", task.error); } return nil; }]; [taskIdentity waitUntilFinished]; cognitoId = tempCognitoId; return cognitoId; } @end 

我意识到,有些人可能会考虑等待完成是不好的做法,但我需要确保cognitoId返回“同步”的testing目的。 修改Facebook App ID后,使用此方法返回cognitoID。

编辑3:但是,Google+在达到deviceId之前失败。

 - (void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error { if (error) { _signInAuthStatus.text = [NSString stringWithFormat:@"Status: Authentication error: %@", error]; NSLog(@"%@", error); return; } NSString *idToken = [auth.parameters objectForKey:@"id_token"]; DeviceId *myDeviceId = [DeviceId sharedInstance]; [myDeviceId setGooglePlusToken:idToken]; } 

NSLog错误打印:错误域= com.google.GooglePlusPlatform代码= -1“该操作无法完成(com.google.HTTPStatus错误400.)”的API和身份validation产品名称和当前电子邮件地址似乎是在控制台上正确。

编辑4:代码的另一部分中的Cognito Synch现在已停止工作,它在之前的工作位置:

  AWSCognito *syncClient = [AWSCognito defaultCognito]; AWSCognitoDataset *dataset = [syncClient openOrCreateDataset:@"myDataSet"]; NSString *fullName = [dataset stringForKey:@"name"]; 

在错误的第一行失败:

***终止应用程序由于未捕获的exception“NSInvalidArgumentException”,原因:'+ [AWSEndpoint endpointWithRegion:服务:]:无法识别的select器发送到类

任何帮助这些额外的错误,表示赞赏。

您所描述的问题的一个常见原因

错误域= com.google.GooglePlusPlatform Code = -1“操作无法完成(com.google.HTTPStatus错误400.)

在这个stackoverflow问题中描述。 我会仔细检查你是否input了产品名称和电子邮件地址。 另外,我相信在input这些数据后,您必须重新创buildOAuth凭据,所以如果您还没有这样做,可能值得尝试。

最后,检查您使用的是Web服务器API密钥, 而不是 iOS客户端密钥。

看起来像在credentialsProvider.logins映射中设置标记之后,您通过再次调用setDeviceId覆盖您的credentialsProvider。 setDeviceId创build一个全新的AWSCognitoCredentialsProvider,它不会添加到前一个令牌中,并覆盖variablescredentialsProvider。