简体   繁体   中英

iOS - Login in with Facebook but still getting: “Unauthenticated access is not supported for this identity pool”

I am working for an iOS App using AWS. I am trying to get items from my DynamoDB table but I am getting the error (From time to time it works!!! Like 4 hours working then goes down)

{
 __type=com.amazon.coral.service#AccessDeniedException,
Message=User:arn:aws:sts::306752704279:

assumed-role/Cognito_equo_MOBILEHUB_1429140868Unauth_Role/CognitoIdentityCredentials 
is not authorized to perform: dynamodb:Query on resource: 
 arn:aws:dynamodb:us-east-1:306752704279:table/equo-mobilehub-1429140868-TripActive/index/searchByOwner
 }

I don't want my app to have Unauthenticated users, but I AM LOGIN IN before calling the DynamoDB query. Can Anyone help me? Here's my code for the query: (I am using de Generated Code for the LogIn)

-(void) getUserHorsesWithMax: (int)pMax page:(int) pPage {

    dispatch_async(dispatch_get_main_queue(), ^{

    loading = true;

    AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
                                                                                                    identityPoolId:@"us-east-1:a1372699-48b0-499a-bf17-84811860a8bb"];

    [[credentialsProvider getIdentityId] continueWithBlock:^id(AWSTask *task) {
        if (task.error) {
            NSLog(@"Error: %@", task.error);
        }
        else {
            // the task result will contain the identity id
            NSString *cognitoId = task.result;

            AWSDynamoDBObjectMapper *dynamoDBObjectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];

            AWSDynamoDBQueryExpression *queryExpression = [AWSDynamoDBQueryExpression new];

            queryExpression.indexName = @"searchByOwner";

            queryExpression.expressionAttributeValues =  @{@":owID":cognitoId};
            queryExpression.keyConditionExpression = @"ownerId=:owID";


            [[dynamoDBObjectMapper query:[TripActive class]
                              expression:queryExpression]
             continueWithBlock:^id(AWSTask *task) {

                 loading = false;

                 if (task.error) {
                     NSLog(@"The request failed. Error: [%@]", task.error);
                 }
                 if (task.exception) {
                     NSLog(@"The request failed. Exception: [%@]", task.exception);
                 }
                 if (task.result) {

                     dispatch_async(dispatch_get_main_queue(), ^{

                         AWSDynamoDBPaginatedOutput *paginatedOutput = task.result;
                         horses = [NSMutableArray new];
                         for (Horse *horse in paginatedOutput.items) {
                             //Do something with horse.

                             if (self.segmentedTrips.selectedSegmentIndex == FUTURE_TRIPS) {



                             } else if (self.segmentedTrips.selectedSegmentIndex == ACTIVE_TRIPS) {

                                 [horses addObject:horse];

                             } else if (self.segmentedTrips.selectedSegmentIndex == PAST_TRIPS) {


                             }


                         }


                         [UIView animateWithDuration:0.2 animations:^(void) {

                             self.tripsTableView.alpha = 1.0f;


                         } completion:^(BOOL finished) {

                             self.tripsTableView.hidden = false;

                         }];


                         [self.tripsTableView reloadData];

                     });



                 }

                 return nil;
             }];


        }
        return nil;
    }];

    });


}

PLEASE HELP ME!

The exception you are getting means that the logins map is empty when calling Cognito to get credentials. Is this happening during app open/close? Or are you keeping the app open for 4 hours?

Make sure that the logins map always contains the provider and token from the provider.

Additionally, please make sure you are using the most recent version of the iOS SDK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM