簡體   English   中英

AWS / iOS / Cognito:此身份池不支持未經身份驗證的訪問

[英]AWS / iOS / Cognito: unauthenticated access is not supported for this identity pool

我正在嘗試使S3TransferUtilitySampleObjC項目與我的Cognito和AWS憑證一起使用。

不幸的是,我得到以下錯誤:

AWSURLSessionManager.m line:566 | -[AWSURLSessionManager printHTTPHeadersForResponse:] | Response headers:
{
    Connection = "keep-alive";
    "Content-Length" = 111;
    "Content-Type" = "application/x-amz-json-1.1";
    Date = "Mon, 16 Jan 2017 17:17:50 GMT";
    "x-amzn-ErrorMessage" = "Unauthenticated access is not supported for this identity pool.";
    "x-amzn-ErrorType" = "NotAuthorizedException:";
    "x-amzn-RequestId" = "xxxxxxxxx-xxxxx-xxxxx-xxxx-xxxxxxx";
}

你能幫忙嗎?


代碼(請注意,我僅從SecondViewController中刪除了一些代碼並修改了Constants中的值-我還修改了Info.plist文件(請參見下面的屏幕截圖)

我目前只專注於從S3存儲桶下載文件 因此,我僅修改了以下內容:

// In Constants.m
NSString *const S3BucketName = @"mybucketname";
NSString *const S3DownloadKeyName = @"config.plist";

// In SecondViewController.m

#import "SecondViewController.h"
#import "AppDelegate.h"
#import <AWSS3/AWSS3.h>
#import "Constants.h"

@interface SecondViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;

@property (copy, nonatomic) AWSS3TransferUtilityDownloadCompletionHandlerBlock completionHandler;
@property (copy, nonatomic) AWSS3TransferUtilityProgressBlock progressBlock;

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.progressView.progress = 0;
    self.statusLabel.text = @"Ready";

    __weak SecondViewController *weakSelf = self;
    self.completionHandler = ^(AWSS3TransferUtilityDownloadTask *task, NSURL *location, NSData *data, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (error) {
                weakSelf.statusLabel.text = @"Failed to Download";
            }
            if (data) {
                weakSelf.statusLabel.text = @"Successfully Downloaded";
                weakSelf.imageView.image = [UIImage imageWithData:data];
                weakSelf.progressView.progress = 1.0;
            }
        });
    };

    self.progressBlock = ^(AWSS3TransferUtilityTask *task, NSProgress *progress) {
        dispatch_async(dispatch_get_main_queue(), ^{
            weakSelf.progressView.progress = progress.fractionCompleted;
        });
    };

    AWSS3TransferUtility *transferUtility = [AWSS3TransferUtility defaultS3TransferUtility];
    [transferUtility enumerateToAssignBlocksForUploadTask:nil downloadTask:^(AWSS3TransferUtilityDownloadTask * _Nonnull downloadTask, AWSS3TransferUtilityProgressBlock  _Nullable __autoreleasing * _Nullable downloadProgressBlockReference, AWSS3TransferUtilityDownloadCompletionHandlerBlock  _Nullable __autoreleasing * _Nullable completionHandlerReference) {
        NSLog(@"%lu", (unsigned long)downloadTask.taskIdentifier);

        *downloadProgressBlockReference = weakSelf.progressBlock;
        *completionHandlerReference = weakSelf.completionHandler;

        dispatch_async(dispatch_get_main_queue(), ^{
            self.statusLabel.text = @"Uploading...";
        });
    }];
}

- (IBAction)start:(id)sender {
    self.imageView.image = nil;

    AWSS3TransferUtilityDownloadExpression *expression = [AWSS3TransferUtilityDownloadExpression new];
    expression.progressBlock = self.progressBlock;

    AWSS3TransferUtility *transferUtility = [AWSS3TransferUtility defaultS3TransferUtility];
    [[transferUtility downloadDataFromBucket:S3BucketName
                                         key:S3DownloadKeyName
                                  expression:expression
                            completionHander:self.completionHandler] continueWithBlock:^id(AWSTask *task) {
        if (task.error) {
            NSLog(@"Error: %@", task.error);
        }
        if (task.exception) {
            NSLog(@"Exception: %@", task.exception);
        }
        if (task.result) {
            dispatch_async(dispatch_get_main_queue(), ^{
                self.statusLabel.text = @"Downloading...";
            });
        }

        return nil;
    }];
}

在以下位置修改了Info.plist文件:

在此處輸入圖片說明

您收到的錯誤說明了這個問題-您正在以未經身份驗證的用戶身份向Cognito發送請求,這意味着沒有為該身份包含/鏈接任何登錄名,但未為該池啟用該登錄名。

未經身份驗證的身份是身份池的可選功能,您必須在通過Cognito控制台創建/編輯池時將其啟用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM