Cognito身份validation工作但错误显示?
基本上我使用开发人员身份validation的身份来validation我的用户。 即使出现此错误:
AWSiOSSDKv2 [详细] AWSURLResponseSerialization.m行:87 | – [AWSJSONResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | 响应正文:[{“_ _ type”:“InvalidParameterException”,“message”:“请提供有效的公共提供者”}] 2015-10-20 17:50:19.251 BusyTime [56549:7365231] AWSiOSSDKv2 [错误] AWSCredentialsProvider.m行:435 | __73- [AWSCognitoCredentialsProvider getCredentialsWithCognito:authenticated:] _ block_invoke | GetCredentialsForIdentity失败。 错误是[Error Domain = com.amazonaws.AWSCognitoIdentityErrorDomain Code = 7“无法完成操作。(com.amazonaws.AWSCognitoIdentityErrorDomain error 7.)”UserInfo = 0x7f9d9342dde0 {__type = InvalidParameterException,message =请提供有效的公共提供者}]
虽然这个错误显示,但我仍然返回我的identityId和Token并成功调用一个需要经过身份validation的特权来调用的lambda方法。 我相信它与我的刷新方法有关,但我不完全确定。 请帮我处理这个错误。
我的凭证提供者代码:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [AWSLogger defaultLogger].logLevel = AWSLogLevelVerbose; id identityProvider = [[BusytimeAuthenticated alloc] initWithRegionType:AWSRegionUSEast1 identityId:nil identityPoolId:@"EXAMPLEPOOLID" logins:@{@"login.busytimeapp": [defaults objectForKey:@"username"]} providerName:@"login.busytimeapp" ]; credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1 identityProvider:identityProvider unauthRoleArn:nil authRoleArn:nil]; configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:self.credentialsProvider]; AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration; [[credentialsProvider refresh] continueWithBlock:^id(BFTask *task){ [self testAuth]; return nil; }];
我的刷新方法:
- (BFTask *)refresh { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if (![self authenticatedWithProvider]) { return [super getIdentityId]; }else{ NSDictionary *post = [[NSDictionary alloc] initWithObjectsAndKeys: [defaults objectForKey:@"username"], @"username", [defaults objectForKey:@"password"], @"password", nil]; NSError *error; NSData *postData = [NSJSONSerialization dataWithJSONObject:post options:0 error:&error]; NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:@"SOMEURL"]]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setHTTPBody:postData]; NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; __block BOOL isLogged = false; [[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSDictionary *newJSON = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; isLogged = true; if(!newJSON){ NSLog(@"DID NOT AUTHENTICATE"); }else{ self.identityId = [newJSON objectForKey:@"IdentityId" ]; self.token = [newJSON objectForKey:@"Token" ]; NSLog(@"Result: %@", newJSON); } }] resume]; return [super getIdentityId]; } return [super getIdentityId]; }
这里的问题是您将登录提供程序名称作为键传递给登录映射。 您不能为开发者身份validation身份执行此操作。
相反,您应该在地图中使用Cognito身份提供者名称cognito-identity.amazonaws.com ,就像在文档中所述。 这应该可以解决您的exception。