Ios Cognito身份验证工作正常但显示错误?

Ios Cognito身份验证工作正常但显示错误?,ios,authentication,amazon-cognito,Ios,Authentication,Amazon Cognito,基本上,我使用开发人员身份验证的身份来验证我的用户。即使此错误正在显示: AWSiOSSDKv2[Verbose]AWSURLResponseSerialization.m行:87| -[AWSJSONResponseSerializer responseObjectForResponse:原始请求:当前请求:数据:错误:] |答复机构: [{“\uuuu类型”:“InvalidParameterException”,“message”:“请提供一个 有效公共提供者“}]2015-10-20 1

基本上,我使用开发人员身份验证的身份来验证我的用户。即使此错误正在显示:

AWSiOSSDKv2[Verbose]AWSURLResponseSerialization.m行:87| -[AWSJSONResponseSerializer responseObjectForResponse:原始请求:当前请求:数据:错误:] |答复机构: [{“\uuuu类型”:“InvalidParameterException”,“message”:“请提供一个 有效公共提供者“}]2015-10-20 17:50:19.251 BusyTime[56549:7365231]AWSiOSSDKv2[Error]AWSCredentialsProvider.m 行:435 | uu 73-[AWSCognitoCredentialsProvider getCredentialsWithCognito:authenticated:][u block\u invoke| GetCredentialsForIdentity失败。错误是[错误] Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=7“的 操作无法完成。 (com.amazonaws.AWSCognitoIdentityErrorDomain错误7.) UserInfo=0x7f9d9342dde0{{uuuu type=InvalidParameterException, message=请提供有效的公共提供程序}]

尽管这个错误显示,我仍然返回我的identityId和Token,并成功调用一个lambda方法,该方法需要经过身份验证的特权才能调用。我相信这与我的刷新方法有关,但我不太确定。请帮我处理这个错误

我的凭据提供程序代码:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    [AWSLogger defaultLogger].logLevel = AWSLogLevelVerbose;
    id<AWSCognitoIdentityProvider> 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;
    }];

这里的问题是,您正在将登录映射中的登录提供者名称作为密钥传递。对于开发人员身份验证的身份,您不能这样做


相反,您应该在地图中使用Cognito身份提供者名称Cognito-identity.amazonaws.com,如图中所示。这将修复您的异常。

您能通过代码给我一个示例吗?如果你的意思是这样的,我对此有点困惑:登录:{“cognito identity.amazonaws.com:[defaults objectForKey:@“username”]}当我切换它时,会出现以下错误:AWSiOSSDKv2[error]AWSCredentialsProvider.m行:534 |(awscognitoredentialsprovider refresh](wscognitoredentialsprovider refresh |块)调用350 |无法刷新。错误是[Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=9“操作无法完成。(com.amazonaws.AWSCognitoIdentityErrorDomain错误9.)“UserInfo=0x7fc7084f7ed0{uuu type=NotAuthorizedException,message=Invalid login token.}]是的,这就是我的意思。错误状态为“无效登录令牌”,这意味着您在登录映射中传递的令牌无效。此令牌应该是后端提供的令牌,它由名为GetOpenIdTokenForDeveloperIdentity的CognitoAPI生成。您必须使用AWS开发人员凭据从后端调用此API。谢谢,它使用以下代码:登录:@{@“cognito identity.amazonaws.com”:[Default objectForKey:@“Token”]}providerName:@“cognito identity.amazonaws.com”设置login.busytimeapp的目的是什么?
- (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];
}