我目前无法授权用户使用AWS iOS SDK,V2,使用Facebook和Google+作为提供者。
我不确定这是我在AWS开发者控制台上的设置,还是代码。
这是身份池的角色策略:
{
"Version": "2012-10-17",
"Statement": [{
"Action": [
"mobileanalytics:PutEvents",
"cognito-sync:*"
],
"Effect": "Allow",
"Resource": ["*"]
}] 我确实收到了一个未经授权的认知ID,但是当我尝试使用Facebook或Google+提供者身份验证时,它不起作用。

一旦Facebook登录返回,我可以成功地使用用户属性提取配置文件图片、姓名和电子邮件地址。然后我从Facebook会话中获取令牌(是的,它是一个非常长的字符串),并在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我没有收到错误消息,上面的仪表板从未显示过经过身份验证的用户。CognitoID从不改变它的值。有人能告诉我问题在哪里吗?
编辑:基于注释更新的DeviceId.m仍然返回cognitoId的零
编辑2:更新的DeviceId.m替换was循环检查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。修改了Facebook之后,使用此方法返回cognitoID。
编辑3:然而,在到达deviceId.之前,Google+失败了。
- (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错误打印: error Domain=com.google.GooglePlusPlatform Code=-1“操作无法完成。(com.google.HTTPStatus错误400。)API & Auth产品名称和当前电子邮件地址在控制台上似乎是正确的。
编辑4:代码的另一部分中的认知同步现在已经停止了以前工作的地方:
AWSCognito *syncClient = [AWSCognito defaultCognito];
AWSCognitoDataset *dataset = [syncClient openOrCreateDataset:@"myDataSet"];
NSString *fullName = [dataset stringForKey:@"name"];在第一行出现错误时失败:
*由于未识别的异常“NSInvalidArgumentException”终止应用程序,原因:'+AWSEndpoint endpointWithRegion:service::未识别的选择器发送到类
任何关于这些额外错误的帮助都是非常感谢的。
发布于 2015-04-07 18:32:48
你所描述的问题的共同原因
错误Domain=com.google.GooglePlusPlatform代码=-1“操作无法完成。(com.google.HTTPStatus错误400。)
在this stackoverflow question中描述。我会再次检查您是否输入了产品名称和电子邮件地址。此外,我认为您必须在输入这些数据后重新创建OAuth凭据,所以如果您还没有这样做,可能值得一试。
最后,检查是否使用的是web服务器API密钥,而不是iOS客户端密钥。
发布于 2015-03-07 03:02:24
看起来,在credentialsProvider.logins映射中设置令牌之后,您将再次调用setDeviceId来重写您的credentialsProvider。setDeviceId创建了一个全新的AWSCognitoCredentialsProvider,它将不具有添加到上一个标记的令牌,并覆盖变量credentialsProvider。
https://stackoverflow.com/questions/28902415
复制相似问题